c85bed20e9
This PR was merged into the 2.6-dev branch.
Discussion
----------
[Filesystem] Added a LockHandler
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #9357 , #3586
| License | MIT
| Doc PR | https://github.com/symfony/symfony-docs/pull/3956/files
Code sample:
```php
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$lockHelper = new LockHandler('/tmp/acme/hello.lock');
if (!$lockHelper->lock()) {
$output->writeln('The command is already running in another process.');
return 0;
}
$output->writeln(sprintf('Hello <comment>%s</comment>!', $input->getArgument('who')));
for (;;) {
}
$output->writeln(sprintf('bye <comment>%s</comment>!', $input->getArgument('who')));
$lockHelper->unlock();
}
```
![process-lock](https://f.cloud.github.com/assets/408368/2443205/4f0bf3e8-ae30-11e3-9bd4-78e09e2973ad.png)
Commits
-------
|
||
---|---|---|
.. | ||
Exception | ||
Tests | ||
.gitignore | ||
CHANGELOG.md | ||
composer.json | ||
Filesystem.php | ||
LICENSE | ||
LockHandler.php | ||
phpunit.xml.dist | ||
README.md |
Filesystem Component
Filesystem provides basic utility to manipulate the file system:
<?php
use Symfony\Component\Filesystem\Filesystem;
$filesystem = new Filesystem();
$filesystem->copy($originFile, $targetFile, $override = false);
$filesystem->mkdir($dirs, $mode = 0777);
$filesystem->touch($files, $time = null, $atime = null);
$filesystem->remove($files);
$filesystem->chmod($files, $mode, $umask = 0000, $recursive = false);
$filesystem->chown($files, $user, $recursive = false);
$filesystem->chgrp($files, $group, $recursive = false);
$filesystem->rename($origin, $target);
$filesystem->symlink($originDir, $targetDir, $copyOnWindows = false);
$filesystem->makePathRelative($endPath, $startPath);
$filesystem->mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array());
$filesystem->isAbsolutePath($file);
Resources
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/Filesystem/
$ composer.phar install
$ phpunit