コード例 #1
0
 function it_locates_resource(PathCheckerInterface $pathChecker, KernelInterface $kernel, BundleInterface $bundle)
 {
     $bundle->getName()->willReturn("Bundle");
     $bundle->getPath()->willReturn("/app/bundle");
     $kernel->getBundle("Bundle", false)->willReturn([$bundle]);
     $pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/bundle/resource");
     $this->locateResource("@Bundle/Resources/resource", [])->shouldReturn("/app/bundle/resource");
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function locateResource($resourceName, array $themes = [])
 {
     if (false !== strpos($resourceName, '..')) {
         throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $resourceName));
     }
     $bundleName = substr($resourceName, 1);
     $resourcePath = '';
     if (false !== strpos($bundleName, '/')) {
         list($bundleName, $resourcePath) = explode('/', $bundleName, 2);
     }
     if (0 !== strpos($resourcePath, 'Resources')) {
         throw new \RuntimeException('Template files have to be in Resources.');
     }
     $bundles = $this->kernel->getBundle($bundleName, false);
     $parameters = array_merge($this->parameters, ['%override_path%' => substr($resourcePath, strlen('Resources/'))]);
     foreach ($bundles as $bundle) {
         $parameters = array_merge($parameters, ['%bundle_name%' => $bundle->getName(), '%bundle_path%' => $bundle->getPath()]);
         $checkedPath = $this->pathChecker->processPaths($this->paths, $parameters, $themes);
         if (null !== $checkedPath) {
             return $checkedPath;
         }
     }
     return null;
 }
コード例 #3
0
 function it_locates_resource(PathCheckerInterface $pathChecker)
 {
     $pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/resource");
     $this->locateResource("resource", [])->shouldReturn("/app/resource");
 }