public function Kernel::locateResource in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Kernel.php \Symfony\Component\HttpKernel\Kernel::locateResource()
Throws
\RuntimeException if a custom resource is hidden by a resource in a derived bundle
Overrides KernelInterface::locateResource
File
- vendor/
symfony/ http-kernel/ Kernel.php, line 244
Class
- Kernel
- The Kernel is the heart of the Symfony system.
Namespace
Symfony\Component\HttpKernelCode
public function locateResource($name, $dir = null, $first = true) {
if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
}
if (false !== strpos($name, '..')) {
throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
}
$bundleName = substr($name, 1);
$path = '';
if (false !== strpos($bundleName, '/')) {
list($bundleName, $path) = explode('/', $bundleName, 2);
}
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
$overridePath = substr($path, 9);
$resourceBundle = null;
$bundles = $this
->getBundle($bundleName, false);
$files = array();
foreach ($bundles as $bundle) {
if ($isResource && file_exists($file = $dir . '/' . $bundle
->getName() . $overridePath)) {
if (null !== $resourceBundle) {
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.', $file, $resourceBundle, $dir . '/' . $bundles[0]
->getName() . $overridePath));
}
if ($first) {
return $file;
}
$files[] = $file;
}
if (file_exists($file = $bundle
->getPath() . '/' . $path)) {
if ($first && !$isResource) {
return $file;
}
$files[] = $file;
$resourceBundle = $bundle
->getName();
}
}
if (count($files) > 0) {
return $first && $isResource ? $files[0] : $files;
}
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
}