Skip to content

Commit

Permalink
fixed finding resources under the main app/ directory
Browse files Browse the repository at this point in the history
* Now, all resources can be stored globally (templates, assets, ...)
* The new directory is app/Resources/...
  • Loading branch information
fabpot committed Mar 23, 2011
1 parent 72854cf commit a229410
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
Expand Up @@ -96,6 +96,7 @@ static protected function registerFormulaResources(ContainerBuilder $container,
foreach ($bundles as $name) {
$rc = new \ReflectionClass($map[$name]);
if (is_dir($dir = dirname($rc->getFileName()).'/Resources/views')) {
// FIXME: must also look for templates in %kernel.root_dir%/Resources/%bundle%/views
foreach (array('twig', 'php') as $engine) {
$container->setDefinition(
'assetic.'.$engine.'_directory_resource.'.$name,
Expand All @@ -106,7 +107,7 @@ static protected function registerFormulaResources(ContainerBuilder $container,
}

// kernel views/ directory
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/views')) {
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
foreach (array('twig', 'php') as $engine) {
$container->setDefinition(
'assetic.'.$engine.'_directory_resource.kernel',
Expand Down
Expand Up @@ -23,8 +23,6 @@
*/
class TemplatePathsCacheWarmer extends CacheWarmer
{
const TEMPLATES_PATH_IN_BUNDLE = '/Resources/views';

protected $kernel;
protected $rootDir;
protected $parser;
Expand Down Expand Up @@ -53,10 +51,11 @@ public function warmUp($cacheDir)
$templates = array();

foreach ($this->kernel->getBundles() as $name => $bundle) {
$templates += $this->findTemplatesIn($bundle->getPath().self::TEMPLATES_PATH_IN_BUNDLE, $name);
$templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name);
$templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name);
}

$templates += $this->findTemplatesIn($this->rootDir);
$templates += $this->findTemplatesIn($this->rootDir.'/views');

$this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
}
Expand Down
Expand Up @@ -29,19 +29,19 @@

<service id="templating.locator" class="%templating.locator.class%" public="false">
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.root_dir%/Resources</argument>
</service>

<service id="templating.locator.cached" class="%templating.locator.cached.class%" public="false">
<argument>%kernel.cache_dir%</argument>
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.root_dir%/Resources</argument>
</service>

<service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">
<argument type="service" id="kernel" />
<argument type="service" id="templating.name_parser" />
<argument>%kernel.root_dir%/views</argument>
<argument>%kernel.root_dir%/Resources</argument>
</service>

<service id="templating.loader.filesystem" class="%templating.loader.filesystem.class%" public="false">
Expand Down

4 comments on commit a229410

@lenar
Copy link
Contributor

@lenar lenar commented on a229410 Mar 23, 2011

Choose a reason for hiding this comment

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

Can we make %kernel.resources_dir% instead of %kernel.root_dir%/Resources?
This way developers could have more freedom over the naming.
It's just I don't like app/config and app/Resources in one directory (case mixed).

@Seldaek
Copy link
Member

Choose a reason for hiding this comment

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

Just delete the Resources dir and put everything in bundles as it should be :)

@lenar
Copy link
Contributor

@lenar lenar commented on a229410 Mar 23, 2011

Choose a reason for hiding this comment

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

Can one override templates of other bundles inside SomeBundle/Resources?

@Seldaek
Copy link
Member

Choose a reason for hiding this comment

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

Yes, you just need to define a getParent() method in your SomeBundle that returns "OtherBundle", then SomeBundle's templates takes priority over OtherBundle's. IIRC this limited to one parent, so you'd have to create one bundle per eveyr bundle you want to override stuff from.. I guess app/Resources makes it easier, but I'm still not a big fan

Please sign in to comment.