locateResource() 공개 메소드

A Resource can be a file or a directory. The resource name must follow the following pattern: @/path/to/a/file.something where BundleName is the name of 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", this method will look for a file named: $dir//path/without/Resources before looking in the bundle resource folder.
public locateResource ( string $name, string $dir = null, boolean $first = true ) : string | array
$name string A resource name to locate
$dir string A directory where to look for the resource first
$first boolean Whether to return the first path or paths for all matching bundles
리턴 string | array The absolute path of the resource or an array if $first is false
 public function getFilters()
 {
     $client = new \Mleko\ImageSqueeze\Client\Client();
     $squeeze = new \Twig_SimpleFilter('squeeze', function ($path) use($client) {
         $path = (string) $path;
         if (strlen($path) > 0 && $path[0] === '@') {
             $path = $this->kernel->locateResource($path);
         }
         if (file_exists($path)) {
             $inputFile = new \Mleko\ImageSqueeze\Client\File($path);
         } else {
             $inputFile = new \Mleko\ImageSqueeze\Client\File($path, $this->webRoot);
         }
         $pathHash = str_pad(base_convert(sha1($path), 16, 36), 31, '0', STR_PAD_LEFT);
         $compressedName = implode("/", str_split(substr($pathHash, 0, 6), 1)) . "/" . substr($pathHash, 6);
         if (false !== ($dotPosition = strrpos($path, "."))) {
             $compressedName .= substr($path, $dotPosition);
         }
         $newPath = '/cache/image/' . $compressedName;
         $fullPath = $this->webRoot . $newPath;
         if (!file_exists($fullPath)) {
             $newDir = dirname($fullPath);
             if (!file_exists($newDir)) {
                 mkdir($newDir, 0777, true);
             }
             return $client->shrink($inputFile)->toFile($newPath, $this->webRoot);
         }
         return new \Mleko\ImageSqueeze\Client\File($newPath, $this->webRoot);
     });
     return ['squeeze' => $squeeze];
 }
예제 #2
0
 protected function copyTemplates()
 {
     $from = $this->kernel->locateResource('@AnimeDbCatalogBundle/Resources/views/');
     $to = $this->root_dir . '/Resources/';
     // overwrite twig error templates
     $this->fs->copy($from . 'errors/error.html.twig', $to . 'TwigBundle/views/Exception/error.html.twig', true);
     $this->fs->copy($from . 'errors/error404.html.twig', $to . 'TwigBundle/views/Exception/error404.html.twig', true);
 }
예제 #3
0
 public function resolveTargetFormType($name)
 {
     $parts = preg_split('/:/', $name);
     $bundleName = $parts[0];
     $formType = $parts[1];
     $bundlePath = $this->kernel->locateResource(sprintf('@%s', $bundleName));
     $path = sprintf('%sForm/Type/%sType.php', $bundlePath, $formType);
     return $path;
 }
 protected function resolve($groups, $input)
 {
     $resolved = array();
     if (strpos($input, '@') === false) {
         return array($this->webdir . '/' . $input);
     }
     $cleaned = str_replace('@', '', $input);
     if (isset($groups[$cleaned])) {
         foreach ($groups[$cleaned]['inputs'] as $candidate) {
             $resolved = array_merge($resolved, $this->resolve($groups, $candidate));
         }
         return $resolved;
     }
     if (($star = strpos($input, '*')) === false) {
         return array($this->kernel->locateResource($input));
     } else {
         $dir = $this->kernel->locateResource(substr($input, 0, $star));
         $it = new \DirectoryIterator($dir);
         foreach ($it as $file) {
             if ($file->isFile()) {
                 array_push($resolved, $it->getRealPath());
             }
         }
     }
     return $resolved;
 }
 public function let(IntentDocumentGeneratedEvent $event, RumGeneratorInterface $rumGenerator, Intent $intent, Kernel $kernel)
 {
     $this->event = $event;
     $this->rumGenerator = $rumGenerator;
     $this->intent = $intent;
     $this->kernel = $kernel;
     $this->event->getIntent()->willReturn($this->intent);
     $kernel->locateResource('@DonatePaymentBundle/Resources/public/img/sepa-template.jpg')->willReturn(__DIR__ . '/test.jpg');
     $this->beConstructedWith($rumGenerator, $kernel);
 }
예제 #6
0
 /**
  * Construct the manager
  *
  * @param Kernel $kernel
  * @param string $path
  * @param string $maskBuilder
  */
 public function __construct(Kernel $kernel, $path, $maskBuilder)
 {
     $this->maskBuilder = $maskBuilder;
     $path = $kernel->locateResource('@' . $path);
     $config = Yaml::parse($path);
     $this->config = $config['acl_config'];
     $replace = array();
     if (isset($config['parameters'])) {
         foreach ($config['parameters'] as $k => $v) {
             $replace['%' . $k . '%'] = $v;
         }
         $this->config = $this->replaceParameters($this->config, $replace);
     }
     return $this->config;
 }
 public function locateResource($name, $dir = null, $first = true)
 {
     if (substr($name, 0, 4) == '@Kwc') {
         if (!$first) {
             throw new \Kwf_Exception_NotYetImplemented();
         }
         $componentClass = substr($name, 4, strpos($name, '/') - 4);
         $name = substr($name, strpos($name, '/') + 1);
         $paths = \Kwc_Abstract::getSetting($componentClass, 'parentFilePaths');
         foreach ($paths as $path => $cls) {
             if (file_exists($path . '/' . $name)) {
                 return $path . '/' . $name;
             }
         }
         throw new \Kwf_Exception();
     } else {
         return parent::locateResource($name, $dir, $first);
     }
 }
 /**
  * Returns an UploadedFile based on a source file
  * @param  string $source 
  * @return UploadedFile
  */
 public function uploadfile($source)
 {
     $source = $this->kernel->locateResource($source);
     return new UploadedFile($source, basename($source));
 }
 /**
  * @param string $name
  * @param string $dir
  * @param bool $first
  * @return string|array
  */
 public function locateResource($name, $dir = null, $first = true)
 {
     return $this->kernel->locateResource($name, $dir, $first);
 }
예제 #10
0
 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
  */
 public function locateResource($name, $dir = null, $first = true)
 {
     $themeBundle = $this->container->get('zikula_core.common.theme_engine')->getTheme();
     $locations = parent::locateResource($name, $dir, false);
     if ($locations && false !== strpos($locations[0], $dir)) {
         // if found in $dir (typically app/Resources) return it immediately.
         return $locations[0];
     }
     // add theme path to template locator
     // this method functions if the controller uses `@Template` or `ZikulaSpecModule:Foo:index.html.twig` naming scheme
     // if `@ZikulaSpecModule/Foo/index.html.twig` (name-spaced) naming scheme is used
     // the \Zikula\Bundle\CoreBundle\EventListener\ThemeListener::setUpThemePathOverrides method is used instead
     if ($themeBundle && false === strpos($name, $themeBundle->getName())) {
         // do not add theme override path to theme files
         $customThemePath = $themeBundle->getPath() . '/Resources';
         return parent::locateResource($name, $customThemePath, true);
     }
     return $locations[0];
 }