1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types=1); |
20
|
|
|
|
21
|
|
|
namespace ProxyManager\Exception; |
22
|
|
|
|
23
|
|
|
use UnexpectedValueException; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Exception for non writable files |
27
|
|
|
* |
28
|
|
|
* @author Marco Pivetta <[email protected]> |
29
|
|
|
* @license MIT |
30
|
|
|
*/ |
31
|
|
|
class FileNotWritableException extends UnexpectedValueException implements ExceptionInterface |
32
|
|
|
{ |
33
|
|
|
public static function fromInvalidMoveOperation(string $fromPath, string $toPath) : self |
34
|
|
|
{ |
35
|
|
|
return new self(sprintf( |
36
|
|
|
'Could not move file "%s" to location "%s": ' |
37
|
1 |
|
. 'either the source file is not readable, or the destination is not writable', |
38
|
|
|
$fromPath, |
39
|
1 |
|
$toPath |
40
|
|
|
)); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
public static function fromNonWritableLocation($path) : self |
44
|
|
|
{ |
45
|
|
|
$messages = []; |
46
|
|
|
$destination = realpath($path); |
47
|
|
|
|
48
|
|
|
if (! $destination) { |
49
|
|
|
$messages[] = 'path does not exist'; |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
if ($destination && ! is_file($destination)) { |
53
|
|
|
$messages[] = 'exists and is not a file'; |
54
|
2 |
|
} |
55
|
|
|
|
56
|
2 |
|
if ($destination && ! is_writable($destination)) { |
57
|
1 |
|
$messages[] = 'is not writable'; |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
return new self(sprintf('Could not write to path "%s": %s', $path, implode(', ', $messages))); |
61
|
1 |
|
} |
62
|
|
|
} |
63
|
|
|
|