Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Loader / AbstractFileLoader.php
1 <?php
2
3 /*
4  * This file is part of the Behat Gherkin.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Gherkin\Loader;
12
13 /**
14  * Abstract filesystem loader.
15  *
16  * @author Konstantin Kudryashov <ever.zet@gmail.com>
17  */
18 abstract class AbstractFileLoader implements FileLoaderInterface
19 {
20     protected $basePath;
21
22     /**
23      * Sets base features path.
24      *
25      * @param string $path Base loader path
26      */
27     public function setBasePath($path)
28     {
29         $this->basePath = realpath($path);
30     }
31
32     /**
33      * Finds relative path for provided absolute (relative to base features path).
34      *
35      * @param string $path Absolute path
36      *
37      * @return string
38      */
39     protected function findRelativePath($path)
40     {
41         if (null !== $this->basePath) {
42             return strtr($path, array($this->basePath . DIRECTORY_SEPARATOR => ''));
43         }
44
45         return $path;
46     }
47
48     /**
49      * Finds absolute path for provided relative (relative to base features path).
50      *
51      * @param string $path Relative path
52      *
53      * @return string
54      */
55     protected function findAbsolutePath($path)
56     {
57         if (is_file($path) || is_dir($path)) {
58             return realpath($path);
59         }
60
61         if (null === $this->basePath) {
62             return false;
63         }
64
65         if (is_file($this->basePath . DIRECTORY_SEPARATOR . $path)
66                || is_dir($this->basePath . DIRECTORY_SEPARATOR . $path)) {
67             return realpath($this->basePath . DIRECTORY_SEPARATOR . $path);
68         }
69
70         return false;
71     }
72 }