@@ -26,10 +26,10 @@ endpoint for filesystem operations::
26
26
use Symfony\Component\Filesystem\Filesystem;
27
27
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
28
28
29
- $fileSystem = new Filesystem();
29
+ $filesystem = new Filesystem();
30
30
31
31
try {
32
- $fileSystem ->mkdir(sys_get_temp_dir().'/'.random_int(0, 1000));
32
+ $filesystem ->mkdir(sys_get_temp_dir().'/'.random_int(0, 1000));
33
33
} catch (IOExceptionInterface $exception) {
34
34
echo "An error occurred while creating your directory at ".$exception->getPath();
35
35
}
53
53
On POSIX filesystems, directories are created with a default mode value
54
54
`0777 `. You can use the second argument to set your own mode::
55
55
56
- $fileSystem ->mkdir('/tmp/photos', 0700);
56
+ $filesystem ->mkdir('/tmp/photos', 0700);
57
57
58
58
.. note ::
59
59
@@ -79,11 +79,11 @@ presence of one or more files or directories and returns ``false`` if any of
79
79
them is missing::
80
80
81
81
// if this absolute directory exists, returns true
82
- $fileSystem ->exists('/tmp/photos');
82
+ $filesystem ->exists('/tmp/photos');
83
83
84
84
// if rabbit.jpg exists and bottle.png does not exist, returns false
85
85
// non-absolute paths are relative to the directory where the running PHP script is stored
86
- $fileSystem ->exists(['rabbit.jpg', 'bottle.png']);
86
+ $filesystem ->exists(['rabbit.jpg', 'bottle.png']);
87
87
88
88
.. note ::
89
89
@@ -100,10 +100,10 @@ source modification date is later than the target. This behavior can be overridd
100
100
by the third boolean argument::
101
101
102
102
// works only if image-ICC has been modified after image.jpg
103
- $fileSystem ->copy('image-ICC.jpg', 'image.jpg');
103
+ $filesystem ->copy('image-ICC.jpg', 'image.jpg');
104
104
105
105
// image.jpg will be overridden
106
- $fileSystem ->copy('image-ICC.jpg', 'image.jpg', true);
106
+ $filesystem ->copy('image-ICC.jpg', 'image.jpg', true);
107
107
108
108
touch
109
109
~~~~~
@@ -113,11 +113,11 @@ modification time for a file. The current time is used by default. You can set
113
113
your own with the second argument. The third argument is the access time::
114
114
115
115
// sets modification time to the current timestamp
116
- $fileSystem ->touch('file.txt');
116
+ $filesystem ->touch('file.txt');
117
117
// sets modification time 10 seconds in the future
118
- $fileSystem ->touch('file.txt', time() + 10);
118
+ $filesystem ->touch('file.txt', time() + 10);
119
119
// sets access time 10 seconds in the past
120
- $fileSystem ->touch('file.txt', time(), time() - 10);
120
+ $filesystem ->touch('file.txt', time(), time() - 10);
121
121
122
122
.. note ::
123
123
@@ -131,9 +131,9 @@ chown
131
131
a file. The third argument is a boolean recursive option::
132
132
133
133
// sets the owner of the lolcat video to www-data
134
- $fileSystem ->chown('lolcat.mp4', 'www-data');
134
+ $filesystem ->chown('lolcat.mp4', 'www-data');
135
135
// changes the owner of the video directory recursively
136
- $fileSystem ->chown('/video', 'www-data', true);
136
+ $filesystem ->chown('/video', 'www-data', true);
137
137
138
138
.. note ::
139
139
@@ -147,9 +147,9 @@ chgrp
147
147
a file. The third argument is a boolean recursive option::
148
148
149
149
// sets the group of the lolcat video to nginx
150
- $fileSystem ->chgrp('lolcat.mp4', 'nginx');
150
+ $filesystem ->chgrp('lolcat.mp4', 'nginx');
151
151
// changes the group of the video directory recursively
152
- $fileSystem ->chgrp('/video', 'nginx', true);
152
+ $filesystem ->chgrp('/video', 'nginx', true);
153
153
154
154
.. note ::
155
155
@@ -163,9 +163,9 @@ chmod
163
163
permissions of a file. The fourth argument is a boolean recursive option::
164
164
165
165
// sets the mode of the video to 0600
166
- $fileSystem ->chmod('video.ogg', 0600);
166
+ $filesystem ->chmod('video.ogg', 0600);
167
167
// changes the mod of the src directory recursively
168
- $fileSystem ->chmod('src', 0700, 0000, true);
168
+ $filesystem ->chmod('src', 0700, 0000, true);
169
169
170
170
.. note ::
171
171
@@ -178,7 +178,7 @@ remove
178
178
:method: `Symfony\\ Component\\ Filesystem\\ Filesystem::remove ` deletes files,
179
179
directories and symlinks::
180
180
181
- $fileSystem ->remove(['symlink', '/path/to/directory', 'activity.log']);
181
+ $filesystem ->remove(['symlink', '/path/to/directory', 'activity.log']);
182
182
183
183
.. note ::
184
184
@@ -192,9 +192,9 @@ rename
192
192
of a single file or directory::
193
193
194
194
// renames a file
195
- $fileSystem ->rename('/tmp/processed_video.ogg', '/path/to/store/video_647.ogg');
195
+ $filesystem ->rename('/tmp/processed_video.ogg', '/path/to/store/video_647.ogg');
196
196
// renames a directory
197
- $fileSystem ->rename('/tmp/files', '/path/to/store/files');
197
+ $filesystem ->rename('/tmp/files', '/path/to/store/files');
198
198
199
199
symlink
200
200
~~~~~~~
@@ -204,10 +204,10 @@ symbolic link from the target to the destination. If the filesystem does not
204
204
support symbolic links, a third boolean argument is available::
205
205
206
206
// creates a symbolic link
207
- $fileSystem ->symlink('/path/to/source', '/path/to/destination');
207
+ $filesystem ->symlink('/path/to/source', '/path/to/destination');
208
208
// duplicates the source directory if the filesystem
209
209
// does not support symbolic links
210
- $fileSystem ->symlink('/path/to/source', '/path/to/destination', true);
210
+ $filesystem ->symlink('/path/to/source', '/path/to/destination', true);
211
211
212
212
readlink
213
213
~~~~~~~~
@@ -227,10 +227,10 @@ The :method:`Symfony\\Component\\Filesystem\\Filesystem::readlink` method provid
227
227
by the Filesystem component always behaves in the same way::
228
228
229
229
// returns the next direct target of the link without considering the existence of the target
230
- $fileSystem ->readlink('/path/to/link');
230
+ $filesystem ->readlink('/path/to/link');
231
231
232
232
// returns its absolute fully resolved final version of the target (if there are nested links, they are resolved)
233
- $fileSystem ->readlink('/path/to/link', true);
233
+ $filesystem ->readlink('/path/to/link', true);
234
234
235
235
Its behavior is the following::
236
236
@@ -251,12 +251,12 @@ makePathRelative
251
251
absolute paths and returns the relative path from the second path to the first one::
252
252
253
253
// returns '../'
254
- $fileSystem ->makePathRelative(
254
+ $filesystem ->makePathRelative(
255
255
'/var/lib/symfony/src/Symfony/',
256
256
'/var/lib/symfony/src/Symfony/Component'
257
257
);
258
258
// returns 'videos/'
259
- $fileSystem ->makePathRelative('/tmp/videos', '/tmp')
259
+ $filesystem ->makePathRelative('/tmp/videos', '/tmp')
260
260
261
261
mirror
262
262
~~~~~~
@@ -266,7 +266,7 @@ contents of the source directory into the target one (use the
266
266
:method: `Symfony\\ Component\\ Filesystem\\ Filesystem::copy ` method to copy single
267
267
files)::
268
268
269
- $fileSystem ->mirror('/path/to/source', '/path/to/target');
269
+ $filesystem ->mirror('/path/to/source', '/path/to/target');
270
270
271
271
isAbsolutePath
272
272
~~~~~~~~~~~~~~
@@ -275,13 +275,13 @@ isAbsolutePath
275
275
``true `` if the given path is absolute, ``false `` otherwise::
276
276
277
277
// returns true
278
- $fileSystem ->isAbsolutePath('/tmp');
278
+ $filesystem ->isAbsolutePath('/tmp');
279
279
// returns true
280
- $fileSystem ->isAbsolutePath('c:\\Windows');
280
+ $filesystem ->isAbsolutePath('c:\\Windows');
281
281
// returns false
282
- $fileSystem ->isAbsolutePath('tmp');
282
+ $filesystem ->isAbsolutePath('tmp');
283
283
// returns false
284
- $fileSystem ->isAbsolutePath('../dir');
284
+ $filesystem ->isAbsolutePath('../dir');
285
285
286
286
tempnam
287
287
~~~~~~~
@@ -300,7 +300,7 @@ file first and then moves it to the new file location when it's finished.
300
300
This means that the user will always see either the complete old file or
301
301
complete new file (but never a partially-written file)::
302
302
303
- $fileSystem ->dumpFile('file.txt', 'Hello World');
303
+ $filesystem ->dumpFile('file.txt', 'Hello World');
304
304
305
305
The ``file.txt `` file contains ``Hello World `` now.
306
306
@@ -315,7 +315,7 @@ appendToFile
315
315
:method: `Symfony\\ Component\\ Filesystem\\ Filesystem::appendToFile ` adds new
316
316
contents at the end of some file::
317
317
318
- $fileSystem ->appendToFile('logs.txt', 'Email sent to user@example.com');
318
+ $filesystem ->appendToFile('logs.txt', 'Email sent to user@example.com');
319
319
320
320
If either the file or its containing directory doesn't exist, this method
321
321
creates them before appending the contents.
0 commit comments