/** * {@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; }
/** * {@inheritdoc} */ public function parse($name) { if ($name instanceof TemplateReferenceInterface) { return $name; } else { if (isset($this->cache[$name])) { return $this->cache[$name]; } } // normalize name $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'))); if (false !== strpos($name, '..')) { throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name)); } $parts = explode(':', $name); if (3 !== count($parts)) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); } $elements = explode('.', $parts[2]); if (3 !== count($elements)) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); } $template = new TemplateReference($parts[0], $parts[1], $elements[0], $elements[1], $elements[2]); 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; }
/** * {@inheritdoc} */ public function parse($name) { if ($name instanceof TemplateReferenceInterface) { return $name; } elseif (isset($this->cache[$name])) { return $this->cache[$name]; } if (!preg_match('/^(?:@([^\\/]*)|)(?:\\/(.+))?\\/(.+)\\.([^\\.]+)\\.([^\\.]+)$/', $name, $matches)) { return $this->decoratedParser->parse($name); } $template = new TemplateReference($matches[1] ? $matches[1] . 'Bundle' : '', $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; }