Нет описания

FileLocator.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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. namespace Symfony\Component\HttpKernel\Config;
  11. use Symfony\Component\Config\FileLocator as BaseFileLocator;
  12. use Symfony\Component\HttpKernel\KernelInterface;
  13. /**
  14. * FileLocator uses the KernelInterface to locate resources in bundles.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class FileLocator extends BaseFileLocator
  19. {
  20. private $kernel;
  21. /**
  22. * @deprecated since Symfony 4.4
  23. */
  24. private $path;
  25. public function __construct(KernelInterface $kernel/*, string $path = null, array $paths = [], bool $triggerDeprecation = true*/)
  26. {
  27. $this->kernel = $kernel;
  28. if (2 <= \func_num_args()) {
  29. $this->path = func_get_arg(1);
  30. $paths = 3 <= \func_num_args() ? func_get_arg(2) : [];
  31. if (null !== $this->path) {
  32. $paths[] = $this->path;
  33. }
  34. if (4 !== \func_num_args() || func_get_arg(3)) {
  35. @trigger_error(sprintf('Passing more than one argument to %s is deprecated since Symfony 4.4 and will be removed in 5.0.', __METHOD__), \E_USER_DEPRECATED);
  36. }
  37. } else {
  38. $paths = [];
  39. }
  40. parent::__construct($paths);
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function locate($file, $currentPath = null, $first = true)
  46. {
  47. if (isset($file[0]) && '@' === $file[0]) {
  48. return $this->kernel->locateResource($file, $this->path, $first, false);
  49. }
  50. $locations = parent::locate($file, $currentPath, $first);
  51. if (isset($file[0]) && !(
  52. '/' === $file[0] || '\\' === $file[0]
  53. || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && ('\\' === $file[2] || '/' === $file[2]))
  54. || null !== parse_url($file, \PHP_URL_SCHEME)
  55. )) {
  56. $deprecation = false;
  57. // no need to trigger deprecations when the loaded file is given as absolute path
  58. foreach ($this->paths as $deprecatedPath) {
  59. foreach ((array) $locations as $location) {
  60. if (null !== $currentPath && str_starts_with($location, $currentPath)) {
  61. return $locations;
  62. }
  63. if (str_starts_with($location, $deprecatedPath) && (null === $currentPath || !str_contains($location, $currentPath))) {
  64. $deprecation = sprintf('Loading the file "%s" from the global resource directory "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $file, $deprecatedPath);
  65. }
  66. }
  67. }
  68. if ($deprecation) {
  69. @trigger_error($deprecation, \E_USER_DEPRECATED);
  70. }
  71. }
  72. return $locations;
  73. }
  74. }