|
@@ -204,15 +204,17 @@ abstract class Kernel implements KernelInterface
|
|
*
|
|
*
|
|
* The resource name must follow the following pattern:
|
|
* The resource name must follow the following pattern:
|
|
*
|
|
*
|
|
- * @BundleName/path/to/a/file.something
|
|
|
|
|
|
+ * @<BundleName>/path/to/a/file.something
|
|
*
|
|
*
|
|
* where BundleName is the name of the bundle
|
|
* where BundleName is the name of the bundle
|
|
* and the remaining part is the relative path in the bundle.
|
|
* and the remaining part is the relative path in the bundle.
|
|
*
|
|
*
|
|
- * If $dir is passed, and the first segment of the path is Resources,
|
|
|
|
|
|
+ * If $dir is passed, and the first segment of the path is "Resources",
|
|
* this method will look for a file named:
|
|
* this method will look for a file named:
|
|
*
|
|
*
|
|
- * $dir/BundleName/path/without/Resources
|
|
|
|
|
|
+ * $dir/<BundleName>Bundle/path/without/Resources
|
|
|
|
+ *
|
|
|
|
+ * before looking in the bundle resource folder.
|
|
*
|
|
*
|
|
* @param string $name A resource name to locate
|
|
* @param string $name A resource name to locate
|
|
* @param string $dir A directory where to look for the resource first
|
|
* @param string $dir A directory where to look for the resource first
|
|
@@ -221,7 +223,8 @@ abstract class Kernel implements KernelInterface
|
|
* @return string|array The absolute path of the resource or an array if $first is false
|
|
* @return string|array The absolute path of the resource or an array if $first is false
|
|
*
|
|
*
|
|
* @throws \InvalidArgumentException if the file cannot be found or the name is not valid
|
|
* @throws \InvalidArgumentException if the file cannot be found or the name is not valid
|
|
- * @throws \RuntimeException if the name contains invalid/unsafe characters
|
|
|
|
|
|
+ * @throws \RuntimeException if the name contains invalid/unsafe
|
|
|
|
+ * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
|
|
*/
|
|
*/
|
|
public function locateResource($name, $dir = null, $first = true)
|
|
public function locateResource($name, $dir = null, $first = true)
|
|
{
|
|
{
|
|
@@ -238,9 +241,20 @@ abstract class Kernel implements KernelInterface
|
|
|
|
|
|
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
|
|
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
|
|
$overridePath = substr($path, 9);
|
|
$overridePath = substr($path, 9);
|
|
|
|
+ $resourceBundle = null;
|
|
|
|
+ $bundles = $this->getBundle($bundleName, false);
|
|
|
|
|
|
- foreach ($this->getBundle($bundleName, false) as $bundle) {
|
|
|
|
|
|
+ foreach ($bundles as $bundle) {
|
|
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().'Bundle'.$overridePath)) {
|
|
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().'Bundle'.$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().'Bundle'.$overridePath
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
if ($first) {
|
|
if ($first) {
|
|
return $file;
|
|
return $file;
|
|
}
|
|
}
|
|
@@ -248,15 +262,16 @@ abstract class Kernel implements KernelInterface
|
|
}
|
|
}
|
|
|
|
|
|
if (file_exists($file = $bundle->getPath().'/'.$path)) {
|
|
if (file_exists($file = $bundle->getPath().'/'.$path)) {
|
|
- if ($first) {
|
|
|
|
|
|
+ if ($first && !$isResource) {
|
|
return $file;
|
|
return $file;
|
|
}
|
|
}
|
|
$files[] = $file;
|
|
$files[] = $file;
|
|
|
|
+ $resourceBundle = $bundle->getName();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ($files) {
|
|
|
|
- return $files;
|
|
|
|
|
|
+ if (count($files) > 0) {
|
|
|
|
+ return $first && $isResource ? $files[0] : $files;
|
|
}
|
|
}
|
|
|
|
|
|
throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name));
|
|
throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name));
|