1 | <?php |
||
23 | class Parser { |
||
24 | const MSG_NOT_FOUND = 'Error opening local file '; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $timeZone; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $host; |
||
35 | |||
36 | // todo replace with static once <5.6 support is dropped |
||
37 | // see error.h |
||
38 | const EXCEPTION_MAP = [ |
||
39 | ErrorCodes::LogonFailure => AuthenticationException::class, |
||
40 | ErrorCodes::PathNotFound => NotFoundException::class, |
||
41 | ErrorCodes::ObjectNotFound => NotFoundException::class, |
||
42 | ErrorCodes::NoSuchFile => NotFoundException::class, |
||
43 | ErrorCodes::NameCollision => AlreadyExistsException::class, |
||
44 | ErrorCodes::AccessDenied => AccessDeniedException::class, |
||
45 | ErrorCodes::DirectoryNotEmpty => NotEmptyException::class, |
||
46 | ErrorCodes::FileIsADirectory => InvalidTypeException::class, |
||
47 | ErrorCodes::NotADirectory => InvalidTypeException::class, |
||
48 | ErrorCodes::SharingViolation => FileInUseException::class, |
||
49 | ErrorCodes::InvalidParameter => InvalidParameterException::class |
||
50 | ]; |
||
51 | |||
52 | const MODE_STRINGS = [ |
||
53 | 'R' => FileInfo::MODE_READONLY, |
||
54 | 'H' => FileInfo::MODE_HIDDEN, |
||
55 | 'S' => FileInfo::MODE_SYSTEM, |
||
56 | 'D' => FileInfo::MODE_DIRECTORY, |
||
57 | 'A' => FileInfo::MODE_ARCHIVE, |
||
58 | 'N' => FileInfo::MODE_NORMAL |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @param string $timeZone |
||
63 | */ |
||
64 | 1088 | public function __construct($timeZone) { |
|
67 | |||
68 | 80 | private function getErrorCode($line) { |
|
69 | 80 | $parts = explode(' ', $line); |
|
70 | 80 | foreach ($parts as $part) { |
|
71 | 80 | if (substr($part, 0, 9) === 'NT_STATUS') { |
|
72 | 80 | return $part; |
|
73 | } |
||
74 | } |
||
75 | 8 | return false; |
|
76 | } |
||
77 | |||
78 | 80 | public function checkForError($output, $path) { |
|
79 | 80 | if (strpos($output[0], 'does not exist')) { |
|
80 | throw new NotFoundException($path); |
||
81 | } |
||
82 | 80 | $error = $this->getErrorCode($output[0]); |
|
83 | |||
84 | 80 | if (substr($output[0], 0, strlen(self::MSG_NOT_FOUND)) === self::MSG_NOT_FOUND) { |
|
85 | 4 | $localPath = substr($output[0], strlen(self::MSG_NOT_FOUND)); |
|
86 | 4 | throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing'); |
|
87 | } |
||
88 | |||
89 | 80 | throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * check if the first line holds a connection failure |
||
94 | * |
||
95 | * @param $line |
||
96 | * @throws AuthenticationException |
||
97 | * @throws InvalidHostException |
||
98 | * @throws NoLoginServerException |
||
99 | * @throws AccessDeniedException |
||
100 | */ |
||
101 | 1040 | public function checkConnectionError($line) { |
|
122 | |||
123 | 460 | public function parseMode($mode) { |
|
124 | 460 | $result = 0; |
|
132 | |||
133 | 16 | public function parseStat($output) { |
|
153 | |||
154 | 1008 | public function parseDir($output, $basePath) { |
|
172 | |||
173 | 8 | public function parseListShares($output) { |
|
189 | } |
||
190 |