Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PathValidator.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
14 
21 {
25  private $driver;
26 
30  public function __construct(DriverInterface $driver)
31  {
32  $this->driver = $driver;
33  }
34 
38  public function validate(
39  string $directoryPath,
40  string $path,
41  ?string $scheme = null,
42  bool $absolutePath = false
43  ): void {
44  $realDirectoryPath = $this->driver->getRealPathSafety($directoryPath);
45  if ($realDirectoryPath[-1] !== DIRECTORY_SEPARATOR) {
46  $realDirectoryPath .= DIRECTORY_SEPARATOR;
47  }
48  if (!$absolutePath) {
49  $actualPath = $this->driver->getRealPathSafety(
50  $this->driver->getAbsolutePath(
51  $realDirectoryPath,
52  $path,
53  $scheme
54  )
55  );
56  } else {
57  $actualPath = $this->driver->getRealPathSafety($path);
58  }
59 
60  if (mb_strpos($actualPath, $realDirectoryPath) !== 0
61  && $path .DIRECTORY_SEPARATOR !== $realDirectoryPath
62  ) {
63  throw new ValidatorException(
64  new Phrase(
65  'Path "%1" cannot be used with directory "%2"',
66  [$path, $directoryPath]
67  )
68  );
69  }
70  }
71 }
validate(string $directoryPath, string $path, ?string $scheme=null, bool $absolutePath=false)