@@ -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
~~~~~~~~
@@ -223,10 +223,10 @@ The :method:`Symfony\\Component\\Filesystem\\Filesystem::readlink` method provid
223
223
by the Filesystem component always behaves in the same way::
224
224
225
225
// returns the next direct target of the link without considering the existence of the target
226
- $fileSystem ->readlink('/path/to/link');
226
+ $filesystem ->readlink('/path/to/link');
227
227
228
228
// returns its absolute fully resolved final version of the target (if there are nested links, they are resolved)
229
- $fileSystem ->readlink('/path/to/link', true);
229
+ $filesystem ->readlink('/path/to/link', true);
230
230
231
231
Its behavior is the following::
232
232
@@ -247,12 +247,12 @@ makePathRelative
247
247
absolute paths and returns the relative path from the second path to the first one::
248
248
249
249
// returns '../'
250
- $fileSystem ->makePathRelative(
250
+ $filesystem ->makePathRelative(
251
251
'/var/lib/symfony/src/Symfony/',
252
252
'/var/lib/symfony/src/Symfony/Component'
253
253
);
254
254
// returns 'videos/'
255
- $fileSystem ->makePathRelative('/tmp/videos', '/tmp')
255
+ $filesystem ->makePathRelative('/tmp/videos', '/tmp')
256
256
257
257
mirror
258
258
~~~~~~
@@ -262,7 +262,7 @@ contents of the source directory into the target one (use the
262
262
:method: `Symfony\\ Component\\ Filesystem\\ Filesystem::copy ` method to copy single
263
263
files)::
264
264
265
- $fileSystem ->mirror('/path/to/source', '/path/to/target');
265
+ $filesystem ->mirror('/path/to/source', '/path/to/target');
266
266
267
267
isAbsolutePath
268
268
~~~~~~~~~~~~~~
@@ -271,13 +271,13 @@ isAbsolutePath
271
271
``true `` if the given path is absolute, ``false `` otherwise::
272
272
273
273
// returns true
274
- $fileSystem ->isAbsolutePath('/tmp');
274
+ $filesystem ->isAbsolutePath('/tmp');
275
275
// returns true
276
- $fileSystem ->isAbsolutePath('c:\\Windows');
276
+ $filesystem ->isAbsolutePath('c:\\Windows');
277
277
// returns false
278
- $fileSystem ->isAbsolutePath('tmp');
278
+ $filesystem ->isAbsolutePath('tmp');
279
279
// returns false
280
- $fileSystem ->isAbsolutePath('../dir');
280
+ $filesystem ->isAbsolutePath('../dir');
281
281
282
282
tempnam
283
283
~~~~~~~
@@ -296,7 +296,7 @@ file first and then moves it to the new file location when it's finished.
296
296
This means that the user will always see either the complete old file or
297
297
complete new file (but never a partially-written file)::
298
298
299
- $fileSystem ->dumpFile('file.txt', 'Hello World');
299
+ $filesystem ->dumpFile('file.txt', 'Hello World');
300
300
301
301
The ``file.txt `` file contains ``Hello World `` now.
302
302
@@ -306,7 +306,7 @@ appendToFile
306
306
:method: `Symfony\\ Component\\ Filesystem\\ Filesystem::appendToFile ` adds new
307
307
contents at the end of some file::
308
308
309
- $fileSystem ->appendToFile('logs.txt', 'Email sent to user@example.com');
309
+ $filesystem ->appendToFile('logs.txt', 'Email sent to user@example.com');
310
310
311
311
If either the file or its containing directory doesn't exist, this method
312
312
creates them before appending the contents.
0 commit comments