1 | <?php |
||
10 | class File extends AbstractHandler |
||
11 | { |
||
12 | private $file_name; |
||
13 | private $file_path; |
||
14 | |||
15 | /** |
||
16 | * @var \SplFileObject |
||
17 | */ |
||
18 | private $file_pointer; |
||
19 | |||
20 | /** |
||
21 | * Sets up the file name and path if optional parameters provided. |
||
22 | * |
||
23 | * @param string|null $file_name [optional] The name of the file used for logging; file_path is not required if |
||
24 | * file_name is fully-qualified. |
||
25 | * @param string|null $file_path [optional] The path of the file used for logging without the trailing directory |
||
26 | * separator |
||
27 | */ |
||
28 | 18 | public function __construct($file_name = null, $file_path = null) |
|
37 | |||
38 | /** |
||
39 | * Clean-up |
||
40 | */ |
||
41 | 18 | public function __destruct() |
|
45 | |||
46 | /** |
||
47 | * @return string|null The file_name set for the File instance |
||
48 | */ |
||
49 | 2 | public function getFileName() |
|
53 | |||
54 | /** |
||
55 | * @return string|null The file_path set for the File instance |
||
56 | */ |
||
57 | 3 | public function getFilePath() |
|
61 | |||
62 | /** |
||
63 | * Sets the name of the file to be used for logging; setting file_path is not required if the specified file name |
||
64 | * is fully-qualified. |
||
65 | * |
||
66 | * @param string $file_name The name of the file to be used for logging |
||
67 | */ |
||
68 | 2 | public function setFileName($file_name) |
|
72 | |||
73 | /** |
||
74 | * Sets the path of the file to be used for logging; file path should not be set if the File's file name is |
||
75 | * fully-qualified. |
||
76 | * |
||
77 | * @see File::setFileName() |
||
78 | * |
||
79 | * @param string $file_path The path of the file to be used for logging |
||
80 | */ |
||
81 | 3 | public function setFilePath($file_path) |
|
86 | |||
87 | /** |
||
88 | * Truncates the File to zero bytes, effectively clearing the file's contents. Does not delete the file. |
||
89 | * |
||
90 | * @return bool Returns true if truncate succeeded; returns false on failure. |
||
91 | */ |
||
92 | 2 | public function clearFile() |
|
102 | |||
103 | /** |
||
104 | * Sets the File's file_pointer to null to clean up resource. |
||
105 | */ |
||
106 | 18 | public function close() |
|
110 | |||
111 | /** |
||
112 | * Initializes the File for writing via append. Initialization attempts to create an SplFileObject pointer using |
||
113 | * the File's name and path properties. |
||
114 | * |
||
115 | * @see \SplFileObject |
||
116 | * |
||
117 | * @return bool Returns true on successful file pointer creation; returns false on failure. |
||
118 | */ |
||
119 | 11 | public function initialize() |
|
137 | |||
138 | /** |
||
139 | * Writes the specified message to the File pointer. Requires initialization via File::initialize(). |
||
140 | * |
||
141 | * @see File::initialize() |
||
142 | * |
||
143 | * @param string $message Message to be written to the file. |
||
144 | * |
||
145 | * @return bool Returns true on successful write; returns false on failure. |
||
146 | */ |
||
147 | 7 | public function write($message) |
|
168 | } |
||
169 |