Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Added missing error codes and turned codes into UUIDs #12388

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 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0642911
[FrameworkBundle] Add a doctrine cache service definition for validat…
jakzal Apr 21, 2015
b93bcc1
Fixed colspan issues with multiple render() calls
jaytaph Jun 14, 2015
f42c777
[Form] moved data trimming logic of TrimListener into StringUtil
issei-m Jun 20, 2015
3151614
feature #14660 [Form] moved data trimming logic of TrimListener into …
webmozart Jun 22, 2015
9f86195
feature #14991 [Console][Table] allow multiple render() calls. (jaytaph)
fabpot Jun 22, 2015
dd7583d
feature #14429 [FrameworkBundle] Add a doctrine cache service definit…
fabpot Jun 23, 2015
f360758
[Debug] Allow throwing from __toString() with `return trigger_error($…
nicolas-grekas Jun 22, 2015
6c4a676
Add "shared" flag and deprecate scopes concept
dosten Jun 15, 2015
50e752b
feature #14984 [DependencyInjection] Deprecate scope concept (dosten)
fabpot Jun 24, 2015
b7030cc
Make service not shared when prototype scope is set
wouterj Jun 24, 2015
bd66434
minor #15091 [2.8] Make service not shared when prototype scope is se…
Tobion Jun 24, 2015
93e69e4
feature #15076 [Debug] Allow throwing from __toString() with `return …
nicolas-grekas Jun 25, 2015
d144dbb
[DependencyInjection] improve deprecation messages
xabbuh Jun 26, 2015
03e96d2
minor #15113 [2.8][DependencyInjection] improve deprecation messages …
fabpot Jun 27, 2015
1583fad
add option to force web server startup
xabbuh Jun 28, 2015
1df4ebe
added remove option to ignoreExtraKeys
Apr 6, 2015
674b124
feature #14238 [config] added remove option to ignoreExtraKeys (twifty)
fabpot Jun 28, 2015
268210b
fixed CS
fabpot Jun 28, 2015
ffed0ce
feature #15134 [FrameworkBundle] add option to force web server start…
fabpot Jun 30, 2015
96cce38
Warmup twig templates in non-standard paths (closes #12507)
kbond May 27, 2015
cad16ac
feature #14764 [TwigBundle] Warmup twig templates in non-standard pat…
fabpot Jun 30, 2015
cb9c069
[Validator] Added missing error codes and turned codes into UUIDs
webmozart Nov 3, 2014
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
Prev Previous commit
Next Next commit
Warmup twig templates in non-standard paths (closes #12507)
  • Loading branch information
kbond authored and fabpot committed Jun 30, 2015
commit 96cce38b00c7c2186f082584eb468688e2d873d9
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Symfony\Bundle\TwigBundle\CacheWarmer;

use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
use Symfony\Component\Templating\TemplateReference;

/**
* Generates the Twig cache for all templates.
Expand All @@ -27,21 +29,24 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface
{
protected $container;
protected $finder;
private $paths;

/**
* Constructor.
*
* @param ContainerInterface $container The dependency injection container
* @param TemplateFinderInterface $finder The template paths cache warmer
* @param array $paths Additional twig paths to warm
*/
public function __construct(ContainerInterface $container, TemplateFinderInterface $finder)
public function __construct(ContainerInterface $container, TemplateFinderInterface $finder, array $paths = array())
{
// We don't inject the Twig environment directly as it depends on the
// template locator (via the loader) which might be a cached one.
// The cached template locator is available once the TemplatePathsCacheWarmer
// has been warmed up
$this->container = $container;
$this->finder = $finder;
$this->paths = $paths;
}

/**
Expand All @@ -53,7 +58,13 @@ public function warmUp($cacheDir)
{
$twig = $this->container->get('twig');

foreach ($this->finder->findAllTemplates() as $template) {
$templates = $this->finder->findAllTemplates();

foreach ($this->paths as $path => $namespace) {
$templates = array_merge($templates, $this->findTemplatesInFolder($namespace, $path));
}

foreach ($templates as $template) {
if ('twig' !== $template->get('engine')) {
continue;
}
Expand All @@ -75,4 +86,32 @@ public function isOptional()
{
return true;
}

/**
* Find templates in the given directory.
*
* @param string $namespace The namespace for these templates
* @param string $dir The folder where to look for templates
*
* @return array An array of templates of type TemplateReferenceInterface
*/
private function findTemplatesInFolder($namespace, $dir)
{
if (!is_dir($dir)) {
return array();
}

$templates = array();
$finder = new Finder();

foreach ($finder->files()->followLinks()->in($dir) as $file) {
$name = $file->getRelativePathname();
$templates[] = new TemplateReference(
$namespace ? sprintf('@%s/%s', $namespace, $name) : $name,
'twig'
);
}

return $templates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function load(array $configs, ContainerBuilder $container)
}
}

$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);

// register bundles as Twig namespaces
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
$dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views';
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<service id="twig.cache_warmer" class="%twig.cache_warmer.class%" public="false">
<argument type="service" id="service_container" />
<argument type="service" id="templating.finder" />
<argument type="collection" /> <!-- Twig paths -->
</service>

<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.