Skip to content

[WIP] Explicitly Declare Twig "Paths", deprecate old syntaxes #13928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Bundle/Bundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Bundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle as BaseBundle;

class Bundle extends BaseBundle
{
private $twigPaths = array();

protected function addTwigPath($templateDirectory, $namespace)
{
$this->twigPaths[$namespace] = $templateDirectory;
}

public function build(ContainerBuilder $container)
{
foreach ($this->twigPaths as $namespace => $directory) {
if (!is_dir($directory)) {
throw new \InvalidArgumentException(sprintf(
'Directory "%s" does not exist, so it cannot be added as a Twig path', $directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symfony doesn't wrap lines like that, this should all be on one line

));
}

$container->prependExtensionConfig('twig', array(
'paths' => array($directory => $namespace)
));
}
}


}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing final new line feed :)

Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ protected function getCacheKey($template)
*
* @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface
* @throws \InvalidArgumentException When the template file can not be found
*
* @deprecated since version 2.8, to be removed in 3.0.
*/
public function locate($template, $currentPath = null, $first = true)
{
trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will 2.8 ever exist?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not settled yet. This is in discussion in the core team


if (!$template instanceof TemplateReferenceInterface) {
throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* "bundle:section:template.format.engine" to TemplateReferenceInterface
* instances.
*
* @deprecated since version 2.8, to be removed in 3.0
* @author Fabien Potencier <fabien@symfony.com>
*/
class TemplateNameParser extends BaseTemplateNameParser
Expand Down Expand Up @@ -48,6 +49,8 @@ public function parse($name)
return $this->cache[$name];
}

trigger_error('The "bundle:section:template.format.engine" syntax is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);

// normalize name
$name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ public function load(array $configs, ContainerBuilder $container)
if (!$namespace) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path));
} else {
// register the "override" path
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$namespace.'/views')) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir, $namespace));
}

$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
}
}

// register bundles as Twig namespaces
// register bundles as Twig namespaces (deprecated)
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
Expand Down Expand Up @@ -120,6 +125,9 @@ public function load(array $configs, ContainerBuilder $container)
));
}

/**
* @deprecated The automatic @AcmeDemo (for AcmeDemoBundle) Twig path was deprecated in 2.8 and will be removed in 3.0
*/
private function addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle)
{
$name = $bundle;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function findTemplate($template)
} catch (\Twig_Error_Loader $e) {
$previous = $e;

// for BC
// deprecated - supports the bundle:directory:filename.format.engine format
try {
$template = $this->parser->parse($template);
$file = $this->locator->locate($template);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy