Skip to content

Cleaned the FileSystem docs #2591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions components/filesystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ endpoint for filesystem operations::
Mkdir
~~~~~

Mkdir creates directory. On posix filesystems, directories are created with a
default mode value `0777`. You can use the second argument to set your own mode::
:method:`Symfony\\Component\\Filesystem\\Filesystem::mkdir` creates directory.
On posix filesystems, directories are created with a default mode value
`0777`. You can use the second argument to set your own mode::

$fs->mkdir('/tmp/photos', 0700);

Expand All @@ -64,8 +65,8 @@ default mode value `0777`. You can use the second argument to set your own mode:
Exists
~~~~~~

Exists checks for the presence of all files or directories and returns false if a
file is missing::
:method:`Symfony\\Component\\Filesystem\\Filesystem::exists` checks for the
presence of all files or directories and returns false if a file is missing::

// this directory exists, return true
$fs->exists('/tmp/photos');
Expand All @@ -81,9 +82,10 @@ file is missing::
Copy
~~~~

This method is used to copy files. If the target already exists, the file is
copied only if the source modification date is later than the target. This
behavior can be overridden by the third boolean argument::
:method:`Symfony\\Component\\Filesystem\\Filesystem::copy` is used to copy
files. If the target already exists, the file is copied only if the source
modification date is later than the target. This behavior can be overridden by
the third boolean argument::

// works only if image-ICC has been modified after image.jpg
$fs->copy('image-ICC.jpg', 'image.jpg');
Expand All @@ -94,9 +96,9 @@ behavior can be overridden by the third boolean argument::
Touch
~~~~~

Touch sets access and modification time for a file. The current time is used by
default. You can set your own with the second argument. The third argument is
the access time::
:method:`Symfony\\Component\\Filesystem\\Filesystem::touch` sets access and
modification time for a file. The current time is used by default. You can set
your own with the second argument. The third argument is the access time::

// set modification time to the current timestamp
$fs->touch('file.txt');
Expand All @@ -113,8 +115,8 @@ the access time::
Chown
~~~~~

Chown is used to change the owner of a file. The third argument is a boolean
recursive option::
:method:`Symfony\\Component\\Filesystem\\Filesystem::chown` is used to change
the owner of a file. The third argument is a boolean recursive option::

// set the owner of the lolcat video to www-data
$fs->chown('lolcat.mp4', 'www-data');
Expand All @@ -129,8 +131,8 @@ recursive option::
Chgrp
~~~~~

Chgrp is used to change the group of a file. The third argument is a boolean
recursive option::
:method:`Symfony\\Component\\Filesystem\\Filesystem::chgrp` is used to change
the group of a file. The third argument is a boolean recursive option::

// set the group of the lolcat video to nginx
$fs->chgrp('lolcat.mp4', 'nginx');
Expand All @@ -146,8 +148,8 @@ recursive option::
Chmod
~~~~~

Chmod is used to change the mode of a file. The fourth argument is a boolean
recursive option::
:method:`Symfony\\Component\\Filesystem\\Filesystem::chmod` is used to change
the mode of a file. The fourth argument is a boolean recursive option::

// set the mode of the video to 0600
$fs->chmod('video.ogg', 0600);
Expand All @@ -162,7 +164,8 @@ recursive option::
Remove
~~~~~~

Remove let's you remove files, symlink, directories easily::
:method:`Symfony\\Component\\Filesystem\\Filesystem::remove` let's you remove
files, symlink, directories easily::

$fs->remove(array('symlink', '/path/to/directory', 'activity.log'));

Expand All @@ -174,7 +177,8 @@ Remove let's you remove files, symlink, directories easily::
Rename
~~~~~~

Rename is used to rename files and directories::
:method:`Symfony\\Component\\Filesystem\\Filesystem::rename` is used to rename
files and directories::

//rename a file
$fs->rename('/tmp/processed_video.ogg', '/path/to/store/video_647.ogg');
Expand All @@ -184,8 +188,9 @@ Rename is used to rename files and directories::
symlink
~~~~~~~

Creates a symbolic link from the target to the destination. If the filesystem
does not support symbolic links, a third boolean argument is available::
:method:`Symfony\\Component\\Filesystem\\Filesystem::symlink` creates a
symbolic link from the target to the destination. If the filesystem does not
support symbolic links, a third boolean argument is available::

// create a symbolic link
$fs->symlink('/path/to/source', '/path/to/destination');
Expand All @@ -196,7 +201,8 @@ does not support symbolic links, a third boolean argument is available::
makePathRelative
~~~~~~~~~~~~~~~~

Return the relative path of a directory given another one::
:method:`Symfony\\Component\\Filesystem\\Filesystem::makePathRelative` returns
the relative path of a directory given another one::

// returns '../'
$fs->makePathRelative(
Expand All @@ -209,14 +215,16 @@ Return the relative path of a directory given another one::
mirror
~~~~~~

Mirrors a directory::
:method:`Symfony\\Component\\Filesystem\\Filesystem::mirror` mirrors a
directory::

$fs->mirror('/path/to/source', '/path/to/target');

isAbsolutePath
~~~~~~~~~~~~~~

isAbsolutePath returns true if the given path is absolute, false otherwise::
:method:`Symfony\\Component\\Filesystem\\Filesystem::isAbsolutePath` returns
``true`` if the given path is absolute, false otherwise::

// return true
$fs->isAbsolutePath('/tmp');
Expand All @@ -236,9 +244,9 @@ thrown.

.. note::

Prior to version 2.1, :method:`Symfony\\Component\\Filesystem\\Filesystem::mkdir`
returned a boolean and did not throw exceptions. As of 2.1, a
:class:`Symfony\\Component\\Filesystem\\Exception\\IOException` is
thrown if a directory creation fails.
Prior to version 2.1, ``mkdir`` returned a boolean and did not throw
exceptions. As of 2.1, a
:class:`Symfony\\Component\\Filesystem\\Exception\\IOException` is thrown
if a directory creation fails.

.. _`Packagist`: https://packagist.org/packages/symfony/filesystem