Author: fabien
Date: 2010-02-03 22:45:04 +0100 (Wed, 03 Feb 2010)
New Revision: 27517
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
branches/2.0/src/Symfony/Components/Templating/Loader/CacheLoader.php
branches/2.0/src/Symfony/Components/Templating/Loader/FilesystemLoader.php
branches/2.0/src/Symfony/Components/Templating/Storage/FileStorage.php
branches/2.0/src/Symfony/Components/Templating/Storage/Storage.php
branches/2.0/src/Symfony/Components/Templating/Storage/StringStorage.php
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/CacheLoaderTest.php
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/FilesystemLoaderTest.php
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php
Log:
Merge branch 'master' of git://github.com/symfony/symfony
Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -32,6 +32,7 @@
*/
public function setService($id, $service)
{
+ unset($this->definitions[$id]);
unset($this->aliases[$id]);
parent::setService($id, $service);
@@ -136,8 +137,8 @@
return;
}
- $this->aliases = array_merge($this->aliases, $configuration->getAliases());
- $this->definitions = array_merge($this->definitions,
$configuration->getDefinitions());
+ $this->addDefinitions($configuration->getDefinitions());
+ $this->addAliases($configuration->getAliases());
$currentParameters = $this->getParameters();
foreach ($configuration->getParameters() as $key => $value)
@@ -163,6 +164,30 @@
}
/**
+ * Adds the service aliases.
+ *
+ * @param array $aliases An array of aliases
+ */
+ public function addAliases(array $aliases)
+ {
+ foreach ($aliases as $alias => $id)
+ {
+ $this->setAlias($alias, $id);
+ }
+ }
+
+ /**
+ * Sets the service aliases.
+ *
+ * @param array $definitions An array of service definitions
+ */
+ public function setAliases(array $aliases)
+ {
+ $this->aliases = array();
+ $this->addAliases($aliases);
+ }
+
+ /**
* Sets an alias for an existing service.
*
* @param string $alias The alias to create
@@ -170,6 +195,8 @@
*/
public function setAlias($alias, $id)
{
+ unset($this->definitions[$alias]);
+
$this->aliases[$alias] = $id;
}
@@ -413,11 +440,11 @@
}
else
{
- $replaceParameter = function ($match) use ($parameters)
+ $replaceParameter = function ($match) use ($parameters, $value)
{
if (!array_key_exists($name = strtolower($match[2]), $parameters))
{
- throw new \RuntimeException(sprintf('The parameter "%s" must be
defined.', $name));
+ throw new \RuntimeException(sprintf('The parameter "%s" must be
defined (used in the following expression: "%s").', $name, $value));
}
return $parameters[$name];
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -157,6 +157,8 @@
*/
public function setAlias($alias, $id)
{
+ unset($this->definitions[$alias]);
+
$this->aliases[$alias] = $id;
}
Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -400,6 +400,6 @@
static public function underscore($id)
{
- return strtolower(preg_replace(array('/_/', '/([A-Z]+)([A-Z][a-z])/',
'/([a-z\d])([A-Z])/'), array('.', '\\1_\\2', '\\1_\\2'), $id));
+ return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/',
'/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
}
}
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -101,7 +101,10 @@
$helpers = array();
foreach (explode("\n", $config['helpers']) as $helper)
{
- $helpers[] = new Reference(trim($helper));
+ if ($helper)
+ {
+ $helpers[] = new Reference(trim($helper));
+ }
}
}
else
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -45,7 +45,7 @@
throw new \InvalidArgumentException(sprintf('The file "%s" does not
exist (in: %s).', $file, implode(', ', $this->paths)));
}
- return realpath($path);
+ return $path;
}
protected function getAbsolutePath($file, $currentPath = null)
Modified: branches/2.0/src/Symfony/Components/Templating/Loader/CacheLoader.php
===================================================================
--- branches/2.0/src/Symfony/Components/Templating/Loader/CacheLoader.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/Templating/Loader/CacheLoader.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -34,7 +34,7 @@
* Constructor.
*
* @param Loader $loader A Loader instance
- * @param string $dir The directory where to store the cache
files
+ * @param string $dir The directory where to store the cache files
*/
public function __construct(Loader $loader, $dir)
{
@@ -56,7 +56,10 @@
{
$options = $this->mergeDefaultOptions($options);
- $path =
$this->dir.DIRECTORY_SEPARATOR.md5($template.$options['renderer']).'.tpl';
+ $tmp = md5($template.serialize($options)).'.tpl';
+ $dir = $this->dir.DIRECTORY_SEPARATOR.substr($tmp, 0, 2);
+ $file = substr($tmp, 2);
+ $path = $dir.DIRECTORY_SEPARATOR.$file;
if ($this->loader instanceof CompilableLoaderInterface)
{
@@ -65,7 +68,7 @@
if (file_exists($path))
{
- if ($this->debugger)
+ if (null !== $this->debugger)
{
$this->debugger->log(sprintf('Fetching template "%s" from cache',
$template));
}
@@ -73,19 +76,26 @@
return new FileStorage($path, $options['renderer']);
}
- if (false === $content = $this->loader->load($template, $options))
+ if (false === $storage = $this->loader->load($template, $options))
{
return false;
}
+ $content = $storage->getContent();
+
if ($this->loader instanceof CompilableLoaderInterface)
{
$content = $this->loader->compile($content);
}
+ if (!file_exists($dir))
+ {
+ mkdir($dir, 0777, true);
+ }
+
file_put_contents($path, $content);
- if ($this->debugger)
+ if (null !== $this->debugger)
{
$this->debugger->log(sprintf('Storing template "%s" in cache',
$template));
}
Modified:
branches/2.0/src/Symfony/Components/Templating/Loader/FilesystemLoader.php
===================================================================
--- branches/2.0/src/Symfony/Components/Templating/Loader/FilesystemLoader.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/Templating/Loader/FilesystemLoader.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -71,7 +71,7 @@
{
if (is_file($file = strtr($templatePathPattern, $replacements)))
{
- if ($this->debugger)
+ if (null !== $this->debugger)
{
$this->debugger->log(sprintf('Loaded template file "%s" (renderer:
%s)', $file, $options['renderer']));
}
@@ -79,13 +79,13 @@
return new FileStorage($file);
}
- if ($this->debugger)
+ if (null !== $this->debugger)
{
$logs[] = sprintf('Failed loading template file "%s" (renderer: %s)',
$file, $options['renderer']);
}
}
- if ($this->debugger)
+ if (null !== $this->debugger)
{
foreach ($logs as $log)
{
Modified: branches/2.0/src/Symfony/Components/Templating/Storage/FileStorage.php
===================================================================
--- branches/2.0/src/Symfony/Components/Templating/Storage/FileStorage.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/Templating/Storage/FileStorage.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -20,4 +20,8 @@
*/
class FileStorage extends Storage
{
+ public function getContent()
+ {
+ return file_get_contents($this->template);
+ }
}
Modified: branches/2.0/src/Symfony/Components/Templating/Storage/Storage.php
===================================================================
--- branches/2.0/src/Symfony/Components/Templating/Storage/Storage.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/Templating/Storage/Storage.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -18,7 +18,7 @@
* @subpackage templating
* @author Fabien Potencier <[email protected]>
*/
-class Storage
+abstract class Storage
{
protected $renderer;
protected $template;
@@ -44,6 +44,8 @@
return (string) $this->template;
}
+ abstract public function getContent();
+
/**
* Gets the renderer.
*
Modified:
branches/2.0/src/Symfony/Components/Templating/Storage/StringStorage.php
===================================================================
--- branches/2.0/src/Symfony/Components/Templating/Storage/StringStorage.php
2010-02-03 21:36:40 UTC (rev 27516)
+++ branches/2.0/src/Symfony/Components/Templating/Storage/StringStorage.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -20,4 +20,8 @@
*/
class StringStorage extends Storage
{
+ public function getContent()
+ {
+ return $this->template;
+ }
}
Modified:
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/CacheLoaderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/CacheLoaderTest.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/CacheLoaderTest.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -16,6 +16,7 @@
use Symfony\Components\Templating\Loader\Loader;
use Symfony\Components\Templating\Loader\CacheLoader;
use Symfony\Components\Templating\Loader\CompilableLoaderInterface;
+use Symfony\Components\Templating\Storage\StringStorage;
$t = new LimeTest(9);
@@ -48,7 +49,7 @@
{
if (method_exists($this, $method = 'get'.ucfirst($template).'Template'))
{
- return $this->$method();
+ return new StringStorage($this->$method());
}
return false;
Modified:
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/FilesystemLoaderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/FilesystemLoaderTest.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/tests/unit/Symfony/Components/Templating/Loader/FilesystemLoaderTest.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -18,7 +18,7 @@
$fixturesPath =
realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/');
-$t = new LimeTest(15);
+$t = new LimeTest(14);
class ProjectTemplateLoader extends FilesystemLoader
{
@@ -70,5 +70,4 @@
$loader = new ProjectTemplateLoader(array($fixturesPath.'/null/%name%',
$pathPattern));
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$loader->load('foo');
-$t->ok($debugger->hasMessage('Failed loading template'), '->load() logs a
"Failed loading template" message if the template is not found');
$t->ok($debugger->hasMessage('Loaded template file'), '->load() logs a "Loaded
template file" message if the template is found');
Modified:
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -14,7 +14,12 @@
use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Storage\FileStorage;
-$t = new LimeTest(1);
+$t = new LimeTest(2);
$storage = new FileStorage('foo');
$t->ok($storage instanceof Storage, 'FileStorage is an instance of Storage');
+
+// ->getContent()
+$t->diag('->getContent()');
+$storage = new
FileStorage(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/templates/foo.php');
+$t->is($storage->getContent(), '<?php echo $foo ?>', '->getContent() returns
the content of the template');
Modified:
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -16,13 +16,20 @@
$t = new LimeTest(2);
+class TestStorage extends Storage
+{
+ public function getContent()
+ {
+ }
+}
+
// __construct() __toString()
$t->diag('__construct() __toString()');
-$storage = new Storage('foo');
+$storage = new TestStorage('foo');
$t->is((string) $storage, 'foo', '__toString() returns the template name');
// ->getRenderer()
$t->diag('->getRenderer()');
-$storage = new Storage('foo', $renderer = new PhpRenderer());
+$storage = new TestStorage('foo', $renderer = new PhpRenderer());
$t->ok($storage->getRenderer() === $renderer, '->getRenderer() returns the
renderer');
Modified:
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php
2010-02-03 21:36:40 UTC (rev 27516)
+++
branches/2.0/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php
2010-02-03 21:45:04 UTC (rev 27517)
@@ -14,7 +14,13 @@
use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Storage\StringStorage;
-$t = new LimeTest(1);
+$t = new LimeTest(2);
$storage = new StringStorage('foo');
$t->ok($storage instanceof Storage, 'StringStorage is an instance of Storage');
+
+
+// ->getContent()
+$t->diag('->getContent()');
+$storage = new StringStorage('foo');
+$t->is($storage->getContent(), 'foo', '->getContent() returns the content of
the template');
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.