| 1 | <?php |
||
| 21 | class File extends Abstraction |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Validate path. |
||
| 25 | * |
||
| 26 | * @param string $path |
||
| 27 | * @return boolean |
||
| 28 | */ |
||
| 29 | 5 | public function isPathValid($path) : bool |
|
| 30 | { |
||
| 31 | 5 | return is_file($path); |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns the executable for this action. |
||
| 36 | * |
||
| 37 | * @param \phpbu\App\Backup\Target $target |
||
| 38 | * @return \phpbu\App\Cli\Executable |
||
| 39 | * @throws \phpbu\App\Exception |
||
| 40 | 3 | */ |
|
| 41 | 3 | protected function createExecutable(Target $target) : Executable |
|
| 42 | 1 | { |
|
| 43 | 1 | if (!$target->shouldBeCompressed()) { |
|
| 44 | 1 | throw new Exception('target should not be compressed at all'); |
|
| 45 | 1 | } |
|
| 46 | 3 | $executable = new Compressor($target->getCompression()->getCommand(), $this->pathToCommand); |
|
| 47 | $executable->force(true)->compressFile($this->path); |
||
| 48 | return $executable; |
||
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * Return final archive file. |
||
| 54 | * |
||
| 55 | * @param \phpbu\App\Backup\Target $target |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function getArchiveFile(Target $target) : string |
||
| 62 | } |
||
| 63 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: