root / drupal7 / misc / typo3 / phar-stream-wrapper / src / Interceptor / PharExtensionInterceptor.php @ fbb66ca6
1 | cd5c298a | Geoffroy Desvernay | <?php
|
---|---|---|---|
2 | namespace TYPO3\PharStreamWrapper\Interceptor; |
||
3 | |||
4 | /*
|
||
5 | * This file is part of the TYPO3 project.
|
||
6 | *
|
||
7 | * It is free software; you can redistribute it and/or modify it under the terms
|
||
8 | * of the MIT License (MIT). For the full copyright and license information,
|
||
9 | * please read the LICENSE file that was distributed with this source code.
|
||
10 | *
|
||
11 | * The TYPO3 project - inspiring people to share!
|
||
12 | */
|
||
13 | |||
14 | use TYPO3\PharStreamWrapper\Assertable; |
||
15 | use TYPO3\PharStreamWrapper\Exception; |
||
16 | fbb66ca6 | Assos Assos | use TYPO3\PharStreamWrapper\Manager; |
17 | cd5c298a | Geoffroy Desvernay | |
18 | class PharExtensionInterceptor implements Assertable |
||
19 | { |
||
20 | /**
|
||
21 | * Determines whether the base file name has a ".phar" suffix.
|
||
22 | *
|
||
23 | * @param string $path
|
||
24 | * @param string $command
|
||
25 | * @return bool
|
||
26 | * @throws Exception
|
||
27 | */
|
||
28 | public function assert($path, $command) |
||
29 | { |
||
30 | if ($this->baseFileContainsPharExtension($path)) { |
||
31 | return true; |
||
32 | } |
||
33 | throw new Exception( |
||
34 | sprintf(
|
||
35 | 'Unexpected file extension in "%s"',
|
||
36 | $path
|
||
37 | ), |
||
38 | 1535198703
|
||
39 | ); |
||
40 | } |
||
41 | |||
42 | /**
|
||
43 | * @param string $path
|
||
44 | * @return bool
|
||
45 | */
|
||
46 | private function baseFileContainsPharExtension($path) |
||
47 | { |
||
48 | fbb66ca6 | Assos Assos | $invocation = Manager::instance()->resolve($path); |
49 | if ($invocation === null) { |
||
50 | cd5c298a | Geoffroy Desvernay | return false; |
51 | } |
||
52 | fbb66ca6 | Assos Assos | $fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION); |
53 | cd5c298a | Geoffroy Desvernay | return strtolower($fileExtension) === 'phar'; |
54 | } |
||
55 | } |