Projet

Général

Profil

Paste
Télécharger (1,43 ko) Statistiques
| Branche: | Révision:

root / drupal7 / misc / typo3 / phar-stream-wrapper / src / Interceptor / PharExtensionInterceptor.php @ cd5c298a

1
<?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\Helper;
16
use TYPO3\PharStreamWrapper\Exception;
17

    
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
        $baseFile = Helper::determineBaseFile($path);
49
        if ($baseFile === null) {
50
            return false;
51
        }
52
        $fileExtension = pathinfo($baseFile, PATHINFO_EXTENSION);
53
        return strtolower($fileExtension) === 'phar';
54
    }
55
}