- */
-class DoctrineMongoDBLogger
-{
- protected $logger;
-
- protected $prefix;
- protected $queries;
-
- protected $processed;
- protected $formattedQueries;
- protected $nbRealQueries;
-
- /**
- * Constructor.
- *
- * @param LoggerInterface $logger The Symfony logger
- * @param string $prefix A prefix for messages sent to the Symfony logger
- */
- public function __construct(LoggerInterface $logger = null, $prefix = 'MongoDB query: ')
- {
- $this->logger = $logger;
- $this->prefix = $prefix;
- $this->queries = array();
- $this->processed = false;
- }
-
- /**
- * Logs a query.
- *
- * This method is configured as the logger callable in the service
- * container.
- *
- * @param array $query A query log array from Doctrine
- */
- public function logQuery(array $query)
- {
- $this->queries[] = $query;
- $this->processed = false;
-
- if (null !== $this->logger) {
- $this->logger->info($this->prefix.static::bsonEncode($query));
- }
- }
-
- /**
- * Returns the number of queries that have been logged.
- *
- * @return integer The number of queries logged
- */
- public function getNbQueries()
- {
- if (!$this->processed) {
- $this->processQueries();
- }
-
- return $this->nbRealQueries;
- }
-
- /**
- * Returns a human-readable array of queries logged.
- *
- * @return array An array of queries
- */
- public function getQueries()
- {
- if (!$this->processed) {
- $this->processQueries();
- }
-
- return $this->formattedQueries;
- }
-
- /**
- * Groups and formats query arrays.
- *
- * @param array $queries An array of query arrays
- *
- * @return array An array of human-readable queries
- */
- protected function processQueries()
- {
- $this->formattedQueries = array();
- $this->nbRealQueries = 0;
-
- $grouped = array();
- $ordered = array();
- foreach ($this->queries as $query) {
- if (!isset($query['query']) || !isset($query['fields'])) {
- // no grouping necessary
- $ordered[] = array($query);
- continue;
- }
-
- $cursor = serialize($query['query']).serialize($query['fields']);
-
- // append if issued from cursor (currently just "sort")
- if (isset($query['sort'])) {
- unset($query['query'], $query['fields']);
- $grouped[$cursor][count($grouped[$cursor]) - 1][] = $query;
- } else {
- $grouped[$cursor][] = array($query);
- $ordered[] =& $grouped[$cursor][count($grouped[$cursor]) - 1];
- }
- }
-
- $i = 0;
- $db = '';
- $query = '';
- foreach ($ordered as $logs) {
- foreach ($logs as $log) {
- if (isset($log['db']) && $db != $log['db']) {
- // for readability
- $this->formattedQueries[$i++] = 'use '.$log['db'].';';
- $db = $log['db'];
- }
-
- if (isset($log['collection'])) {
- // flush the previous and start a new query
- if (!empty($query)) {
- if ('.' == $query[0]) {
- $query = 'db'.$query;
- }
-
- $this->formattedQueries[$i++] = $query.';';
- ++$this->nbRealQueries;
- }
-
- $query = 'db.'.$log['collection'];
- }
-
- // format the method call
- if (isset($log['authenticate'])) {
- $query .= '.authenticate()';
- } elseif (isset($log['batchInsert'])) {
- $query .= '.batchInsert(**'.$log['num'].' item(s)**)';
- } elseif (isset($log['command'])) {
- $query .= '.command()';
- } elseif (isset($log['count'])) {
- $query .= '.count(';
- if ($log['query'] || $log['limit'] || $log['skip']) {
- $query .= static::bsonEncode($log['query']);
- if ($log['limit'] || $log['skip']) {
- $query .= ', '.static::bsonEncode($log['limit']);
- if ($log['skip']) {
- $query .= ', '.static::bsonEncode($log['skip']);
- }
- }
- }
- $query .= ')';
- } elseif (isset($log['createCollection'])) {
- $query .= '.createCollection()';
- } elseif (isset($log['createDBRef'])) {
- $query .= '.createDBRef()';
- } elseif (isset($log['deleteIndex'])) {
- $query .= '.dropIndex('.static::bsonEncode($log['keys']).')';
- } elseif (isset($log['deleteIndexes'])) {
- $query .= '.dropIndexes()';
- } elseif (isset($log['drop'])) {
- $query .= '.drop()';
- } elseif (isset($log['dropDatabase'])) {
- $query .= '.dropDatabase()';
- } elseif (isset($log['ensureIndex'])) {
- $query .= '.ensureIndex('.static::bsonEncode($log['keys']).', '.static::bsonEncode($log['options']).')';
- } elseif (isset($log['execute'])) {
- $query .= '.execute()';
- } elseif (isset($log['find'])) {
- $query .= '.find(';
- if ($log['query'] || $log['fields']) {
- $query .= static::bsonEncode($log['query']);
- if ($log['fields']) {
- $query .= ', '.static::bsonEncode($log['fields']);
- }
- }
- $query .= ')';
- } elseif (isset($log['findOne'])) {
- $query .= '.findOne(';
- if ($log['query'] || $log['fields']) {
- $query .= static::bsonEncode($log['query']);
- if ($log['fields']) {
- $query .= ', '.static::bsonEncode($log['fields']);
- }
- }
- $query .= ')';
- } elseif (isset($log['getDBRef'])) {
- $query .= '.getDBRef()';
- } elseif (isset($log['group'])) {
- $query .= '.group('.static::bsonEncode(array(
- 'keys' => $log['keys'],
- 'initial' => $log['initial'],
- 'reduce' => $log['reduce'],
- )).')';
- } elseif (isset($log['insert'])) {
- $query .= '.insert('.static::bsonEncode($log['document']).')';
- } elseif (isset($log['remove'])) {
- $query .= '.remove('.static::bsonEncode($log['query']).')';
- } elseif (isset($log['save'])) {
- $query .= '.save('.static::bsonEncode($log['document']).')';
- } elseif (isset($log['sort'])) {
- $query .= '.sort('.static::bsonEncode($log['sortFields']).')';
- } elseif (isset($log['update'])) {
- // todo: include $log['options']
- $query .= '.update('.static::bsonEncode($log['query']).', '.static::bsonEncode($log['newObj']).')';
- } elseif (isset($log['validate'])) {
- $query .= '.validate()';
- }
- }
- }
-
- if (!empty($query)) {
- if ('.' == $query[0]) {
- $query = 'db'.$query;
- }
-
- $this->formattedQueries[$i++] = $query.';';
- ++$this->nbRealQueries;
- }
- }
-
- static protected function bsonEncode($query, $array = true)
- {
- $parts = array();
-
- foreach ($query as $key => $value) {
- if (!is_numeric($key)) {
- $array = false;
- }
-
- if (is_bool($value)) {
- $formatted = $value ? 'true' : 'false';
- } elseif (is_numeric($value)) {
- $formatted = $value;
- } elseif (is_scalar($value)) {
- $formatted = '"'.$value.'"';
- } elseif (is_array($value)) {
- $formatted = static::bsonEncode($value);
- } elseif ($value instanceof \MongoId) {
- $formatted = 'ObjectId("'.$value.'")';
- } elseif ($value instanceof \MongoDate) {
- $formatted = 'new Date("'.date('r', $value->sec).'")';
- } elseif ($value instanceof \DateTime) {
- $formatted = 'new Date("'.date('r', $value->getTimestamp()).'")';
- } elseif ($value instanceof \MongoRegex) {
- $formatted = 'new RegExp("'.$value->regex.'", "'.$value->flags.'")';
- } elseif ($value instanceof \MongoMinKey) {
- $formatted = 'new MinKey()';
- } elseif ($value instanceof \MongoMaxKey) {
- $formatted = 'new MaxKey()';
- } elseif ($value instanceof \MongoBinData) {
- $formatted = 'new BinData("'.$value->bin.'", "'.$value->type.'")';
- } elseif ($value instanceof \MongoGridFSFile || $value instanceof GridFSFile) {
- $formatted = 'new MongoGridFSFile("'.$value->getFilename().'")';
- } elseif ($value instanceof \stdClass) {
- $formatted = static::bsonEncode((array) $value);
- } else {
- $formatted = (string) $value;
- }
-
- $parts['"'.$key.'"'] = $formatted;
- }
-
- if (0 == count($parts)) {
- return $array ? '[ ]' : '{ }';
- }
-
- if ($array) {
- return '[ '.implode(', ', $parts).' ]';
- } else {
- $mapper = function($key, $value)
- {
- return $key.': '.$value;
- };
-
- return '{ '.implode(', ', array_map($mapper, array_keys($parts), array_values($parts))).' }';
- }
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml
deleted file mode 100755
index 8281f5d0c4..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml
+++ /dev/null
@@ -1,118 +0,0 @@
-
-
-
-
-
- Doctrine\MongoDB\Connection
- Doctrine\ODM\MongoDB\Configuration
- Doctrine\ODM\MongoDB\DocumentManager
- Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger
- Symfony\Bundle\DoctrineMongoDBBundle\DataCollector\DoctrineMongoDBDataCollector
- Doctrine\Common\EventManager
-
-
- Proxies
- %kernel.cache_dir%/doctrine/odm/mongodb/Proxies
- false
-
-
- Hydrators
- %kernel.cache_dir%/doctrine/odm/mongodb/Hydrators
- false
-
-
- Doctrine\Common\Cache\ArrayCache
- Doctrine\Common\Cache\ApcCache
- Doctrine\Common\Cache\MemcacheCache
- localhost
- 11211
- Memcache
- Doctrine\Common\Cache\XcacheCache
-
-
- Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain
- Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver
- Doctrine\Common\Annotations\AnnotationReader
- Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver
- Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver
-
-
-
- %doctrine.odm.mongodb.mapping_dirs%
- %doctrine.odm.mongodb.mapping_dirs%
-
-
-
- Symfony\Bundle\DoctrineMongoDBBundle\Security\DocumentUserProvider
-
-
- Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\ProxyCacheWarmer
-
-
- Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\HydratorCacheWarmer
-
-
- Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\UniqueValidator
-
-
-
-
-
-
-
-
-
-
- %doctrine.odm.mongodb.document_dirs%
-
-
-
-
- Doctrine\ODM\MongoDB\Mapping\
- mongodb
-
-
-
- %doctrine.odm.mongodb.xml_mapping_dirs%
-
-
- %doctrine.odm.mongodb.yml_mapping_dirs%
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd
deleted file mode 100644
index f214496b5b..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig
deleted file mode 100644
index b57c85a411..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig
+++ /dev/null
@@ -1,45 +0,0 @@
-{% extends 'WebProfiler:Profiler:layout.html.twig' %}
-
-{% block toolbar %}
- {% set icon %}
-
- {% endset %}
- {% set text %}
- {{ collector.querycount }}
- {% endset %}
- {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
-{% endblock %}
-
-{% block menu %}
-
-
- Doctrine MongoDB
-
- {{ collector.querycount }}
-
-
-{% endblock %}
-
-{% block panel %}
- Queries
-
- {% if not collector.queries %}
-
- Query logging is disabled.
-
- {% elseif not collector.querycount %}
-
- No queries.
-
- {% else %}
-
- {% for query in collector.queries %}
- -
-
- {{ query }}
-
-
- {% endfor %}
-
- {% endif %}
-{% endblock %}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php
deleted file mode 100644
index 651c21c554..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php
+++ /dev/null
@@ -1,78 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Security;
-
-use Symfony\Component\Security\Core\User\UserInterface;
-use Symfony\Component\Security\Core\User\UserProviderInterface;
-use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
-use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
-
-class DocumentUserProvider implements UserProviderInterface
-{
- protected $class;
- protected $repository;
- protected $property;
-
- public function __construct($em, $class, $property = null)
- {
- $this->class = $class;
-
- if (false !== strpos($this->class, ':')) {
- $this->class = $em->getClassMetadata($class)->getName();
- }
-
- $this->repository = $em->getRepository($class);
- $this->property = $property;
- }
-
- /**
- * {@inheritdoc}
- */
- public function loadUserByUsername($username)
- {
- if (null !== $this->property) {
- $user = $this->repository->findOneBy(array($this->property => $username));
- } else {
- if (!$this->repository instanceof UserProviderInterface) {
- throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository)));
- }
-
- $user = $this->repository->loadUserByUsername($username);
- }
-
- if (null === $user) {
- throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
- }
-
- return $user;
- }
-
- /**
- * {@inheritDoc}
- */
- public function loadUser(UserInterface $user)
- {
- if (!$user instanceof $this->class) {
- throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
- }
-
- return $this->loadUserByUsername($user->getUsername());
- }
-
- /**
- * {@inheritDoc}
- */
- public function supportsClass($class)
- {
- return $class === $this->class;
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php
deleted file mode 100644
index 6444c6b7b9..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php
+++ /dev/null
@@ -1,97 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\CacheWarmer;
-
-use Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\HydratorCacheWarmer;
-
-class HydratorCacheWarmerTest extends \Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase
-{
- /**
- * This is not necessarily a good test, it doesn't generate any hydrators
- * because there are none in the AnnotationsBundle. However that is
- * rather a task of doctrine to test. We touch the lines here and
- * verify that the container is called correctly for the relevant information.
- *
- * @group DoctrineODMMongoDBHydrator
- */
- public function testWarmCache()
- {
- $testManager = $this->createTestDocumentManager(array(
- __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document")
- );
-
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $container->expects($this->at(0))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.hydrator_dir'))
- ->will($this->returnValue(sys_get_temp_dir()));
- $container->expects($this->at(1))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_hydrator_classes'))
- ->will($this->returnValue(false));
- $container->expects($this->at(2))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.document_managers'))
- ->will($this->returnValue(array('default', 'foo')));
- $container->expects($this->at(3))
- ->method('get')
- ->with($this->equalTo('doctrine.odm.mongodb.default_document_manager'))
- ->will($this->returnValue($testManager));
- $container->expects($this->at(4))
- ->method('get')
- ->with($this->equalTo('doctrine.odm.mongodb.foo_document_manager'))
- ->will($this->returnValue($testManager));
-
- $cacheWarmer = new HydratorCacheWarmer($container);
- $cacheWarmer->warmUp(sys_get_temp_dir());
- }
-
- /**
- * @group DoctrineODMMongoDBHydrator
- */
- public function testSkipWhenHydratorsAreAutoGenerated()
- {
- $testManager = $this->createTestDocumentManager(array(
- __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document")
- );
-
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $container->expects($this->at(0))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.hydrator_dir'))
- ->will($this->returnValue(sys_get_temp_dir()));
- $container->expects($this->at(1))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_hydrator_classes'))
- ->will($this->returnValue(true));
- $container->expects($this->at(2))
- ->method('getParameter')
- ->with($this->equalTo('assertion'))
- ->will($this->returnValue(true));
-
- $cacheWarmer = new HydratorCacheWarmer($container);
- $cacheWarmer->warmUp(sys_get_temp_dir());
-
- $container->getParameter('assertion'); // check that the assertion is really the third call.
- }
-
- /**
- * @group DoctrineODMMongoDBHydrator
- */
- public function testHydratorCacheWarmingIsNotOptional()
- {
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $cacheWarmer = new HydratorCacheWarmer($container);
-
- $this->assertFalse($cacheWarmer->isOptional());
- }
-}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php
deleted file mode 100644
index 9184b2f35b..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php
+++ /dev/null
@@ -1,97 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\CacheWarmer;
-
-use Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\ProxyCacheWarmer;
-
-class ProxyCacheWarmerTest extends \Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase
-{
- /**
- * This is not necessarily a good test, it doesn't generate any proxies
- * because there are none in the AnnotationsBundle. However that is
- * rather a task of doctrine to test. We touch the lines here and
- * verify that the container is called correctly for the relevant information.
- *
- * @group DoctrineODMMongoDBProxy
- */
- public function testWarmCache()
- {
- $testManager = $this->createTestDocumentManager(array(
- __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document")
- );
-
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $container->expects($this->at(0))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.proxy_dir'))
- ->will($this->returnValue(sys_get_temp_dir()));
- $container->expects($this->at(1))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_proxy_classes'))
- ->will($this->returnValue(false));
- $container->expects($this->at(2))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.document_managers'))
- ->will($this->returnValue(array('default', 'foo')));
- $container->expects($this->at(3))
- ->method('get')
- ->with($this->equalTo('doctrine.odm.mongodb.default_document_manager'))
- ->will($this->returnValue($testManager));
- $container->expects($this->at(4))
- ->method('get')
- ->with($this->equalTo('doctrine.odm.mongodb.foo_document_manager'))
- ->will($this->returnValue($testManager));
-
- $cacheWarmer = new ProxyCacheWarmer($container);
- $cacheWarmer->warmUp(sys_get_temp_dir());
- }
-
- /**
- * @group DoctrineODMMongoDBProxy
- */
- public function testSkipWhenProxiesAreAutoGenerated()
- {
- $testManager = $this->createTestDocumentManager(array(
- __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document")
- );
-
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $container->expects($this->at(0))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.proxy_dir'))
- ->will($this->returnValue(sys_get_temp_dir()));
- $container->expects($this->at(1))
- ->method('getParameter')
- ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_proxy_classes'))
- ->will($this->returnValue(true));
- $container->expects($this->at(2))
- ->method('getParameter')
- ->with($this->equalTo('assertion'))
- ->will($this->returnValue(true));
-
- $cacheWarmer = new ProxyCacheWarmer($container);
- $cacheWarmer->warmUp(sys_get_temp_dir());
-
- $container->getParameter('assertion'); // check that the assertion is really the third call.
- }
-
- /**
- * @group DoctrineODMMongoDBProxy
- */
- public function testProxyCacheWarmingIsNotOptional()
- {
- $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
- $cacheWarmer = new ProxyCacheWarmer($container);
-
- $this->assertFalse($cacheWarmer->isOptional());
- }
-}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php
deleted file mode 100644
index 701d7ba7dc..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
-use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
-
-class ContainerTest extends TestCase
-{
- public function getContainer()
- {
- require_once __DIR__.'/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php';
-
- $container = new ContainerBuilder(new ParameterBag(array(
- 'kernel.bundles' => array('Yaml' => 'DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\YamlBundle'),
- 'kernel.cache_dir' => sys_get_temp_dir(),
- 'kernel.debug' => false,
- )));
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $configs = array();
- $configs[] = array('connections' => array('default' => array()), 'document_managers' => array('default' => array('mappings' => array('Yaml' => array()))));
- $loader->load($configs, $container);
-
- return $container;
- }
-
- public function testContainer()
- {
- $container = $this->getContainer();
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.metadata.chain'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', $container->get('doctrine.odm.mongodb.metadata.annotation'));
- $this->assertInstanceOf('Doctrine\Common\Annotations\AnnotationReader', $container->get('doctrine.odm.mongodb.metadata.annotation_reader'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', $container->get('doctrine.odm.mongodb.metadata.xml'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', $container->get('doctrine.odm.mongodb.metadata.yml'));
- $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache.array'));
- $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger', $container->get('doctrine.odm.mongodb.logger'));
- $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\DataCollector\DoctrineMongoDBDataCollector', $container->get('doctrine.odm.mongodb.data_collector'));
- $this->assertInstanceOf('Doctrine\MongoDB\Connection', $container->get('doctrine.odm.mongodb.default_connection'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Configuration', $container->get('doctrine.odm.mongodb.default_configuration'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.default_metadata_driver'));
- $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.default_metadata_cache'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.default_document_manager'));
- $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache'));
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.document_manager'));
- $this->assertInstanceof('Doctrine\Common\EventManager', $container->get('doctrine.odm.mongodb.event_manager'));
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
deleted file mode 100644
index 9c19eebebd..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
+++ /dev/null
@@ -1,361 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;
-
-use Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase;
-use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\DependencyInjection\Reference;
-
-abstract class AbstractMongoDBExtensionTest extends TestCase
-{
- abstract protected function loadFromFile(ContainerBuilder $container, $file);
-
- public function testDependencyInjectionConfigurationDefaults()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array()), $container);
-
- $this->assertEquals('Doctrine\MongoDB\Connection', $container->getParameter('doctrine.odm.mongodb.connection_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\Configuration', $container->getParameter('doctrine.odm.mongodb.configuration_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\DocumentManager', $container->getParameter('doctrine.odm.mongodb.document_manager_class'));
- $this->assertEquals('Proxies', $container->getParameter('doctrine.odm.mongodb.proxy_namespace'));
- $this->assertEquals(false, $container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes'));
- $this->assertEquals('Doctrine\Common\Cache\ArrayCache', $container->getParameter('doctrine.odm.mongodb.cache.array_class'));
- $this->assertEquals('Doctrine\Common\Cache\ApcCache', $container->getParameter('doctrine.odm.mongodb.cache.apc_class'));
- $this->assertEquals('Doctrine\Common\Cache\MemcacheCache', $container->getParameter('doctrine.odm.mongodb.cache.memcache_class'));
- $this->assertEquals('localhost', $container->getParameter('doctrine.odm.mongodb.cache.memcache_host'));
- $this->assertEquals('11211', $container->getParameter('doctrine.odm.mongodb.cache.memcache_port'));
- $this->assertEquals('Memcache', $container->getParameter('doctrine.odm.mongodb.cache.memcache_instance_class'));
- $this->assertEquals('Doctrine\Common\Cache\XcacheCache', $container->getParameter('doctrine.odm.mongodb.cache.xcache_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->getParameter('doctrine.odm.mongodb.metadata.driver_chain_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', $container->getParameter('doctrine.odm.mongodb.metadata.annotation_class'));
- $this->assertEquals('Doctrine\Common\Annotations\AnnotationReader', $container->getParameter('doctrine.odm.mongodb.metadata.annotation_reader_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', $container->getParameter('doctrine.odm.mongodb.metadata.xml_class'));
- $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', $container->getParameter('doctrine.odm.mongodb.metadata.yml_class'));
-
- $this->assertEquals('Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\UniqueValidator', $container->getParameter('doctrine_odm.mongodb.validator.unique.class'));
-
- $config = array(
- 'proxy_namespace' => 'MyProxies',
- 'auto_generate_proxy_classes' => true,
- 'connections' => array('default' => array()),
- 'document_managers' => array('default' => array())
- );
- $loader->load(array($config), $container);
-
- $this->assertEquals('MyProxies', $container->getParameter('doctrine.odm.mongodb.proxy_namespace'));
- $this->assertEquals(true, $container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes'));
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array(null, array(), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]);
- }
-
- public function testSingleDocumentManagerConfiguration()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
-
- $config = array(
- 'connections' => array(
- 'default' => array(
- 'server' => 'mongodb://localhost:27017',
- 'options' => array('connect' => true)
- )
- ),
- 'document_managers' => array('default' => array())
- );
- $loader->load(array($config), $container);
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]);
- }
-
- public function testLoadSimpleSingleConnection()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'mongodb_service_simple_single_connection');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_configuration');
- $methodCalls = $definition->getMethodCalls();
- $methodNames = array_map(function($call) { return $call[0]; }, $methodCalls);
- $this->assertInternalType('integer', $pos = array_search('setDefaultDB', $methodNames));
- $this->assertEquals('mydb', $methodCalls[$pos][1][0]);
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]);
- }
-
- public function testLoadSingleConnection()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'mongodb_service_single_connection');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]);
- }
-
- public function testLoadMultipleConnections()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'mongodb_service_multiple_connections');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.conn1_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.conn1_configuration')), $definition->getArguments());
-
- $this->assertEquals('doctrine.odm.mongodb.dm2_document_manager', (string) $container->getAlias('doctrine.odm.mongodb.document_manager'));
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.dm1_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.conn1_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.dm1_configuration', (string) $arguments[1]);
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.conn2_connection');
- $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass());
- $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.conn2_configuration')), $definition->getArguments());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.dm2_document_manager');
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass());
- $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass());
- $this->assertEquals('create', $definition->getFactoryMethod());
- $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags());
-
- $arguments = $definition->getArguments();
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
- $this->assertEquals('doctrine.odm.mongodb.conn2_connection', (string) $arguments[0]);
- $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
- $this->assertEquals('doctrine.odm.mongodb.dm2_configuration', (string) $arguments[1]);
- }
-
- public function testBundleDocumentAliases()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Yaml' => array()))))), $container);
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_configuration');
- $calls = $definition->getMethodCalls();
- $this->assertTrue(isset($calls[0][1][0]['Yaml']));
- $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][0]['Yaml']);
- }
-
- public function testYamlBundleMappingDetection()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Yaml' => array()))))), $container);
-
- $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls();
- $this->assertEquals('doctrine.odm.mongodb.default_yml_metadata_driver', (string) $calls[0][1][0]);
- $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][1]);
- }
-
- public function testXmlBundleMappingDetection()
- {
- $container = $this->getContainer('XmlBundle');
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Xml' => array()))))), $container);
-
- $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls();
- $this->assertEquals('doctrine.odm.mongodb.default_xml_metadata_driver', (string) $calls[0][1][0]);
- $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\XmlBundle\Document', $calls[0][1][1]);
- }
-
- public function testAnnotationsBundleMappingDetection()
- {
- $container = $this->getContainer('AnnotationsBundle');
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Annotations' => array()))))), $container);
-
- $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls();
- $this->assertEquals('doctrine.odm.mongodb.default_annotation_metadata_driver', (string) $calls[0][1][0]);
- $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\AnnotationsBundle\Document', $calls[0][1][1]);
- }
-
- public function testDocumentManagerMetadataCacheDriverConfiguration()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'mongodb_service_multiple_connections');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.dm1_metadata_cache');
- $this->assertEquals('%doctrine.odm.mongodb.cache.xcache_class%', $definition->getClass());
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.dm2_metadata_cache');
- $this->assertEquals('%doctrine.odm.mongodb.cache.apc_class%', $definition->getClass());
- }
-
- public function testDocumentManagerMemcacheMetadataCacheDriverConfiguration()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'mongodb_service_simple_single_connection');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_metadata_cache');
- $this->assertEquals('Doctrine\Common\Cache\MemcacheCache', $definition->getClass());
-
- $calls = $definition->getMethodCalls();
- $this->assertEquals('setMemcache', $calls[0][0]);
- $this->assertEquals('doctrine.odm.mongodb.default_memcache_instance', (string) $calls[0][1][0]);
-
- $definition = $container->getDefinition('doctrine.odm.mongodb.default_memcache_instance');
- $this->assertEquals('Memcache', $definition->getClass());
-
- $calls = $definition->getMethodCalls();
- $this->assertEquals('connect', $calls[0][0]);
- $this->assertEquals('localhost', $calls[0][1][0]);
- $this->assertEquals(11211, $calls[0][1][1]);
- }
-
- public function testDependencyInjectionImportsOverrideDefaults()
- {
- $container = $this->getContainer();
- $loader = new DoctrineMongoDBExtension();
- $container->registerExtension($loader);
-
- $this->loadFromFile($container, 'odm_imports');
-
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
- $container->compile();
-
- $this->assertTrue($container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes'));
- }
-
- public function testRegistersValidatorNamespace()
- {
- $container = $this->getContainer();
-
- $container->setParameter('validator.annotations.namespaces', array('Namespace1\\', 'Namespace2\\'));
-
- $loader = new DoctrineMongoDBExtension();
-
- $loader->load(array(array()), $container);
-
- $this->assertEquals(array(
- 'Namespace1\\',
- 'Namespace2\\',
- 'mongodb' => 'Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\\',
- ), $container->getParameter('validator.annotations.namespaces'));
- }
-
- protected function getContainer($bundle = 'YamlBundle')
- {
- require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php';
-
- return new ContainerBuilder(new ParameterBag(array(
- 'kernel.bundles' => array(substr($bundle, 0, -6) => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle),
- 'kernel.cache_dir' => sys_get_temp_dir(),
- 'kernel.debug' => false,
- )));
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php
deleted file mode 100644
index 21262c5e06..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ /dev/null
@@ -1,280 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration;
-use Symfony\Component\Yaml\Yaml;
-
-use Symfony\Component\Config\Definition\Processor;
-
-class ConfigurationTest extends \PHPUnit_Framework_TestCase
-{
- public function testDefaults()
- {
- $processor = new Processor();
- $configuration = new Configuration(false);
- $options = $processor->process($configuration->getConfigTree(), array());
-
- $defaults = array(
- 'auto_generate_hydrator_classes' => false,
- 'auto_generate_proxy_classes' => false,
- 'default_database' => 'default',
- 'document_managers' => array(),
- 'connections' => array(),
- 'proxy_namespace' => 'Proxies',
- 'hydrator_namespace' => 'Hydrators',
- );
-
- foreach ($defaults as $key => $default) {
- $this->assertTrue(array_key_exists($key, $options), sprintf('The default "%s" exists', $key));
- $this->assertEquals($default, $options[$key]);
-
- unset($options[$key]);
- }
-
- if (count($options)) {
- $this->fail('Extra defaults were returned: '. print_r($options, true));
- }
- }
-
- /**
- * Tests a full configuration.
- *
- * @dataProvider fullConfigurationProvider
- */
- public function testFullConfiguration($config)
- {
- $processor = new Processor();
- $configuration = new Configuration(false);
- $options = $processor->process($configuration->getConfigTree(), array($config));
-
- $expected = array(
- 'proxy_namespace' => 'Test_Proxies',
- 'auto_generate_proxy_classes' => true,
- 'hydrator_namespace' => 'Test_Hydrators',
- 'auto_generate_hydrator_classes' => true,
- 'default_document_manager' => 'default_dm_name',
- 'default_database' => 'default_db_name',
- 'default_connection' => 'conn1',
- 'connections' => array(
- 'conn1' => array(
- 'server' => 'http://server',
- 'options' => array(
- 'connect' => true,
- 'persist' => 'persist_val',
- 'timeout' => 500,
- 'replicaSet' => true,
- 'username' => 'username_val',
- 'password' => 'password_val',
- ),
- ),
- 'conn2' => array(
- 'server' => 'http://server2',
- 'options' => array(),
- ),
- ),
- 'document_managers' => array(
- 'dm1' => array(
- 'mappings' => array(
- 'Foo' => array(
- 'type' => 'annotations',
- ),
- ),
- 'metadata_cache_driver' => array(
- 'type' => 'memcache',
- 'class' => 'fooClass',
- 'host' => 'host_val',
- 'port' => 1234,
- 'instance_class' => 'instance_val',
- ),
- 'logging' => false,
- ),
- 'dm2' => array(
- 'connection' => 'dm2_connection',
- 'database' => 'db1',
- 'mappings' => array(
- 'Bar' => array(
- 'type' => 'yml',
- 'dir' => '%kernel.cache_dir%',
- 'prefix' => 'prefix_val',
- 'alias' => 'alias_val',
- 'is_bundle' => false,
- )
- ),
- 'metadata_cache_driver' => array(
- 'type' => 'apc',
- ),
- 'logging' => true,
- )
- )
- );
-
- $this->assertEquals($expected, $options);
- }
-
- public function fullConfigurationProvider()
- {
- $yaml = Yaml::load(__DIR__.'/Fixtures/config/yml/full.yml');
- $yaml = $yaml['doctrine_mongo_db'];
-
- return array(
- array($yaml),
- );
- }
-
- /**
- * @dataProvider optionProvider
- * @param array $configs The source array of configuration arrays
- * @param array $correctValues A key-value pair of end values to check
- */
- public function testMergeOptions(array $configs, array $correctValues)
- {
- $processor = new Processor();
- $configuration = new Configuration(false);
- $options = $processor->process($configuration->getConfigTree(), $configs);
-
- foreach ($correctValues as $key => $correctVal)
- {
- $this->assertEquals($correctVal, $options[$key]);
- }
- }
-
- public function optionProvider()
- {
- $cases = array();
-
- // single config, testing normal option setting
- $cases[] = array(
- array(
- array('default_document_manager' => 'foo'),
- ),
- array('default_document_manager' => 'foo')
- );
-
- // single config, testing normal option setting with dashes
- $cases[] = array(
- array(
- array('default-document-manager' => 'bar'),
- ),
- array('default_document_manager' => 'bar')
- );
-
- // testing the normal override merging - the later config array wins
- $cases[] = array(
- array(
- array('default_document_manager' => 'foo'),
- array('default_document_manager' => 'baz'),
- ),
- array('default_document_manager' => 'baz')
- );
-
- // the "options" array is totally replaced
- $cases[] = array(
- array(
- array('connections' => array('default' => array('options' => array('timeout' => 2000)))),
- array('connections' => array('default' => array('options' => array('username' => 'foo')))),
- ),
- array('connections' => array('default' => array('options' => array('username' => 'foo'), 'server' => null))),
- );
-
- // mappings are merged non-recursively.
- $cases[] = array(
- array(
- array('document_managers' => array('default' => array('mappings' => array('foomap' => array('type' => 'val1'), 'barmap' => array('dir' => 'val2'))))),
- array('document_managers' => array('default' => array('mappings' => array('barmap' => array('prefix' => 'val3'))))),
- ),
- array('document_managers' => array('default' => array('logging' => false, 'mappings' => array('foomap' => array('type' => 'val1'), 'barmap' => array('prefix' => 'val3'))))),
- );
-
- // connections are merged non-recursively.
- $cases[] = array(
- array(
- array('connections' => array('foocon' => array('server' => 'val1'), 'barcon' => array('options' => array('username' => 'val2')))),
- array('connections' => array('barcon' => array('server' => 'val3'))),
- ),
- array('connections' => array(
- 'foocon' => array('server' => 'val1', 'options' => array()),
- 'barcon' => array('server' => 'val3', 'options' => array())
- )),
- );
-
- // managers are merged non-recursively.
- $cases[] = array(
- array(
- array('document_managers' => array('foodm' => array('database' => 'val1'), 'bardm' => array('database' => 'val2'))),
- array('document_managers' => array('bardm' => array('database' => 'val3'))),
- ),
- array('document_managers' => array(
- 'foodm' => array('database' => 'val1', 'logging' => false, 'mappings' => array()),
- 'bardm' => array('database' => 'val3', 'logging' => false, 'mappings' => array()),
- )),
- );
-
- return $cases;
- }
-
- /**
- * @dataProvider getNormalizationTests
- */
- public function testNormalizeOptions(array $config, $targetKey, array $normalized)
- {
- $processor = new Processor();
- $configuration = new Configuration(false);
- $options = $processor->process($configuration->getConfigTree(), array($config));
- $this->assertSame($normalized, $options[$targetKey]);
- }
-
- public function getNormalizationTests()
- {
- return array(
- // connection versus connections (id is the identifier)
- array(
- array('connection' => array(
- array('server' => 'mongodb://abc', 'id' => 'foo'),
- array('server' => 'mongodb://def', 'id' => 'bar'),
- )),
- 'connections',
- array(
- 'foo' => array('server' => 'mongodb://abc', 'options' => array()),
- 'bar' => array('server' => 'mongodb://def', 'options' => array()),
- ),
- ),
- // document_manager versus document_managers (id is the identifier)
- array(
- array('document_manager' => array(
- array('connection' => 'conn1', 'id' => 'foo'),
- array('connection' => 'conn2', 'id' => 'bar'),
- )),
- 'document_managers',
- array(
- 'foo' => array('connection' => 'conn1', 'logging' => false, 'mappings' => array()),
- 'bar' => array('connection' => 'conn2', 'logging' => false, 'mappings' => array()),
- ),
- ),
- // mapping configuration that's beneath a specific document manager
- array(
- array('document_manager' => array(
- array('id' => 'foo', 'connection' => 'conn1', 'mapping' => array(
- 'type' => 'xml', 'name' => 'foo-mapping'
- )),
- )),
- 'document_managers',
- array(
- 'foo' => array('connection' => 'conn1', 'mappings' => array(
- 'foo-mapping' => array('type' => 'xml'),
- ), 'logging' => false),
- ),
- ),
- );
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
deleted file mode 100644
index 39e9f4f0a6..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
+++ /dev/null
@@ -1,41 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
-
-use Symfony\Component\Config\Definition\Processor;
-
-class DoctrineMongoDBExtensionTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @dataProvider parameterProvider
- */
- public function testParameterOverride($option, $parameter, $value)
- {
- $container = new ContainerBuilder();
- $container->setParameter('kernel.debug', false);
- $loader = new DoctrineMongoDBExtension();
- $loader->load(array(array($option => $value)), $container);
-
- $this->assertEquals($value, $container->getParameter('doctrine.odm.mongodb.'.$parameter));
- }
-
- public function parameterProvider()
- {
- return array(
- array('proxy_namespace', 'proxy_namespace', 'foo'),
- array('proxy-namespace', 'proxy_namespace', 'bar'),
- );
- }
-}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
deleted file mode 100644
index 23b96a825d..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
- true
-
-
-
-
- true
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml
deleted file mode 100644
index 0663a9c314..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
- true
-
-
-
-
- Doctrine\Common\Cache\MemcacheCache
- localhost
- 11211
- Memcache
-
-
-
-
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml
deleted file mode 100644
index 0ee2ddb300..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
- true
-
-
-
-
-
- Doctrine\Common\Cache\MemcacheCache
- localhost
- 11211
- Memcache
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml
deleted file mode 100644
index 1e215a1635..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml
deleted file mode 100644
index b06efb4628..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml
deleted file mode 100644
index f6032bc3f2..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-doctrine_mongo_db:
- proxy_namespace: Test_Proxies
- auto_generate_proxy_classes: true
-
- hydrator_namespace: Test_Hydrators
- auto_generate_hydrator_classes: true
-
- default_document_manager: default_dm_name
- default_database: default_db_name
-
- default_connection: conn1
-
- connections:
- conn1:
- server: http://server
- options:
- connect: true
- persist: persist_val
- timeout: 500
- replicaSet: true
- username: username_val
- password: password_val
- conn2:
- server: http://server2
-
- document_managers:
- dm1:
- mappings:
- Foo: annotations
- metadata_cache_driver:
- type: memcache
- class: fooClass
- host: host_val
- port: 1234
- instance_class: instance_val
- dm2:
- connection: dm2_connection
- database: db1
- mappings:
- Bar:
- type: yml
- dir: %kernel.cache_dir%
- prefix: prefix_val
- alias: alias_val
- is_bundle: false
- metadata_cache_driver: apc
- logging: true
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml
deleted file mode 100644
index d56d9383ee..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-doctrine_mongo_db:
- default_document_manager: dm2
- default_connection: conn2
- connections:
- conn1:
- server: mongodb://localhost:27017
- options:
- connect: true
- conn2:
- server: mongodb://localhost:27017
- options:
- connect: true
- document_managers:
- dm1:
- connection: conn1
- metadata_cache_driver: xcache
- dm2:
- connection: conn2
- metadata_cache_driver: apc
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml
deleted file mode 100644
index 4e55aa119e..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-doctrine_mongo_db:
- connections:
- default:
- server: mongodb://localhost:27017
- options: { connect: true }
- default_database: mydb
- document_managers:
- default:
- metadata_cache_driver:
- type: memcache
- class: Doctrine\Common\Cache\MemcacheCache
- host: localhost
- port: 11211
- instance_class: Memcache
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml
deleted file mode 100644
index 95466f9126..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-doctrine_mongo_db:
- connections:
- default:
- server: mongodb://localhost:27017
- options:
- connect: true
- document_managers:
- default:
- connection: default
- metadata_cache_driver:
- type: memcache
- class: Doctrine\Common\Cache\MemcacheCache
- host: localhost
- port: 11211
- instance_class: Memcache
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml
deleted file mode 100644
index e4292b8662..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-imports:
- - { resource: odm_imports_import.yml }
-
-doctrine_mongo_db:
- auto_generate_proxy_classes: true
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml
deleted file mode 100644
index 888177d921..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-doctrine_mongo_db:
- auto_generate_proxy_classes: false
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php
deleted file mode 100644
index 00976d6bb9..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
-use Symfony\Component\Config\FileLocator;
-
-class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
-{
- protected function loadFromFile(ContainerBuilder $container, $file)
- {
- $loadXml = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/xml'));
- $loadXml->load($file.'.xml');
- }
-}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php
deleted file mode 100644
index 2c56e63d6a..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
-use Symfony\Component\Config\FileLocator;
-
-class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest
-{
- protected function loadFromFile(ContainerBuilder $container, $file)
- {
- $loadYaml = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/yml'));
- $loadYaml->load($file.'.yml');
- }
-}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php
deleted file mode 100755
index 6c8b77d6ca..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php
+++ /dev/null
@@ -1,9 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\Logger;
-
-use Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger;
-
-class DoctrineMongoDBLoggerTest extends \PHPUnit_Framework_TestCase
-{
- protected $logger;
-
- protected function setUp()
- {
- $this->logger = new DoctrineMongoDBLogger();
- }
-
- /**
- * @dataProvider getQueries
- */
- public function testLogger($query, $formatted)
- {
- $this->logger->logQuery($query);
-
- $this->assertEquals($formatted, $this->logger->getQueries());
- }
-
- public function getQueries()
- {
- return array(
- // batchInsert
- array(
- array('db' => 'foo', 'collection' => 'bar', 'batchInsert' => true, 'num' => 1, 'data' => array('foo'), 'options' => array()),
- array('use foo;', 'db.bar.batchInsert(**1 item(s)**);'),
- ),
- // find
- array(
- array('db' => 'foo', 'collection' => 'bar', 'find' => true, 'query' => array(), 'fields' => array()),
- array('use foo;', 'db.bar.find();'),
- ),
- );
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php
deleted file mode 100644
index 3e14e1bb78..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php
+++ /dev/null
@@ -1,42 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests;
-
-use Doctrine\ODM\MongoDB\DocumentManager;
-use Doctrine\MongoDB\Connection;
-
-class TestCase extends \PHPUnit_Framework_TestCase
-{
- protected function setUp()
- {
- if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) {
- $this->markTestSkipped('Doctrine MongoDB ODM is not available.');
- }
- }
-
- /**
- * @return DocumentManager
- */
- protected function createTestDocumentManager($paths = array())
- {
- $config = new \Doctrine\ODM\MongoDB\Configuration();
- $config->setAutoGenerateProxyClasses(true);
- $config->setProxyDir(\sys_get_temp_dir());
- $config->setHydratorDir(\sys_get_temp_dir());
- $config->setProxyNamespace('SymfonyTests\Doctrine');
- $config->setHydratorNamespace('SymfonyTests\Doctrine');
- $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths));
- $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
-
- return DocumentManager::create(new Connection(), $config);
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php
deleted file mode 100755
index f3e0d6fae7..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php
+++ /dev/null
@@ -1,156 +0,0 @@
-classMetadata = $this->getClassMetadata();
- $this->repository = $this->getDocumentRepository();
- $this->dm = $this->getDocumentManager($this->classMetadata, $this->repository);
- $container = $this->getContainer();
- $this->validator = new UniqueValidator($container);
- }
-
- public function tearDown()
- {
- unset($this->validator, $this->dm, $this->repository, $this->classMetadata);
- }
-
- /**
- * @dataProvider getFieldsPathsValuesDocumentsAndReturns
- */
- public function testShouldValidateValidStringMappingValues($field, $path, $value, $document, $return)
- {
- $this->setFieldMapping($field, 'string');
-
- $this->repository->expects($this->once())
- ->method('findOneBy')
- ->with(array($path => $value))
- ->will($this->returnValue($return));
-
- $this->assertTrue($this->validator->isValid($document, new Unique($path)));
- }
-
- public function getFieldsPathsValuesDocumentsAndReturns()
- {
- $field = 'unique';
- $path = $field;
- $value = 'someUniqueValueToBeValidated';
- $document = $this->getFixtureDocument($field, $value);
-
- return array(
- array('unique', 'unique', 'someUniqueValueToBeValidated', $document, null),
- array('unique', 'unique', 'someUniqueValueToBeValidated', $document, $document),
- array('unique', 'unique', 'someUniqueValueToBeValidated', $document, $this->getFixtureDocument($field, $value)),
- );
- }
-
- /**
- * @dataProvider getFieldTypesFieldsPathsValuesAndQueries
- */
- public function testGetsCorrectQueryArrayForCollection($type, $field, $path, $value, $query)
- {
- $this->setFieldMapping($field, $type);
- $document = $this->getFixtureDocument($field, $value);
-
- $this->repository->expects($this->once())
- ->method('findOneBy')
- ->with($query);
-
- $this->validator->isValid($document, new Unique($path));
- }
-
- public function getFieldTypesFieldsPathsValuesAndQueries()
- {
- $field = 'unique';
- $key = 'uniqueValue';
- $path = $field.'.'.$key;
- $value = 'someUniqueValueToBeValidated';
-
- return array(
- array('collection', $field, $path, array($value), array($field => array('$in' => array($value)))),
- array('hash', $field, $path, array($key => $value), array($path => $value)),
- );
- }
-
- private function getContainer()
- {
- $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
-
- $container->expects($this->once())
- ->method('get')
- ->will($this->returnValue($this->dm));
-
- return $container;
- }
-
- private function getDocumentManager(ClassMetadata $classMetadata, DocumentRepository $repository)
- {
- $dm = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentManager')
- ->disableOriginalConstructor()
- ->setMethods(array('getClassMetadata', 'getRepository'))
- ->getMock();
- $dm->expects($this->any())
- ->method('getClassMetadata')
- ->will($this->returnValue($classMetadata));
- $dm->expects($this->any())
- ->method('getRepository')
- ->will($this->returnValue($repository));
-
- return $dm;
- }
-
- protected function getDocumentRepository()
- {
- $dm = $this->getMock('Doctrine\ODM\MongoDB\DocumentRepository', array('findOneBy'), array(), '', false, false);
-
- return $dm;
- }
-
- protected function getClassMetadata()
- {
- $classMetadata = $this->getMock('Doctrine\ODM\MongoDB\Mapping\ClassMetadata', array(), array(), '', false, false);
- $classMetadata->expects($this->any())
- ->method('getFieldValue')
- ->will($this->returnCallback(function($document, $fieldName) {
- return $document->{$fieldName};
- }));
-
- $classMetadata->fieldmappings = array();
-
- return $classMetadata;
- }
-
- protected function setFieldMapping($fieldName, $type, array $attributes = array())
- {
- $this->classMetadata->fieldMappings[$fieldName] = array_merge(array(
- 'fieldName' => $fieldName,
- 'type' => $type,
- ), $attributes);
- }
-
- protected function getFixtureDocument($field, $value, $id = 1)
- {
- $document = new Document();
- $document->{$field} = $value;
- $document->id = 1;
-
- return $document;
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php
deleted file mode 100755
index 3a29894d0d..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php
+++ /dev/null
@@ -1,56 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints;
-
-use Symfony\Component\Validator\Constraint;
-
-/**
- * Doctrine MongoDB ODM unique value constraint.
- *
- * @author Bulat Shakirzyanov
- */
-class Unique extends Constraint
-{
- public $message = 'The value for {{ property }} already exists.';
- public $path;
- public $documentManager;
-
- public function getDefaultOption()
- {
- return 'path';
- }
-
- public function getRequiredOptions()
- {
- return array('path');
- }
-
- public function validatedBy()
- {
- return 'doctrine_odm.mongodb.unique';
- }
-
- public function getTargets()
- {
- return Constraint::CLASS_CONSTRAINT;
- }
-
- public function getDocumentManagerId()
- {
- $id = 'doctrine.odm.mongodb.document_manager';
- if (null !== $this->documentManager) {
- $id = sprintf('doctrine.odm.mongodb.%s_document_manager', $this->documentManager);
- }
-
- return $id;
- }
-}
diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php
deleted file mode 100755
index 3708760971..0000000000
--- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php
+++ /dev/null
@@ -1,138 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints;
-
-use Doctrine\ODM\MongoDB\DocumentManager;
-use Doctrine\ODM\MongoDB\Proxy\Proxy;
-use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\Validator\Constraint;
-use Symfony\Component\Validator\ConstraintValidator;
-
-/**
- * Doctrine MongoDB ODM unique value validator.
- *
- * @author Bulat Shakirzyanov
- */
-class UniqueValidator extends ConstraintValidator
-{
-
- private $container;
-
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- }
-
- /**
- * @param Doctrine\ODM\MongoDB\Document $value
- * @param Constraint $constraint
- * @return Boolean
- */
- public function isValid($document, Constraint $constraint)
- {
- $class = get_class($document);
- $dm = $this->getDocumentManager($constraint);
- $metadata = $dm->getClassMetadata($class);
-
- if ($metadata->isEmbeddedDocument) {
- throw new \InvalidArgumentException(sprintf("Document '%s' is an embedded document, and cannot be validated", $class));
- }
-
- $query = $this->getQueryArray($metadata, $document, $constraint->path);
-
- // check if document exists in mongodb
- if (null === ($doc = $dm->getRepository($class)->findOneBy($query))) {
- return true;
- }
-
- // check if document in mongodb is the same document as the checked one
- if ($doc === $document) {
- return true;
- }
-
- // check if returned document is proxy and initialize the minimum identifier if needed
- if ($doc instanceof Proxy) {
- $metadata->setIdentifierValue($doc, $doc->__identifier);
- }
-
- // check if document has the same identifier as the current one
- if ($metadata->getIdentifierValue($doc) === $metadata->getIdentifierValue($document)) {
- return true;
- }
-
- $this->context->setPropertyPath($this->context->getPropertyPath() . '.' . $constraint->path);
- $this->setMessage($constraint->message, array(
- '{{ property }}' => $constraint->path,
- ));
- return false;
- }
-
- protected function getQueryArray(ClassMetadata $metadata, $document, $path)
- {
- $class = $metadata->name;
- $field = $this->getFieldNameFromPropertyPath($path);
- if (!isset($metadata->fieldMappings[$field])) {
- throw new \LogicException('Mapping for \'' . $path . '\' doesn\'t exist for ' . $class);
- }
- $mapping = $metadata->fieldMappings[$field];
- if (isset($mapping['reference']) && $mapping['reference']) {
- throw new \LogicException('Cannot determine uniqueness of referenced document values');
- }
- switch ($mapping['type']) {
- case 'one':
- // TODO: implement support for embed one documents
- case 'many':
- // TODO: implement support for embed many documents
- throw new \RuntimeException('Not Implemented.');
- case 'hash':
- $value = $metadata->getFieldValue($document, $mapping['fieldName']);
- return array($path => $this->getFieldValueRecursively($path, $value));
- case 'collection':
- return array($mapping['fieldName'] => array('$in' => $metadata->getFieldValue($document, $mapping['fieldName'])));
- default:
- return array($mapping['fieldName'] => $metadata->getFieldValue($document, $mapping['fieldName']));
- }
- }
-
- /**
- * Returns the actual document field value
- *
- * E.g. document.someVal -> document
- * user.emails -> user
- * username -> username
- *
- * @param string $field
- * @return string
- */
- private function getFieldNameFromPropertyPath($field)
- {
- $pieces = explode('.', $field);
- return $pieces[0];
- }
-
- private function getFieldValueRecursively($fieldName, $value)
- {
- $pieces = explode('.', $fieldName);
- unset($pieces[0]);
- foreach ($pieces as $piece) {
- $value = $value[$piece];
- }
- return $value;
- }
-
- private function getDocumentManager(Unique $constraint)
- {
- return $this->container->get($constraint->getDocumentManagerId());
- }
-
-}
diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php
index fe0e971b5c..b8a142f03c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php
+++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php
@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
+use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
/**
* Computes the association between template names and their paths on the disk.
@@ -24,20 +25,23 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
class TemplatePathsCacheWarmer extends CacheWarmer
{
protected $kernel;
- protected $rootDir;
protected $parser;
+ protected $rootDir;
+ protected $locator;
/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
* @param TemplateNameParser $parser A TemplateNameParser instance
+ * @param TemplateLocator $locator The template locator
* @param string $rootDir The directory where global templates can be stored
*/
- public function __construct(KernelInterface $kernel, TemplateNameParser $parser, $rootDir)
+ public function __construct(KernelInterface $kernel, TemplateNameParser $parser, TemplateLocator $locator, $rootDir)
{
$this->kernel = $kernel;
$this->parser = $parser;
+ $this->locator = $locator;
$this->rootDir = $rootDir;
}
@@ -51,7 +55,6 @@ class TemplatePathsCacheWarmer extends CacheWarmer
$templates = array();
foreach ($this->kernel->getBundles() as $name => $bundle) {
- $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name);
$templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name);
}
@@ -88,9 +91,9 @@ class TemplatePathsCacheWarmer extends CacheWarmer
$template = $this->parser->parseFromFilename($file->getRelativePathname());
if (false !== $template) {
if (null !== $bundle) {
- $template->set('bundle', $bundle);
+ $template->set('bundle', $bundle);
}
- $templates[$template->getSignature()] = $file->getRealPath();
+ $templates[$template->getSignature()] = $this->locator->locate($template);
}
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php
index 91b4b63cf6..9329c21b63 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Client.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Client.php
@@ -14,8 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Client as BaseClient;
-use Symfony\Component\BrowserKit\History;
-use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\HttpKernel\Profiler\Profiler as HttpProfiler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -27,23 +25,6 @@ use Symfony\Component\HttpFoundation\Response;
*/
class Client extends BaseClient
{
- protected $container;
-
- /**
- * Constructor.
- *
- * @param HttpKernelInterface $kernel An HttpKernelInterface instance
- * @param array $server The server parameters (equivalent of $_SERVER)
- * @param History $history A History instance to store the browser history
- * @param CookieJar $cookieJar A CookieJar instance to store the cookies
- */
- public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
- {
- parent::__construct($kernel, $server, $history, $cookieJar);
-
- $this->container = $kernel->getContainer();
- }
-
/**
* Returns the container.
*
@@ -51,7 +32,7 @@ class Client extends BaseClient
*/
public function getContainer()
{
- return $this->container;
+ return $this->kernel->getContainer();
}
/**
@@ -71,11 +52,11 @@ class Client extends BaseClient
*/
public function getProfiler()
{
- if (!$this->container->has('profiler')) {
+ if (!$this->kernel->getContainer()->has('profiler')) {
return false;
}
- return $this->container->get('profiler')->loadFromResponse($this->response);
+ return $this->kernel->getContainer()->get('profiler')->loadFromResponse($this->response);
}
/**
@@ -87,10 +68,9 @@ class Client extends BaseClient
*/
protected function doRequest($request)
{
- $returnValue = $this->kernel->handle($request);
$this->kernel->shutdown();
- return $returnValue;
+ return $this->kernel->handle($request);
}
/**
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
index 1f80df8366..8cf0c09332 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
@@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
/**
- * AssetsInstallCommand.
+ * Command that places bundle web assets into a given directory.
*
* @author Fabien Potencier
*/
@@ -31,9 +31,23 @@ class AssetsInstallCommand extends Command
{
$this
->setDefinition(array(
- new InputArgument('target', InputArgument::REQUIRED, 'The target directory'),
+ new InputArgument('target', InputArgument::REQUIRED, 'The target directory (usually "web")'),
))
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
+ ->setHelp(<<assets:install command installs bundle assets into a given
+directory (e.g. the web directory).
+
+./app/console assets:install web [--symlink]
+
+A "bundles" directory will be created inside the target directory, and the
+"Resources/public" directory of each bundle will be copied into it.
+
+To create a symlink to each bundle instead of copying its assets, use the
+--symlink option.
+
+EOT
+ )
->setName('assets:install')
;
}
@@ -56,10 +70,10 @@ class AssetsInstallCommand extends Command
foreach ($this->container->get('kernel')->getBundles() as $bundle) {
if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
- $output->writeln(sprintf('Installing assets for %s', $bundle->getNamespace()));
-
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));
+ $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir));
+
$filesystem->remove($targetDir);
if ($input->getOption('symlink')) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
index bf1f323685..14ef5f12ca 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
@@ -57,7 +57,7 @@ EOF
$oldCacheDir = $realCacheDir.'_old';
if (!is_writable($realCacheDir)) {
- throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->realCacheDir));
+ throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
if ($input->getOption('no-warmup')) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
index 0195ff4648..8aeb8193ce 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
@@ -49,13 +49,7 @@ The container:debug displays all configured publiccontainer:debug
-You can also search for specific services using wildcards (*):
-
- container:debug doctrine.*
-
- container:debug *event_manager
-
-To get specific information about a service, use specify its name exactly:
+To get specific information about a service, specify its name:
container:debug validator
@@ -73,20 +67,23 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $filter = $input->getArgument('name');
+ $name = $input->getArgument('name');
$this->containerBuilder = $this->getContainerBuilder();
- $serviceIds = $this->filterServices($this->containerBuilder->getServiceIds(), $filter);
+ $serviceIds = $this->containerBuilder->getServiceIds();
- if (1 == count($serviceIds) && false === strpos($filter, '*')) {
- $this->outputService($output, $serviceIds[0]);
+ // sort so that it reads like an index of services
+ asort($serviceIds);
+
+ if ($name) {
+ $this->outputService($output, $name);
} else {
$showPrivate = $input->getOption('show-private');
- $this->outputServices($output, $serviceIds, $filter, $showPrivate);
+ $this->outputServices($output, $serviceIds, $showPrivate);
}
}
- protected function outputServices(OutputInterface $output, $serviceIds, $filter, $showPrivate = false)
+ protected function outputServices(OutputInterface $output, $serviceIds, $showPrivate = false)
{
// set the label to specify public or public+private
if ($showPrivate) {
@@ -95,9 +92,6 @@ EOF
$label = 'Public services';
}
- if ($filter) {
- $label .= sprintf(' matching %s', $filter);
- }
$output->writeln($this->getHelper('formatter')->formatSection('container', $label));
// loop through to find get space needed and filter private services
@@ -215,74 +209,4 @@ EOF
// the service has been injected in some special way, just return the service
return $this->containerBuilder->get($serviceId);
}
-
- /**
- * Filters the given array of service ids by the given string filter:
- *
- * * An exact filter, "foo", will return *only* the "foo" service
- * * A wildcard filter, "foo*", will return all services matching the wildcard
- *
- * @param array $serviceIds The array of service ids
- * @param string $filter The given filter. If ending in *, a wildcard
- * @return array
- */
- private function filterServices($serviceIds, $filter, $onlyPublic = true)
- {
- // alphabetical so that this reads like an index of services
- asort($serviceIds);
-
- if (!$filter) {
- return $serviceIds;
- }
-
- $regex = $this->buildFilterRegularExpression($filter);
- $filteredIds = array();
- foreach ($serviceIds as $serviceId) {
- if (preg_match($regex, $serviceId)) {
- $filteredIds[] = $serviceId;
- }
- }
-
- if (!$filteredIds) {
- // give a different message if the use was searching for an exact service
- if (false === strpos($filter, '*')) {
- $message = sprintf('The service "%s" does not exist.', $filter);
- } else {
- $message = sprintf('No services matched the pattern "%s"', $filter);
- }
-
- throw new \InvalidArgumentException($message);
- }
-
- return $filteredIds;
- }
-
- /**
- * Given a string with wildcards denoted as asterisks (*), this returns
- * the regular expression that can be used to match on the string.
- *
- * For example, *foo* would equate to:
- *
- * /^(.+?)*foo(.+?)*$/
- *
- * @param string $filter The raw filter
- * @return string The regular expression
- */
- private function buildFilterRegularExpression($filter)
- {
- $regex = preg_quote(str_replace('*', '', $filter));
-
- // process the "front" wildcard
- if ('*' === substr($filter, 0, 1)) {
- $regex = '(.+?)*'.$regex;
- }
-
- // process the "end" wildcard
- if ('*' === substr($filter, -1, 1)) {
- $regex .= '(.+?)*';
- }
- $regex = sprintf('/^%s$/', $regex);
-
- return $regex;
- }
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php
index 9c602a009c..72b84c24b6 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php
@@ -66,6 +66,7 @@ EOT
}
// validate namespace
+ $namespace = strtr($namespace, '/', '\\');
if (preg_match('/[^A-Za-z0-9_\\\-]/', $namespace)) {
throw new \InvalidArgumentException('The namespace contains invalid characters.');
}
@@ -96,8 +97,6 @@ EOT
$targetDir = $dir.strtr($namespace, '\\', '/');
-
-
if (file_exists($targetDir)) {
throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
}
@@ -107,9 +106,8 @@ EOT
$filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/'.$input->getOption('format'), $targetDir);
Mustache::renderDir($targetDir, array(
- 'namespace' => $namespace,
- 'bundle' => $bundle,
- 'bundleShort' => preg_replace('/Bundle$/', '', $bundle),
+ 'namespace' => $namespace,
+ 'bundle' => $bundle,
));
rename($targetDir.'/Bundle.php', $targetDir.'/'.$bundle.'.php');
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
index e5d18d5bce..bf5503bf4a 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
@@ -161,6 +161,10 @@ EOF
return sprintf('object(%s)', get_class($value));
}
+ if (is_string($value)) {
+ return $value;
+ }
+
return preg_replace("/\n\s*/s", '', var_export($value, true));
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php
index 539f908f49..87479a0aa6 100644
--- a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php
+++ b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php
@@ -34,7 +34,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
* The service IDs of the event listeners and subscribers
* @var array
*/
- private $listenerIds;
+ private $listenerIds = array();
/**
* Constructor.
@@ -49,22 +49,21 @@ class ContainerAwareEventDispatcher extends EventDispatcher
/**
* Adds a service as event listener
*
- * @param string|array $events One or more events for which the listener
- * is added
- * @param string $serviceId The ID of the listener service
- * @param integer $priority The higher this value, the earlier an event
- * listener will be triggered in the chain.
- * Defaults to 0.
+ * @param string|array $eventNames One or more events for which the listener is added
+ * @param string $serviceId The ID of the listener service
+ * @param integer $priority The higher this value, the earlier an event listener
+ * will be triggered in the chain.
+ * Defaults to 0.
*/
- public function addListenerService($events, $serviceId, $priority = 0)
+ public function addListenerService($eventNames, $serviceId, $priority = 0)
{
if (!is_string($serviceId)) {
throw new \InvalidArgumentException('Expected a string argument');
}
- foreach ((array) $events as $event) {
+ foreach ((array) $eventNames as $eventName) {
// Prevent duplicate entries
- $this->listenerIds[$event][$serviceId] = $priority;
+ $this->listenerIds[$eventName][$serviceId] = $priority;
}
}
@@ -73,6 +72,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher
*
* Lazily loads listeners for this event from the dependency injection
* container.
+ *
+ * @throws \InvalidArgumentException if the service is not defined
*/
public function dispatch($eventName, Event $event = null)
{
diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
index 8c9efb09a0..4e15c163ad 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
@@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ContainerAware;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Controller is a simple implementation of a Controller.
@@ -41,7 +42,7 @@ class Controller extends ContainerAware
/**
* Forwards the request to another controller.
*
- * @param string $controller The controller name (a string like Blog:Post:index)
+ * @param string $controller The controller name (a string like BlogBundle:Post:index)
* @param array $path An array of path parameters
* @param array $query An array of query parameters
*
@@ -92,6 +93,20 @@ class Controller extends ContainerAware
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
}
+ /**
+ * Returns a NotFoundHttpException.
+ *
+ * This will result in a 404 response code. Usage example:
+ *
+ * throw $this->createNotFoundException('Page not found!');
+ *
+ * @return NotFoundHttpException
+ */
+ public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
+ {
+ return new NotFoundHttpException($message, $previous);
+ }
+
/**
* Returns true if the service id is defined.
*
diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
index b1a948fc57..86dd9cea24 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
@@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface;
/**
* ControllerNameParser converts controller from the short notation a:b:c
- * (Blog:Post:index) to a fully-qualified class::method string
+ * (BlogBundle:Post:index) to a fully-qualified class::method string
* (Bundle\BlogBundle\Controller\PostController::indexAction).
*
* @author Fabien Potencier
diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php
index 1563879571..7c345111e3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php
@@ -49,12 +49,12 @@ class ExceptionController extends ContainerAware
if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
$name = 'exception_full';
}
- $template = 'Framework:Exception:'.$name.'.'.$format.'.twig';
+ $template = 'FrameworkBundle:Exception:'.$name.'.'.$format.'.twig';
$templating = $this->container->get('templating');
if (!$templating->exists($template)) {
$this->container->get('request')->setRequestFormat('html');
- $template = 'Framework:Exception:'.$name.'.html.twig';
+ $template = 'FrameworkBundle:Exception:'.$name.'.html.twig';
}
$code = $exception->getStatusCode();
diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
index 81d40ce8da..40f9a729b2 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
@@ -51,23 +51,43 @@ class RedirectController extends ContainerAware
/**
* Redirects to a URL.
*
- * It expects a url path parameter.
* By default, the response status code is 301.
*
- * If the url is empty, the status code will be 410.
- * If the permanent path parameter is set, the status code will be 302.
+ * If the path is empty, the status code will be 410.
+ * If the permanent flag is set, the status code will be 302.
*
- * @param string $url The url to redirect to
+ * @param string $path The path to redirect to
* @param Boolean $permanent Whether the redirect is permanent or not
+ * @param Boolean $scheme The URL scheme (null to keep the current one)
+ * @param integer $httpPort The HTTP port
+ * @param integer $httpsPort The HTTPS port
*
* @return Response A Response instance
*/
- public function urlRedirectAction($url, $permanent = false)
+ public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
{
- if (!$url) {
+ if (!$path) {
return new Response(null, 410);
}
+ $request = $this->container->get('request');
+ if (null === $scheme) {
+ $scheme = $request->getScheme();
+ }
+ $qs = $request->getQueryString();
+ if ($qs) {
+ $qs = '?'.$qs;
+ }
+
+ $port = '';
+ if ('http' === $scheme && 80 != $httpPort) {
+ $port = ':'.$httpPort;
+ } elseif ('https' === $scheme && 443 != $httpPort) {
+ $port = ':'.$httpsPort;
+ }
+
+ $url = $scheme.'://'.$request->getHttpHost().$port.$request->getBaseUrl().$path.$qs;
+
return new RedirectResponse($url, $permanent ? 301 : 302);
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php
index 24747f6683..bdea0f0456 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php
@@ -24,8 +24,9 @@ use Symfony\Component\EventDispatcher\Event;
*/
class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements TraceableEventDispatcherInterface
{
- protected $logger;
- protected $called;
+ private $logger;
+ private $called;
+ private $container;
/**
* Constructor.
@@ -37,10 +38,33 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
{
parent::__construct($container);
+ $this->container = $container;
$this->logger = $logger;
$this->called = array();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @throws \RuntimeException if the listener method is not callable
+ */
+ public function addListener($eventNames, $listener, $priority = 0)
+ {
+ if (!$listener instanceof \Closure) {
+ foreach ((array) $eventNames as $method) {
+ if (!is_callable(array($listener, $method))) {
+ $msg = sprintf('The event method "%s()" is not callable on the class "%s".', $method, get_class($listener));
+ if (null !== $this->logger) {
+ $this->logger->err($msg);
+ }
+ throw new \RuntimeException($msg);
+ }
+ }
+ }
+
+ parent::addListener($eventNames, $listener, $priority);
+ }
+
/**
* {@inheritDoc}
*/
@@ -48,30 +72,25 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
{
parent::triggerListener($listener, $eventName, $event);
- $listenerString = $this->listenerToString($listener);
-
if (null !== $this->logger) {
- $this->logger->debug(sprintf('Notified event "%s" to listener "%s"', $eventName, $listenerString));
+ $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, get_class($listener)));
}
- $this->called[$eventName.'.'.$listenerString] = array(
- 'class' => $listenerString,
- 'event' => $eventName,
- );
+ $this->called[$eventName.'.'.get_class($listener)] = $this->getListenerInfo($listener, $eventName);
if ($event->isPropagationStopped() && null !== $this->logger) {
- $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', $this->listenerToString($listener), $eventName));
+ $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', get_class($listener), $eventName));
$skippedListeners = $this->getListeners($eventName);
$skipped = false;
foreach ($skippedListeners as $skippedListener) {
if ($skipped) {
- $this->logger->debug(sprintf('Listener "%s" was not called for event "%s"', $this->listenerToString($skippedListener), $eventName));
+ $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', get_class($skippedListener), $eventName));
}
if ($skippedListener === $listener) {
- $skipped = false;
+ $skipped = true;
}
}
}
@@ -93,12 +112,8 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
$notCalled = array();
foreach (array_keys($this->getListeners()) as $name) {
foreach ($this->getListeners($name) as $listener) {
- $listener = $this->listenerToString($listener);
- if (!isset($this->called[$name.'.'.$listener])) {
- $notCalled[] = array(
- 'class' => $listener,
- 'event' => $name,
- );
+ if (!isset($this->called[$name.'.'.get_class($listener)])) {
+ $notCalled[$name.'.'.get_class($listener)] = $this->getListenerInfo($listener, $name);
}
}
}
@@ -106,18 +121,37 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
return $notCalled;
}
- protected function listenerToString($listener)
+ /**
+ * Returns information about the listener
+ *
+ * @param object $listener The listener
+ * @param string $eventName The event name
+ *
+ * @return array Informations about the listener
+ */
+ private function getListenerInfo($listener, $eventName)
{
- if (is_object($listener)) {
- if ($listener instanceof \Closure) {
- return 'Closure';
+ $info = array('event' => $eventName);
+ if ($listener instanceof \Closure) {
+ $info += array('type' => 'Closure');
+ } else {
+ $class = get_class($listener);
+ try {
+ $r = new \ReflectionMethod($class, $eventName);
+ $file = $r->getFileName();
+ $line = $r->getStartLine();
+ } catch (\ReflectionException $e) {
+ $file = null;
+ $line = null;
}
-
- return get_class($listener);
+ $info += array(
+ 'type' => 'Method',
+ 'class' => $class,
+ 'file' => $file,
+ 'line' => $line
+ );
}
- if (is_array($listener)) {
- return is_object($listener[0]) ? get_class($listener[0]) : implode('::', $listener);
- }
+ return $info;
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php
index b69e79a159..170c33e360 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php
@@ -41,7 +41,7 @@ class AddCacheWarmerPass implements CompilerPassInterface
krsort($warmers);
$warmers = call_user_func_array('array_merge', $warmers);
- $container->getDefinition('cache_warmer')->setArgument(0, $warmers);
+ $container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
if ('full' === $container->getParameter('kernel.cache_warmup')) {
$container->getDefinition('cache_warmer')->addMethodCall('enableOptionalWarmers', array());
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php
index 574282ea34..99ee9d6280 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php
@@ -29,6 +29,6 @@ class AddConstraintValidatorsPass implements CompilerPassInterface
}
}
- $container->getDefinition('validator.validator_factory')->setArgument(1, $validators);
+ $container->getDefinition('validator.validator_factory')->replaceArgument(1, $validators);
}
}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php
index 0a0a977147..ef88acf730 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php
@@ -33,6 +33,6 @@ class AddFieldFactoryGuessersPass implements CompilerPassInterface
return new Reference($id);
}, array_keys($container->findTaggedServiceIds('form.field_factory.guesser')));
- $container->getDefinition('form.field_factory')->setArgument(0, $guessers);
+ $container->getDefinition('form.field_factory')->replaceArgument(0, $guessers);
}
}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php
new file mode 100644
index 0000000000..9d5507082b
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php
@@ -0,0 +1,24 @@
+getCompilerLogFilename($container), false);
+ $cache->write(implode("\n", $container->getCompiler()->getLog()));
+ }
+
+ public static function getCompilerLogFilename(ContainerInterface $container)
+ {
+ $class = $container->getParameter('kernel.container_class');
+
+ return $container->getParameter('kernel.cache_dir').'/'.$class.'Compiler.log';
+ }
+}
\ No newline at end of file
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index 931be56deb..b45e2d4582 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -4,34 +4,45 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
+use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* FrameworkExtension configuration structure.
*
* @author Jeremy Mikola
*/
-class Configuration
+class Configuration implements ConfigurationInterface
{
+ private $debug;
+
/**
- * Generates the configuration tree.
+ * Constructor
*
- * @param boolean $kernelDebug The kernel.debug DIC parameter
- *
- * @return \Symfony\Component\Config\Definition\ArrayNode The config tree
+ * @param Boolean $debug Wether to use the debug mode
*/
- public function getConfigTree($kernelDebug)
+ public function __construct($debug)
+ {
+ $this->debug = (Boolean) $debug;
+ }
+
+ /**
+ * Generates the configuration tree builder.
+ *
+ * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
+ */
+ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('framework');
$rootNode
->children()
- ->scalarNode('cache_warmer')->defaultValue(!$kernelDebug)->end()
+ ->scalarNode('cache_warmer')->defaultValue(!$this->debug)->end()
->scalarNode('charset')->end()
->scalarNode('document_root')->end()
->scalarNode('error_handler')->end()
->scalarNode('exception_controller')->defaultValue('Symfony\\Bundle\\FrameworkBundle\\Controller\\ExceptionController::showAction')->end()
- ->scalarNode('ide')->end()
+ ->scalarNode('ide')->defaultNull()->end()
->booleanNode('test')->end()
->end()
;
@@ -45,7 +56,7 @@ class Configuration
$this->addTranslatorSection($rootNode);
$this->addValidationSection($rootNode);
- return $treeBuilder->buildTree();
+ return $treeBuilder;
}
private function addCsrfProtectionSection(ArrayNodeDefinition $rootNode)
@@ -90,6 +101,7 @@ class Configuration
->canBeUnset()
->children()
->booleanNode('only_exceptions')->defaultValue(false)->end()
+ ->booleanNode('only_master_requests')->defaultValue(false)->end()
->scalarNode('dsn')->defaultValue('sqlite:%kernel.cache_dir%/profiler.db')->end()
->scalarNode('username')->defaultValue('')->end()
->scalarNode('password')->defaultValue('')->end()
@@ -119,6 +131,8 @@ class Configuration
->scalarNode('cache_warmer')->defaultFalse()->end()
->scalarNode('resource')->isRequired()->end()
->scalarNode('type')->end()
+ ->scalarNode('http_port')->defaultValue(80)->end()
+ ->scalarNode('https_port')->defaultValue(443)->end()
->end()
->end()
->end()
@@ -183,12 +197,7 @@ class Configuration
->ifTrue(function($v){ return !is_array($v); })
->then(function($v){ return array($v); })
->end()
- ->prototype('scalar')
- ->beforeNormalization()
- ->ifTrue(function($v) { return is_array($v) && isset($v['value']); })
- ->then(function($v){ return $v['value']; })
- ->end()
- ->end()
+ ->prototype('scalar')->end()
->end()
->scalarNode('cache')->end()
->scalarNode('cache_warmer')->defaultFalse()->end()
@@ -201,13 +210,8 @@ class Configuration
->beforeNormalization()
->ifTrue(function($v){ return !is_array($v); })
->then(function($v){ return array($v); })
- ->end()
- ->prototype('scalar')
- ->beforeNormalization()
- ->ifTrue(function($v) { return is_array($v) && isset($v['id']); })
- ->then(function($v){ return $v['id']; })
- ->end()
->end()
+ ->prototype('scalar')->end()
->end()
->end()
->fixXmlConfig('loader')
@@ -225,18 +229,11 @@ class Configuration
->arrayNode('packages')
->useAttributeAsKey('name')
->prototype('array')
- ->children()
- ->scalarNode('version')->defaultNull()->end()
- ->end()
->fixXmlConfig('base_url')
->children()
+ ->scalarNode('version')->defaultNull()->end()
->arrayNode('base_urls')
- ->prototype('scalar')
- ->beforeNormalization()
- ->ifTrue(function($v) { return is_array($v) && isset($v['value']); })
- ->then(function($v){ return $v['value']; })
- ->end()
- ->end()
+ ->prototype('scalar')->end()
->end()
->end()
->end()
@@ -279,6 +276,7 @@ class Configuration
->end()
->children()
->booleanNode('enabled')->end()
+ ->scalarNode('cache')->end()
->arrayNode('annotations')
->canBeUnset()
->treatNullLike(array())
@@ -287,12 +285,7 @@ class Configuration
->children()
->arrayNode('namespaces')
->useAttributeAsKey('prefix')
- ->prototype('scalar')
- ->beforeNormalization()
- ->ifTrue(function($v) { return is_array($v) && isset($v['namespace']); })
- ->then(function($v){ return $v['namespace']; })
- ->end()
- ->end()
+ ->prototype('scalar')->end()
->end()
->end()
->end()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index eb91be85fc..f2297d3f4e 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -15,12 +15,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
+use Symfony\Component\Config\Definition\Processor;
/**
* FrameworkExtension.
@@ -56,9 +56,8 @@ class FrameworkExtension extends Extension
}
$processor = new Processor();
- $configuration = new Configuration();
-
- $config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs);
+ $configuration = new Configuration($container->getParameter('kernel.debug'));
+ $config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('kernel.cache_warmup', $config['cache_warmer']);
@@ -76,26 +75,18 @@ class FrameworkExtension extends Extension
} else {
$container
->getDefinition('error_handler')->addMethodCall('register', array())
- ->setArgument(0, $config['error_handler'])
+ ->replaceArgument(0, $config['error_handler'])
;
}
}
- $container->getDefinition('exception_listener')->setArgument(0, $config['exception_controller']);
-
- $pattern = '';
- if (isset($config['ide'])) {
- $patterns = array(
- 'textmate' => 'txmt://open?url=file://%%f&line=%%l',
- 'macvim' => 'mvim://open?url=file://%%f&line=%%l',
- );
- $pattern = isset($patterns[$config['ide']]) ? $patterns[$config['ide']] : $config['ide'];
- }
- $container->setParameter('debug.file_link_format', $pattern);
+ $container->getDefinition('exception_listener')->replaceArgument(0, $config['exception_controller']);
if (!empty($config['test'])) {
$loader->load('test.xml');
- $config['session']['storage_id'] = 'array';
+ if (isset($config['session'])) {
+ $config['session']['storage_id'] = 'filesystem';
+ }
}
if (isset($config['csrf_protection'])) {
@@ -119,7 +110,7 @@ class FrameworkExtension extends Extension
}
if (isset($config['templating'])) {
- $this->registerTemplatingConfiguration($config['templating'], $container, $loader);
+ $this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader);
}
if (isset($config['translator'])) {
@@ -203,7 +194,8 @@ class FrameworkExtension extends Extension
$loader->load('collectors.xml');
$container->getDefinition('profiler_listener')
- ->setArgument(2, $config['only_exceptions'])
+ ->replaceArgument(2, $config['only_exceptions'])
+ ->replaceArgument(3, $config['only_master_requests'])
;
// Choose storage class based on the DSN
@@ -217,10 +209,10 @@ class FrameworkExtension extends Extension
}
$container->getDefinition('profiler.storage')
- ->setArgument(0, $config['dsn'])
- ->setArgument(1, $config['username'])
- ->setArgument(2, $config['password'])
- ->setArgument(3, $config['lifetime'])
+ ->replaceArgument(0, $config['dsn'])
+ ->replaceArgument(1, $config['username'])
+ ->replaceArgument(2, $config['password'])
+ ->replaceArgument(3, $config['lifetime'])
->setClass($supported[$class])
;
@@ -264,6 +256,10 @@ class FrameworkExtension extends Extension
$container->setAlias('router', 'router.cached');
}
+ $def = $container->getDefinition('request_listener');
+ $def->replaceArgument(2, $config['http_port']);
+ $def->replaceArgument(3, $config['https_port']);
+
$this->addClassesToCompile(array(
'Symfony\\Component\\Routing\\RouterInterface',
'Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface',
@@ -293,7 +289,7 @@ class FrameworkExtension extends Extension
$container->setParameter('session.class', $config['class']);
}
- $container->getDefinition('session')->setArgument(1, $config['default_locale']);
+ $container->getDefinition('session')->replaceArgument(1, $config['default_locale']);
$container->setAlias('session.storage', 'session.storage.'.$config['storage_id']);
@@ -319,11 +315,21 @@ class FrameworkExtension extends Extension
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
- private function registerTemplatingConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
+ private function registerTemplatingConfiguration(array $config, $ide, ContainerBuilder $container, XmlFileLoader $loader)
{
$loader->load('templating.xml');
$loader->load('templating_php.xml');
+ $links = array(
+ 'textmate' => 'txmt://open?url=file://%f&line=%l',
+ 'macvim' => 'mvim://open?url=file://%f&line=%l',
+ );
+
+ $container
+ ->getDefinition('templating.helper.code')
+ ->replaceArgument(0, str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide))
+ ;
+
if ($container->getParameter('kernel.debug')) {
$loader->load('templating_debug.xml');
}
@@ -337,9 +343,9 @@ class FrameworkExtension extends Extension
}
$container
->getDefinition('templating.helper.assets')
- ->setArgument(1, isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array())
- ->setArgument(2, $config['assets_version'])
- ->setArgument(3, $packages)
+ ->replaceArgument(1, isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array())
+ ->replaceArgument(2, $config['assets_version'])
+ ->replaceArgument(3, $packages)
;
if (!empty($config['loaders'])) {
@@ -357,15 +363,20 @@ class FrameworkExtension extends Extension
if (isset($config['cache'])) {
// Wrap the existing loader with cache (must happen after loaders are registered)
$container->setDefinition('templating.loader.wrapped', $container->findDefinition('templating.loader'));
- $container->setDefinition('templating.loader', $container->getDefinition('templating.loader.cache'));
- $container->setParameter('templating.loader.cache.path', $config['cache']);
- } else {
- $container->setParameter('templating.loader.cache.path', null);
+ $loaderCache = $container->getDefinition('templating.loader.cache');
+ $loaderCache->replaceArgument(1, $config['cache']);
+
+ $container->setDefinition('templating.loader', $loaderCache);
}
if ($config['cache_warmer']) {
- $container->getDefinition('templating.cache_warmer.template_paths')->addTag('kernel.cache_warmer');
+ $container
+ ->getDefinition('templating.cache_warmer.template_paths')
+ ->addTag('kernel.cache_warmer', array('priority' => 20))
+ ;
$container->setAlias('templating.locator', 'templating.locator.cached');
+ } else {
+ $container->setAlias('templating.locator', 'templating.locator.uncached');
}
$this->addClassesToCompile(array(
@@ -399,7 +410,7 @@ class FrameworkExtension extends Extension
if (1 === count($engines)) {
$container->setAlias('templating', (string) reset($engines));
} else {
- $container->getDefinition('templating.engine.delegating')->setArgument(1, $engines);
+ $container->getDefinition('templating.engine.delegating')->replaceArgument(1, $engines);
$container->setAlias('templating', 'templating.engine.delegating');
}
}
@@ -462,12 +473,12 @@ class FrameworkExtension extends Extension
$container
->getDefinition('validator.mapping.loader.xml_files_loader')
- ->setArgument(0, $this->getValidatorXmlMappingFiles($container))
+ ->replaceArgument(0, $this->getValidatorXmlMappingFiles($container))
;
$container
->getDefinition('validator.mapping.loader.yaml_files_loader')
- ->setArgument(0, $this->getValidatorYamlMappingFiles($container))
+ ->replaceArgument(0, $this->getValidatorYamlMappingFiles($container))
;
if (isset($config['annotations'])) {
@@ -480,7 +491,7 @@ class FrameworkExtension extends Extension
// Register annotation loader
$container
->getDefinition('validator.mapping.loader.annotation_loader')
- ->setArgument(0, $namespaces)
+ ->replaceArgument(0, $namespaces)
;
$loaderChain = $container->getDefinition('validator.mapping.loader.loader_chain');
@@ -488,6 +499,15 @@ class FrameworkExtension extends Extension
array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader'));
$loaderChain->setArguments($arguments);
}
+
+ if (isset($config['cache'])) {
+ $container->getDefinition('validator.mapping.class_metadata_factory')
+ ->replaceArgument(1, new Reference('validator.mapping.cache.'.$config['cache']));
+ $container->setParameter(
+ 'validator.mapping.cache.prefix',
+ 'validator_'.md5($container->getParameter('kernel.root_dir'))
+ );
+ }
}
private function getValidatorXmlMappingFiles(ContainerBuilder $container)
@@ -513,7 +533,7 @@ class FrameworkExtension extends Extension
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (file_exists($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) {
- $yamlMappingFiles[] = realpath($file);
+ $files[] = realpath($file);
$container->addResource(new FileResource($file));
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
index 9dae9332ec..dedd53aed9 100644
--- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
@@ -22,6 +22,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToAuto
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Scope;
@@ -81,6 +82,10 @@ class FrameworkBundle extends Bundle
$container->addCompilerPass(new AddClassesToAutoloadMapPass());
$container->addCompilerPass(new TranslatorPass());
$container->addCompilerPass(new AddCacheWarmerPass());
- $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING);
+
+ if ($container->getParameter('kernel.debug')) {
+ $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING);
+ $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
+ }
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php b/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php
deleted file mode 100644
index 58a5356c6f..0000000000
--- a/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php
+++ /dev/null
@@ -1,44 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\FrameworkBundle\HttpFoundation;
-
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
-use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
-
-/**
- * SessionListener.
- *
- * Saves session in test environment.
- *
- * @author Bulat Shakirzyanov
- */
-class SessionListener
-{
- /**
- * Checks if session was initialized and saves if current request is master
- * Runs on 'onCoreResponse' in test environment
- *
- * @param FilterResponseEvent $event
- */
- public function onCoreResponse(FilterResponseEvent $event)
- {
- if ($request = $event->getRequest()) {
- if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
- if ($session = $request->getSession()) {
- $session->save();
- }
- }
- }
- }
-}
diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
index 9e9dc4b7a9..dcde0d34df 100644
--- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
+++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
@@ -47,7 +47,7 @@ class HttpKernel extends BaseHttpKernel
/**
* Forwards the request to another controller.
*
- * @param string $controller The controller name (a string like Blog:Post:index)
+ * @param string $controller The controller name (a string like BlogBundle:Post:index)
* @param array $attributes An array of request attributes
* @param array $query An array of request query parameters
*
@@ -76,7 +76,7 @@ class HttpKernel extends BaseHttpKernel
* * standalone: whether to generate an esi:include tag or not when ESI is supported
* * comment: a comment to add when returning an esi:include tag
*
- * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI
+ * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
* @param array $options An array of options
*
* @return string The Response content
@@ -153,7 +153,7 @@ class HttpKernel extends BaseHttpKernel
*
* This method uses the "_internal" route, which should be available.
*
- * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI
+ * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
* @param array $attributes An array of request attributes
* @param array $query An array of request query parameters
*
@@ -169,7 +169,7 @@ class HttpKernel extends BaseHttpKernel
'controller' => $controller,
'path' => $attributes ? http_build_query($attributes) : 'none',
'_format' => $this->container->get('request')->getRequestFormat(),
- ), true);
+ ));
if ($query) {
$uri = $uri.'?'.http_build_query($query);
diff --git a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php
index fcb97a25bd..f3f0524002 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php
@@ -27,9 +27,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class ProfilerListener
{
protected $container;
- protected $exception;
- protected $onlyException;
protected $matcher;
+ protected $onlyException;
+ protected $onlyMasterRequests;
+ protected $exception;
/**
* Constructor.
@@ -37,12 +38,14 @@ class ProfilerListener
* @param ContainerInterface $container A ContainerInterface instance
* @param RequestMatcherInterface $matcher A RequestMatcher instance
* @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
+ * @param Boolean $onlyMaster true if the profiler only collects data when the request is a master request, false otherwise
*/
- public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false)
+ public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
{
$this->container = $container;
$this->matcher = $matcher;
- $this->onlyException = $onlyException;
+ $this->onlyException = (Boolean) $onlyException;
+ $this->onlyMasterRequests = (Boolean) $onlyMasterRequests;
}
/**
@@ -81,6 +84,10 @@ class ProfilerListener
{
$response = $event->getResponse();
+ if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+ return $response;
+ }
+
if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) {
return $response;
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php
index 5a5c81721d..ac68a2e57c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php
+++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php
@@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Matcher\Exception\NotFoundException;
use Symfony\Component\Routing\RouterInterface;
+use Symfony\Component\Routing\RequestContext;
/**
* RequestListener.
@@ -29,14 +30,18 @@ use Symfony\Component\Routing\RouterInterface;
*/
class RequestListener
{
- protected $router;
- protected $logger;
- protected $container;
+ private $router;
+ private $logger;
+ private $container;
+ private $httpPort;
+ private $httpsPort;
- public function __construct(ContainerInterface $container, RouterInterface $router, LoggerInterface $logger = null)
+ public function __construct(ContainerInterface $container, RouterInterface $router, $httpPort = 80, $httpsPort = 443, LoggerInterface $logger = null)
{
$this->container = $container;
$this->router = $router;
+ $this->httpPort = $httpPort;
+ $this->httpsPort = $httpsPort;
$this->logger = $logger;
}
@@ -72,13 +77,20 @@ class RequestListener
if ($master) {
// set the context even if the parsing does not need to be done
// to have correct link generation
- $this->router->setContext(array(
- 'base_url' => $request->getBaseUrl(),
- 'method' => $request->getMethod(),
- 'host' => $request->getHost(),
- 'port' => $request->getPort(),
- 'is_secure' => $request->isSecure(),
- ));
+ $context = new RequestContext(
+ $request->getBaseUrl(),
+ $request->getMethod(),
+ $request->getHost(),
+ $request->getScheme(),
+ $this->httpPort,
+ $this->httpsPort
+ );
+
+ if ($session = $request->getSession()) {
+ $context->setParameter('_locale', $session->getLocale());
+ }
+
+ $this->router->setContext($context);
}
if ($request->attributes->has('_controller')) {
@@ -91,14 +103,10 @@ class RequestListener
$parameters = $this->router->match($request->getPathInfo());
if (null !== $this->logger) {
- $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
+ $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
}
$request->attributes->add($parameters);
-
- if ($locale = $request->attributes->get('_locale')) {
- $request->getSession()->setLocale($locale);
- }
} catch (NotFoundException $e) {
$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
if (null !== $this->logger) {
@@ -112,5 +120,20 @@ class RequestListener
}
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
}
+
+ if ($master && $locale = $request->attributes->get('_locale')) {
+ $request->getSession()->setLocale($locale);
+ $context->setParameter('_locale', $locale);
+ }
+ }
+
+ private function parametersToString(array $parameters)
+ {
+ $pieces = array();
+ foreach ($parameters as $key => $val) {
+ $pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val)));
+ }
+
+ return implode(', ', $pieces);
}
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
index e2bbd15e63..d68b99cdc5 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
@@ -16,38 +16,39 @@
-
+
-
+
-
+
-
+
-
+
+
-
+
-
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
index c1fefe3eaa..ec149eea85 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
@@ -10,6 +10,7 @@
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
index 0659d3b023..9dcaaa401d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
@@ -11,6 +11,7 @@
+
@@ -29,6 +30,7 @@
+