/**
  * @param Method $method
  * @return array
  */
 public function resolve(Method $method)
 {
     /** @var Annotation $annotation */
     $annotation = $method->annotations->withName('Template')->first();
     // テンプレート名を取得する
     $name = array_shift($annotation->parameters);
     if (!$name) {
         $templateReference = $this->guessTemplateName($method->class->getFQCN(), str_replace('Action', '', $method->name));
     } else {
         $templateReference = $this->templateNameParser->parse($this->kernel->getRootDir() . '/Resources/views/' . $name);
     }
     $template = $this->loader->load($templateReference);
     return ['method' => $method, 'name' => $name, 'template' => $templateReference, 'path' => $template];
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function parse($name)
 {
     if ($name instanceof TemplateReferenceInterface) {
         return $name;
     } elseif (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     // normalize name
     $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name)));
     if (false !== strpos($name, '..')) {
         throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
     }
     if (!preg_match('/^([^:]*):([^:]*):(.+)\\.([^\\.]+)\\.([^\\.]+)$/', $name, $matches)) {
         return parent::parse($name);
     }
     $template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
     if ($template->get('bundle')) {
         try {
             $this->kernel->getBundle($template->get('bundle'));
         } catch (\Exception $e) {
             throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
         }
     }
     return $this->cache[$name] = $template;
 }
 private function fallback($name)
 {
     if ($this->fallback) {
         return $this->fallback->parse($name);
     } else {
         return parent::parse($name);
     }
 }