From e866a678d2df9b762fa1fb3ac5b8c1473c652e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Passault?= Date: Tue, 16 Aug 2011 11:51:41 +0200 Subject: [PATCH 01/12] [DoctrineBundle] Tries to auto-generate the missing proxy files on the autoloader --- .../Bundle/DoctrineBundle/DoctrineBundle.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 3ef20d9dae..946c5d24c0 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -42,12 +42,37 @@ class DoctrineBundle extends Bundle if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) { $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace'); $dir = $this->container->getParameter('doctrine.orm.proxy_dir'); + $doctrine = $this->container->get('doctrine'); - spl_autoload_register(function($class) use ($namespace, $dir) { + spl_autoload_register(function($class) use ($namespace, $dir, $doctrine) { if (0 === strpos($class, $namespace)) { $className = substr($class, strlen($namespace) +1); $file = $dir.DIRECTORY_SEPARATOR.$className.'.php'; + if (!file_exists($file)) { + // Tries to auto-generate the proxy file + if (preg_match('/^(.+)\\\\([a-z0-9_]+)Proxy$/i', $class, $matches)) { + $className = $matches[2]; + + foreach ($doctrine->getEntityManagers() as $em) { + $em = $doctrine->getEntityManager(); + + if ($em->getConfiguration()->getAutoGenerateProxyClasses()) { + + $classes = $em->getMetadataFactory()->getAllMetadata(); + foreach ($classes as $class) + { + $name = str_replace('\\', '', $class->name); + + if ($name == $className) { + $em->getProxyFactory()->generateProxyClasses(array($class)); + } + } + } + } + } + } + if (!file_exists($file)) { throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file)); } From 0c4b79396b132585071156091acff93ef619a125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Passault?= Date: Tue, 16 Aug 2011 12:29:33 +0200 Subject: [PATCH 02/12] [DoctrineBundle] Fixed performances issues on "On-demand" proxy file generation --- .../Bundle/DoctrineBundle/DoctrineBundle.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 946c5d24c0..76c98ba8b6 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -42,36 +42,36 @@ class DoctrineBundle extends Bundle if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) { $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace'); $dir = $this->container->getParameter('doctrine.orm.proxy_dir'); - $doctrine = $this->container->get('doctrine'); + $container = $this->container; - spl_autoload_register(function($class) use ($namespace, $dir, $doctrine) { + spl_autoload_register(function($class) use ($namespace, $dir, $container) { if (0 === strpos($class, $namespace)) { $className = substr($class, strlen($namespace) +1); $file = $dir.DIRECTORY_SEPARATOR.$className.'.php'; if (!file_exists($file)) { + $originalClassName = substr($className, 0, -5); + $registry = $container->get('doctrine'); + // Tries to auto-generate the proxy file - if (preg_match('/^(.+)\\\\([a-z0-9_]+)Proxy$/i', $class, $matches)) { - $className = $matches[2]; + foreach ($registry->getEntityManagers() as $em) { - foreach ($doctrine->getEntityManagers() as $em) { - $em = $doctrine->getEntityManager(); + if ($em->getConfiguration()->getAutoGenerateProxyClasses()) { - if ($em->getConfiguration()->getAutoGenerateProxyClasses()) { + $classes = $em->getMetadataFactory()->getAllMetadata(); + foreach ($classes as $class) + { + $name = str_replace('\\', '', $class->name); - $classes = $em->getMetadataFactory()->getAllMetadata(); - foreach ($classes as $class) - { - $name = str_replace('\\', '', $class->name); - - if ($name == $className) { - $em->getProxyFactory()->generateProxyClasses(array($class)); - } + if ($name == $originalClassName) { + $em->getProxyFactory()->generateProxyClasses(array($class)); } } } } } + + clearstatcache($file); if (!file_exists($file)) { throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file)); From 0e00e3ff4c2805e2710e6067b037abf025bee4f4 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Tue, 23 Aug 2011 21:21:15 +0200 Subject: [PATCH 03/12] [DoctrineBundle] CS --- src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 76c98ba8b6..e595d3fbed 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -57,10 +57,9 @@ class DoctrineBundle extends Bundle foreach ($registry->getEntityManagers() as $em) { if ($em->getConfiguration()->getAutoGenerateProxyClasses()) { - $classes = $em->getMetadataFactory()->getAllMetadata(); - foreach ($classes as $class) - { + + foreach ($classes as $class) { $name = str_replace('\\', '', $class->name); if ($name == $originalClassName) { From e6867bb2e022d78803b5501e03f9721dfa96e30c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 29 Sep 2011 17:42:52 +0200 Subject: [PATCH 04/12] [SwiftmailerBundle] added swiftmailer dependency in composer.json --- src/Symfony/Bundle/SwiftmailerBundle/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SwiftmailerBundle/composer.json b/src/Symfony/Bundle/SwiftmailerBundle/composer.json index 106a9df2f3..7b976c21f1 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/composer.json +++ b/src/Symfony/Bundle/SwiftmailerBundle/composer.json @@ -17,6 +17,7 @@ } ], "require": { - "php": ">=5.3.2" + "php": ">=5.3.2", + "swiftmailer/swiftmailer": ">=4.1.2" } } From e70c884f4905878d82b8b5c80d58d96f229290ab Mon Sep 17 00:00:00 2001 From: Danny Berger Date: Fri, 30 Sep 2011 01:35:00 -0400 Subject: [PATCH 05/12] [Bridge/Monolog] Fix WebProcessor to accept a Request object. --- .../Bridge/Monolog/Processor/WebProcessor.php | 2 +- .../Monolog/Processor/WebProcessorTest.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/Symfony/Tests/Bridge/Monolog/Processor/WebProcessorTest.php diff --git a/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php b/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php index fa3395558f..3ccdfa74fb 100644 --- a/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request; */ class WebProcessor extends BaseWebProcessor { - public function __construct(RequestInterface $request) + public function __construct(Request $request) { parent::__construct($request->server->all()); } diff --git a/tests/Symfony/Tests/Bridge/Monolog/Processor/WebProcessorTest.php b/tests/Symfony/Tests/Bridge/Monolog/Processor/WebProcessorTest.php new file mode 100644 index 0000000000..5c17f0948b --- /dev/null +++ b/tests/Symfony/Tests/Bridge/Monolog/Processor/WebProcessorTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Bridge\Monolog\Processor; + +use Monolog\Logger; +use Symfony\Bridge\Monolog\Processor\WebProcessor; +use Symfony\Component\HttpFoundation\Request; + +class WebProcessorTest extends \PHPUnit_Framework_TestCase +{ + public function testUsesRequestServerData() + { + $server = array( + 'REQUEST_URI' => 'A', + 'REMOTE_ADDR' => 'B', + 'REQUEST_METHOD' => 'C', + ); + + $request = new Request(); + $request->server->replace($server); + + $processor = new WebProcessor($request); + $record = $processor($this->getRecord()); + + $this->assertEquals($server['REQUEST_URI'], $record['extra']['url']); + $this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']); + $this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']); + } + + /** + * @return array Record + */ + protected function getRecord($level = Logger::WARNING, $message = 'test') + { + return array( + 'message' => $message, + 'context' => array(), + 'level' => $level, + 'level_name' => Logger::getLevelName($level), + 'channel' => 'test', + 'datetime' => new \DateTime(), + 'extra' => array(), + ); + } +} From 5c8a2fb48dfe09537db6ebdd77a52a3c90f409fe Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Sep 2011 09:20:51 +0200 Subject: [PATCH 06/12] [Routing] fixed route overriden mechanism when using embedded collections (closes #2139) --- .../Matcher/Dumper/PhpMatcherDumper.php | 2 +- .../Component/Routing/RouteCollection.php | 62 ++++++++++++ .../Routing/Fixtures/dumper/url_matcher1.php | 45 +++++---- .../Routing/Fixtures/dumper/url_matcher2.php | 45 +++++---- .../Matcher/Dumper/PhpMatcherDumperTest.php | 95 +++++++++++-------- .../Routing/Matcher/UrlMatcherTest.php | 19 +++- .../Component/Routing/RouteCollectionTest.php | 53 ++++++++++- 7 files changed, 237 insertions(+), 84 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index cf98e403e5..c8231ede08 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -91,7 +91,7 @@ EOF; if ($optimizable) { for ($j = $i; $j < $keysCount; $j++) { if ($keys[$j] === null) { - continue; + continue; } $testRoute = $routeIterator->offsetGet($keys[$j]); diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index 6aeb06f605..47b7511734 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -16,6 +16,9 @@ use Symfony\Component\Config\Resource\ResourceInterface; /** * A RouteCollection represents a set of Route instances. * + * When adding a route, it overrides existing routes with the + * same name defined in theinstance or its children and parents. + * * @author Fabien Potencier * * @api @@ -25,6 +28,7 @@ class RouteCollection implements \IteratorAggregate private $routes; private $resources; private $prefix; + private $parent; /** * Constructor. @@ -38,6 +42,31 @@ class RouteCollection implements \IteratorAggregate $this->prefix = ''; } + /** + * Gets the parent RouteCollection. + * + * @return RouteCollection The parent RouteCollection + */ + public function getParent() + { + return $this->parent; + } + + /** + * Sets the parent RouteCollection. + * + * @param RouteCollection $parent The parent RouteCollection + */ + public function setParent(RouteCollection $parent) + { + $this->parent = $parent; + } + + /** + * Gets the current RouteCollection as an Iterator. + * + * @return \ArrayIterator An \ArrayIterator interface + */ public function getIterator() { return new \ArrayIterator($this->routes); @@ -59,6 +88,15 @@ class RouteCollection implements \IteratorAggregate throw new \InvalidArgumentException(sprintf('Name "%s" contains non valid characters for a route name.', $name)); } + $parent = $this; + while ($parent->getParent()) { + $parent = $parent->getParent(); + } + + if ($parent) { + $parent->remove($name); + } + $this->routes[$name] = $route; } @@ -106,6 +144,24 @@ class RouteCollection implements \IteratorAggregate } } + /** + * Removes a route by name. + * + * @param string $name The route name + */ + public function remove($name) + { + if (isset($this->routes[$name])) { + unset($this->routes[$name]); + } + + foreach ($this->routes as $routes) { + if ($routes instanceof RouteCollection) { + $routes->remove($name); + } + } + } + /** * Adds a route collection to the current set of routes (at the end of the current set). * @@ -116,8 +172,14 @@ class RouteCollection implements \IteratorAggregate */ public function addCollection(RouteCollection $collection, $prefix = '') { + $collection->setParent($this); $collection->addPrefix($prefix); + // remove all routes with the same name in all existing collections + foreach (array_keys($collection->all()) as $name) { + $this->remove($name); + } + $this->routes[] = $collection; } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php index bfd8f8e0f0..7932944a34 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php @@ -108,30 +108,35 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { - // foo - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; - return $matches; - } - - // bar - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'bar'; - return $matches; - } - // foo1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } + // foo2 + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + $matches['_route'] = 'foo2'; + return $matches; + } + + // bar2 + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + $matches['_route'] = 'bar2'; + return $matches; + } + + } + + // overriden + if ($pathinfo === '/a/overriden2') { + return array('_route' => 'overriden'); } // ababa @@ -139,23 +144,23 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher return array('_route' => 'ababa'); } - // foo + // foo4 if (preg_match('#^/aba/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; + $matches['_route'] = 'foo4'; return $matches; } } - // foo + // foo3 if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; + $matches['_route'] = 'foo3'; return $matches; } - // bar + // bar3 if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'bar'; + $matches['_route'] = 'bar3'; return $matches; } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php index e8ff94dc97..d0f1e31381 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -120,30 +120,35 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { - // foo - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; - return $matches; - } - - // bar - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'bar'; - return $matches; - } - // foo1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } + // foo2 + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + $matches['_route'] = 'foo2'; + return $matches; + } + + // bar2 + if (preg_match('#^/a/b\'b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { + $matches['_route'] = 'bar2'; + return $matches; + } + + } + + // overriden + if ($pathinfo === '/a/overriden2') { + return array('_route' => 'overriden'); } // ababa @@ -151,23 +156,23 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec return array('_route' => 'ababa'); } - // foo + // foo4 if (preg_match('#^/aba/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; + $matches['_route'] = 'foo4'; return $matches; } } - // foo + // foo3 if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'foo'; + $matches['_route'] = 'foo3'; return $matches; } - // bar + // bar3 if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#xs', $pathinfo, $matches)) { - $matches['_route'] = 'bar'; + $matches['_route'] = 'bar3'; return $matches; } diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php index 08053caf6c..ec8b6688d6 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php @@ -19,8 +19,52 @@ use Symfony\Component\Routing\RequestContext; class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase { public function testDump() + { + $dumper = new PhpMatcherDumper($this->getRouteCollection(), new RequestContext()); + + $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); + + $collection = $this->getRouteCollection(); + + // force HTTPS redirection + $collection->add('secure', new Route( + '/secure', + array(), + array('_scheme' => 'https') + )); + + // force HTTP redirection + $collection->add('nonsecure', new Route( + '/nonsecure', + array(), + array('_scheme' => 'http') + )); + + $dumper = new PhpMatcherDumper($collection, new RequestContext()); + + $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.'); + } + + /** + * @expectedException \LogicException + */ + public function testDumpWhenSchemeIsUsedWithoutAProperDumper() { $collection = new RouteCollection(); + $collection->add('secure', new Route( + '/secure', + array(), + array('_scheme' => 'https') + )); + $dumper = new PhpMatcherDumper($collection, new RequestContext()); + $dumper->dump(); + } + + protected function getRouteCollection() + { + $collection = new RouteCollection(); + + $collection->add('overriden', new Route('/overriden')); // defaults and requirements $collection->add('foo', new Route( @@ -82,20 +126,22 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase // prefixes $collection1 = new RouteCollection(); - $collection1->add('foo', new Route('/{foo}')); - $collection1->add('bar', new Route('/{bar}')); + $collection1->add('overriden', new Route('/overriden1')); + $collection1->add('foo1', new Route('/{foo}')); + $collection1->add('bar1', new Route('/{bar}')); $collection2 = new RouteCollection(); $collection2->addCollection($collection1, '/b\'b'); + $collection2->add('overriden', new Route('/overriden2')); $collection1 = new RouteCollection(); - $collection1->add('foo1', new Route('/{foo1}')); - $collection1->add('bar1', new Route('/{bar1}')); + $collection1->add('foo2', new Route('/{foo1}')); + $collection1->add('bar2', new Route('/{bar1}')); $collection2->addCollection($collection1, '/b\'b'); $collection->addCollection($collection2, '/a'); // "dynamic" prefix $collection1 = new RouteCollection(); - $collection1->add('foo', new Route('/{foo}')); - $collection1->add('bar', new Route('/{bar}')); + $collection1->add('foo3', new Route('/{foo}')); + $collection1->add('bar3', new Route('/{bar}')); $collection2 = new RouteCollection(); $collection2->addCollection($collection1, '/b'); $collection->addCollection($collection2, '/{_locale}'); @@ -104,42 +150,9 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase // some more prefixes $collection1 = new RouteCollection(); - $collection1->add('foo', new Route('/{foo}')); + $collection1->add('foo4', new Route('/{foo}')); $collection->addCollection($collection1, '/aba'); - $dumper = new PhpMatcherDumper($collection, new RequestContext()); - - $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); - - // force HTTPS redirection - $collection->add('secure', new Route( - '/secure', - array(), - array('_scheme' => 'https') - )); - - // force HTTP redirection - $collection->add('nonsecure', new Route( - '/nonsecure', - array(), - array('_scheme' => 'http') - )); - - $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.'); - } - - /** - * @expectedException \LogicException - */ - public function testDumpWhenSchemeIsUsedWithoutAProperDumper() - { - $collection = new RouteCollection(); - $collection->add('secure', new Route( - '/secure', - array(), - array('_scheme' => 'https') - )); - $dumper = new PhpMatcherDumper($collection, new RequestContext()); - $dumper->dump(); + return $collection; } } diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php index 1f735ca558..5d3349d453 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php @@ -170,6 +170,23 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched'); } + public function testMatchOverridenRoute() + { + $collection = new RouteCollection(); + $collection->add('foo', new Route('/foo')); + + $collection1 = new RouteCollection(); + $collection1->add('foo', new Route('/foo1')); + + $collection->addCollection($collection1); + + $matcher = new UrlMatcher($collection, new RequestContext(), array()); + + $this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1')); + $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $this->assertEquals(array(), $matcher->match('/foo')); + } + public function testMatchRegression() { $coll = new RouteCollection(); @@ -188,4 +205,4 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase } catch (ResourceNotFoundException $e) { } } -} \ No newline at end of file +} diff --git a/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php b/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php index 4ddd128c69..f0569065c1 100644 --- a/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php +++ b/tests/Symfony/Tests/Component/Routing/RouteCollectionTest.php @@ -28,7 +28,6 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\Routing\RouteCollection::add * @expectedException InvalidArgumentException */ public function testAddInvalidRoute() @@ -38,6 +37,58 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $collection->add('f o o', $route); } + public function testOverridenRoute() + { + $collection = new RouteCollection(); + $collection->add('foo', new Route('/foo')); + $collection->add('foo', new Route('/foo1')); + + $this->assertEquals('/foo1', $collection->get('foo')->getPattern()); + } + + public function testDeepOverridenRoute() + { + $collection = new RouteCollection(); + $collection->add('foo', new Route('/foo')); + + $collection1 = new RouteCollection(); + $collection1->add('foo', new Route('/foo1')); + + $collection2 = new RouteCollection(); + $collection2->add('foo', new Route('/foo2')); + + $collection1->addCollection($collection2); + $collection->addCollection($collection1); + + $this->assertEquals('/foo2', $collection1->get('foo')->getPattern()); + $this->assertEquals('/foo2', $collection->get('foo')->getPattern()); + } + + public function testIteratorWithOverridenRoutes() + { + $collection = new RouteCollection(); + $collection->add('foo', new Route('/foo')); + + $collection1 = new RouteCollection(); + $collection->addCollection($collection1); + $collection1->add('foo', new Route('/foo1')); + + $this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPattern()); + } + + protected function getFirstNamedRoute(RouteCollection $routeCollection, $name) + { + foreach ($routeCollection as $key => $route) { + if ($route instanceof RouteCollection) { + return $this->getFirstNamedRoute($route, $name); + } + + if ($name === $key) { + return $route; + } + } + } + public function testAddCollection() { $collection = new RouteCollection(); From 87416b4756f6d28683af46a84321e574653b63e5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Sep 2011 18:08:38 +0200 Subject: [PATCH 07/12] [DoctrineBundle] tweaked previous merge --- src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index e595d3fbed..8acedece6a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -68,12 +68,12 @@ class DoctrineBundle extends Bundle } } } - } - clearstatcache($file); - - if (!file_exists($file)) { - throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file)); + clearstatcache($file); + + if (!file_exists($file)) { + throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file)); + } } require $file; From 6295e553298b5ada14ee633e407a05568ba7687f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Sep 2011 18:10:34 +0200 Subject: [PATCH 08/12] [DoctrineBundle] made the previous fix only available in the development environment --- src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 8acedece6a..be3992bad0 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -49,7 +49,7 @@ class DoctrineBundle extends Bundle $className = substr($class, strlen($namespace) +1); $file = $dir.DIRECTORY_SEPARATOR.$className.'.php'; - if (!file_exists($file)) { + if (!file_exists($file) && $this->container->getParameter('kernel.debug')) { $originalClassName = substr($className, 0, -5); $registry = $container->get('doctrine'); From 54196382b71617870b544dfd30b6744d2151dc72 Mon Sep 17 00:00:00 2001 From: Danny Berger Date: Mon, 3 Oct 2011 02:08:17 -0400 Subject: [PATCH 09/12] [HttpKernel] Show the actual directory needing to be created. --- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ee4c8bb549..ecd9207182 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -615,7 +615,7 @@ abstract class Kernel implements KernelInterface foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) { if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true)) { - throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir))); + throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir)); } } elseif (!is_writable($dir)) { throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir)); From 8d6add638b0eb4b2ae306372b42453d8c9b7f4a0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Oct 2011 08:58:15 +0200 Subject: [PATCH 10/12] [DoctrineBridge] fixed directory reference when the directory cannot be created --- src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php index 7130c0249a..2d45c37d0f 100644 --- a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php +++ b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php @@ -52,7 +52,7 @@ class ProxyCacheWarmer implements CacheWarmerInterface // we need the directory no matter the proxy cache generation strategy if (!file_exists($proxyCacheDir = $em->getConfiguration()->getProxyDir())) { if (false === @mkdir($proxyCacheDir, 0777, true)) { - throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', dirname($proxyCacheDir))); + throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir)); } } elseif (!is_writable($proxyCacheDir)) { throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir)); From cf4a91e923c1192308311c390f42485d27721d10 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Oct 2011 18:02:59 +0200 Subject: [PATCH 11/12] [ClassLoader] fixed usage of trait_exists() --- src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php b/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php index 19952909ee..8a958e01f9 100644 --- a/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php +++ b/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php @@ -54,7 +54,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader if ($file = $this->findFile($class)) { require $file; - if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class))) { + if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) { throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file)); } } From 92d19063a843c53537e49a3c74a052287b4792b2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Oct 2011 08:43:04 +0200 Subject: [PATCH 12/12] [Translation] changed some unit tests for PHPUnit 3.6.0 compatibility --- .../Component/Translation/Loader/XliffFileLoaderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php index a0de14568e..f9b8a74835 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php @@ -28,7 +28,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException \RuntimeException */ public function testLoadInvalidResource() { @@ -37,7 +37,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException \RuntimeException */ public function testLoadResourceDoesNotValidate() {