Upgraded to Symfony 2.1-beta2
This commit is contained in:
@@ -280,7 +280,7 @@ class SQLServerPlatform extends AbstractPlatform
|
||||
$columnSql = array();
|
||||
|
||||
if ($diff->newName !== false) {
|
||||
$queryParts[] = 'RENAME TO ' . $diff->newName;
|
||||
$queryParts[] = "sp_RENAME '" . $diff->name . "', '" . $diff->newName . "'";
|
||||
}
|
||||
|
||||
foreach ($diff->addedColumns AS $fieldName => $column) {
|
||||
|
@@ -61,10 +61,10 @@ class SQLParserUtils
|
||||
} else {
|
||||
$name = "";
|
||||
// TODO: Something faster/better to match this than regex?
|
||||
for ($j = $i; ($j < $stmtLen && preg_match('(([:a-zA-Z0-9_]{1}))', $statement[$j])); $j++) {
|
||||
for ($j = $i + 1; ($j < $stmtLen && preg_match('(([a-zA-Z0-9_]{1}))', $statement[$j])); $j++) {
|
||||
$name .= $statement[$j];
|
||||
}
|
||||
$paramMap[$name][] = $i; // named parameters can be duplicated!
|
||||
$paramMap[$i] = $name; // named parameters can be duplicated!
|
||||
$i = $j;
|
||||
}
|
||||
++$count;
|
||||
@@ -139,34 +139,28 @@ class SQLParserUtils
|
||||
$queryOffset= 0;
|
||||
$typesOrd = array();
|
||||
$paramsOrd = array();
|
||||
foreach ($paramPos as $needle => $needlePos) {
|
||||
$paramLen = strlen($needle);
|
||||
$token = substr($needle,0,1);
|
||||
$needle = substr($needle,1);
|
||||
$value = $params[$needle];
|
||||
foreach ($paramPos as $pos => $paramName) {
|
||||
$paramLen = strlen($paramName) + 1;
|
||||
$value = $params[$paramName];
|
||||
|
||||
if (!isset($arrayPositions[$needle])) {
|
||||
foreach ($needlePos as $pos) {
|
||||
$pos += $queryOffset;
|
||||
$queryOffset -= ($paramLen - 1);
|
||||
$paramsOrd[] = $value;
|
||||
$typesOrd[] = $types[$needle];
|
||||
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
|
||||
}
|
||||
if (!isset($arrayPositions[$paramName])) {
|
||||
$pos += $queryOffset;
|
||||
$queryOffset -= ($paramLen - 1);
|
||||
$paramsOrd[] = $value;
|
||||
$typesOrd[] = $types[$paramName];
|
||||
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
|
||||
} else {
|
||||
$len = count($value);
|
||||
$expandStr = implode(", ", array_fill(0, $len, "?"));
|
||||
foreach ($needlePos as $pos) {
|
||||
|
||||
foreach ($value as $val) {
|
||||
$paramsOrd[] = $val;
|
||||
$typesOrd[] = $types[$needle] - Connection::ARRAY_PARAM_OFFSET;
|
||||
}
|
||||
|
||||
$pos += $queryOffset;
|
||||
$queryOffset += (strlen($expandStr) - $paramLen);
|
||||
$query = substr($query, 0, $pos) . $expandStr . substr($query, ($pos + $paramLen));
|
||||
foreach ($value as $val) {
|
||||
$paramsOrd[] = $val;
|
||||
$typesOrd[] = $types[$paramName] - Connection::ARRAY_PARAM_OFFSET;
|
||||
}
|
||||
|
||||
$pos += $queryOffset;
|
||||
$queryOffset += (strlen($expandStr) - $paramLen);
|
||||
$query = substr($query, 0, $pos) . $expandStr . substr($query, ($pos + $paramLen));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -77,6 +77,14 @@ class Index extends AbstractAsset implements Constraint
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUnquotedColumns()
|
||||
{
|
||||
return array_map(array($this, 'trimQuotes'), $this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the index neither unique nor primary key?
|
||||
*
|
||||
@@ -108,11 +116,11 @@ class Index extends AbstractAsset implements Constraint
|
||||
* @param int $pos
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumnAtPosition($columnName, $pos=0)
|
||||
public function hasColumnAtPosition($columnName, $pos = 0)
|
||||
{
|
||||
$columnName = strtolower($columnName);
|
||||
$indexColumns = \array_map('strtolower', $this->getColumns());
|
||||
return \array_search($columnName, $indexColumns) === $pos;
|
||||
$columnName = $this->trimQuotes(strtolower($columnName));
|
||||
$indexColumns = array_map('strtolower', $this->getUnquotedColumns());
|
||||
return array_search($columnName, $indexColumns) === $pos;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +133,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
{
|
||||
$sameColumns = true;
|
||||
for ($i = 0; $i < count($this->_columns); $i++) {
|
||||
if (!isset($columnNames[$i]) || strtolower($this->_columns[$i]) != strtolower($columnNames[$i])) {
|
||||
if (!isset($columnNames[$i]) || $this->trimQuotes(strtolower($this->_columns[$i])) != $this->trimQuotes(strtolower($columnNames[$i]))) {
|
||||
$sameColumns = false;
|
||||
}
|
||||
}
|
||||
@@ -185,4 +193,4 @@ class Index extends AbstractAsset implements Constraint
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,9 @@ use Doctrine\DBAL\DriverManager;
|
||||
*/
|
||||
class CreateDatabaseDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -47,6 +50,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$connection = $this->getDoctrineConnection($input->getOption('connection'));
|
||||
|
@@ -24,6 +24,11 @@ use Doctrine\ORM\Tools\EntityGenerator;
|
||||
*/
|
||||
abstract class DoctrineCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* get a doctrine entity generator
|
||||
*
|
||||
* @return EntityGenerator
|
||||
*/
|
||||
protected function getEntityGenerator()
|
||||
{
|
||||
$entityGenerator = new EntityGenerator();
|
||||
@@ -37,6 +42,12 @@ abstract class DoctrineCommand extends ContainerAwareCommand
|
||||
return $entityGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a doctrine entity manager by symfony name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected function getEntityManager($name)
|
||||
{
|
||||
return $this->getContainer()->get('doctrine')->getManager($name);
|
||||
@@ -46,7 +57,7 @@ abstract class DoctrineCommand extends ContainerAwareCommand
|
||||
* Get a doctrine dbal connection by symfony name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Doctrine\DBAL\Connection
|
||||
* @return \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected function getDoctrineConnection($name)
|
||||
{
|
||||
|
@@ -26,6 +26,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
class DropDatabaseDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -52,6 +55,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$connection = $this->getDoctrineConnection($input->getOption('connection'));
|
||||
|
@@ -29,6 +29,9 @@ use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
|
||||
*/
|
||||
class GenerateEntitiesDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -79,6 +82,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
|
||||
|
@@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
*/
|
||||
class ImportMappingDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -65,6 +68,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
|
||||
|
@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand;
|
||||
*/
|
||||
class ClearMetadataCacheDoctrineCommand extends MetadataCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -49,6 +52,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand;
|
||||
*/
|
||||
class ClearQueryCacheDoctrineCommand extends QueryCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -49,6 +52,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
|
||||
*/
|
||||
class ClearResultCacheDoctrineCommand extends ResultCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -45,25 +48,13 @@ You can also optionally specify the <comment>--em</comment> option to specify
|
||||
which entity manager to clear the cache for:
|
||||
|
||||
<info>php app/console doctrine:cache:clear-result --em=default</info>
|
||||
|
||||
If you don't want to clear all result cache you can specify some additional
|
||||
options to control what cache is deleted:
|
||||
|
||||
<info>php app/console doctrine:cache:clear-result --id=cache_key</info>
|
||||
|
||||
Or you can specify a <comment>--regex</comment> to delete cache entries that
|
||||
match it:
|
||||
|
||||
<info>php app/console doctrine:cache:clear-result --regex="user_(.*)"</info>
|
||||
|
||||
You can also specify a <comment>--prefix</comment> or
|
||||
<comment>--suffix</comment> to delete cache entries for:
|
||||
|
||||
<info>php app/console doctrine:cache:clear-result --prefix="user_" --suffix="_frontend"</info>
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
|
||||
*/
|
||||
class ConvertMappingDoctrineCommand extends ConvertMappingCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -46,6 +49,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
@@ -53,9 +59,15 @@ EOT
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $toType
|
||||
* @param string $destPath
|
||||
*
|
||||
* @return \Doctrine\ORM\Tools\Export\Driver\AbstractExporter
|
||||
*/
|
||||
protected function getExporter($toType, $destPath)
|
||||
{
|
||||
/** @var $exporter \Doctrine\ORM\Tools\Export\Driver\AbstractExporter */
|
||||
$exporter = parent::getExporter($toType, $destPath);
|
||||
if ($exporter instanceof XmlExporter) {
|
||||
$exporter->setExtension('.orm.xml');
|
||||
|
@@ -29,6 +29,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
|
||||
*/
|
||||
class CreateSchemaDoctrineCommand extends CreateCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -54,6 +57,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
|
||||
@@ -33,12 +33,19 @@ abstract class DoctrineCommandHelper
|
||||
*/
|
||||
static public function setApplicationEntityManager(Application $application, $emName)
|
||||
{
|
||||
/** @var $em \Doctrine\ORM\EntityManager */
|
||||
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
|
||||
$helperSet = $application->getHelperSet();
|
||||
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
|
||||
$helperSet->set(new EntityManagerHelper($em), 'em');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to push the helper sets of a given connection into the application.
|
||||
*
|
||||
* @param Application $application
|
||||
* @param string $connName
|
||||
*/
|
||||
static public function setApplicationConnection(Application $application, $connName)
|
||||
{
|
||||
$connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);
|
||||
|
@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand;
|
||||
*/
|
||||
class DropSchemaDoctrineCommand extends DropCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -54,6 +57,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
|
||||
*/
|
||||
class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -49,6 +52,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -27,6 +27,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
class InfoDoctrineCommand extends InfoCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -48,6 +51,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
|
||||
*/
|
||||
class RunDqlDoctrineCommand extends RunDqlCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -54,6 +57,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -28,6 +28,9 @@ use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
|
||||
*/
|
||||
class RunSqlDoctrineCommand extends RunSqlCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -44,6 +47,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection'));
|
||||
|
@@ -29,6 +29,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
|
||||
*/
|
||||
class UpdateSchemaDoctrineCommand extends UpdateCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -58,6 +61,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand as DoctrineValidate
|
||||
*/
|
||||
class ValidateSchemaCommand extends DoctrineValidateSchemaCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
@@ -50,6 +53,9 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
@@ -69,6 +69,9 @@ class ConnectionFactory
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the types
|
||||
*/
|
||||
private function initializeTypes()
|
||||
{
|
||||
foreach ($this->typesConfig as $type => $typeConfig) {
|
||||
|
@@ -35,6 +35,7 @@ class ProfilerController extends ContainerAware
|
||||
*/
|
||||
public function explainAction($token, $connectionName, $query)
|
||||
{
|
||||
/** @var $profiler \Symfony\Component\HttpKernel\Profiler\Profiler */
|
||||
$profiler = $this->container->get('profiler');
|
||||
$profiler->disable();
|
||||
|
||||
|
@@ -41,9 +41,7 @@ class Configuration implements ConfigurationInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the configuration tree builder.
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
@@ -56,6 +54,11 @@ class Configuration implements ConfigurationInterface
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add DBAL section to configuration tree
|
||||
*
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addDbalSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
@@ -105,6 +108,11 @@ class Configuration implements ConfigurationInterface
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the dbal connections node
|
||||
*
|
||||
* @return ArrayNodeDefinition
|
||||
*/
|
||||
private function getDbalConnectionsNode()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
@@ -157,7 +165,7 @@ class Configuration implements ConfigurationInterface
|
||||
*
|
||||
* These keys are available for slave configurations too.
|
||||
*
|
||||
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function configureDbalDriverNode(ArrayNodeDefinition $node)
|
||||
{
|
||||
@@ -202,6 +210,11 @@ class Configuration implements ConfigurationInterface
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the ORM section to configuration tree
|
||||
*
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addOrmSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
@@ -246,6 +259,11 @@ class Configuration implements ConfigurationInterface
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ORM target entity resolver node
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
|
||||
*/
|
||||
private function getOrmTargetEntityResolverNode()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
@@ -261,6 +279,11 @@ class Configuration implements ConfigurationInterface
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ORM entity manager node
|
||||
*
|
||||
* @return ArrayNodeDefinition
|
||||
*/
|
||||
private function getOrmEntityManagersNode()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
@@ -362,6 +385,13 @@ class Configuration implements ConfigurationInterface
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a ORM cache driver node for an given entity manager
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return ArrayNodeDefinition
|
||||
*/
|
||||
private function getOrmCacheDriverNode($name)
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
|
@@ -32,6 +32,9 @@ use Symfony\Component\Config\FileLocator;
|
||||
*/
|
||||
class DoctrineExtension extends AbstractDoctrineExtension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = $this->getConfiguration($configs, $container);
|
||||
@@ -377,6 +380,9 @@ class DoctrineExtension extends AbstractDoctrineExtension
|
||||
$ormConfigDef->addMethodCall('setEntityNamespaces', array($this->aliasMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getObjectManagerElementName($name)
|
||||
{
|
||||
return 'doctrine.orm.'.$name;
|
||||
@@ -387,11 +393,17 @@ class DoctrineExtension extends AbstractDoctrineExtension
|
||||
return 'Entity';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getMappingResourceConfigDirectory()
|
||||
{
|
||||
return 'Resources/config/doctrine';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getMappingResourceExtension()
|
||||
{
|
||||
return 'orm';
|
||||
@@ -411,9 +423,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base path for the XSD files.
|
||||
*
|
||||
* @return string The XSD base path
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
@@ -421,15 +431,16 @@ class DoctrineExtension extends AbstractDoctrineExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the namespace to be used for this extension (XML namespace).
|
||||
*
|
||||
* @return string The XML namespace
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return 'http://symfony.com/schema/dic/doctrine';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new Configuration($container->getParameter('kernel.debug'));
|
||||
|
@@ -36,6 +36,9 @@ class DoctrineBundle extends Bundle
|
||||
{
|
||||
private $autoloader;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
@@ -48,6 +51,9 @@ class DoctrineBundle extends Bundle
|
||||
$container->addCompilerPass(new DoctrineValidationPass('orm'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Register an autoloader for proxies to avoid issues when unserializing them
|
||||
@@ -66,9 +72,11 @@ class DoctrineBundle extends Bundle
|
||||
|
||||
if (!is_file($file) && $container->getParameter('kernel.debug')) {
|
||||
$originalClassName = ClassUtils::getRealClass($class);
|
||||
/** @var $registry Registry */
|
||||
$registry = $container->get('doctrine');
|
||||
|
||||
// Tries to auto-generate the proxy file
|
||||
/** @var $em \Doctrine\ORM\EntityManager */
|
||||
foreach ($registry->getManagers() as $em) {
|
||||
|
||||
if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
|
||||
@@ -94,6 +102,9 @@ class DoctrineBundle extends Bundle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
if (null !== $this->autoloader) {
|
||||
@@ -102,6 +113,9 @@ class DoctrineBundle extends Bundle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function registerCommands(Application $application)
|
||||
{
|
||||
// Use the default logic when the ORM is available.
|
||||
|
@@ -45,6 +45,13 @@ class ManagerConfigurator
|
||||
$this->enableFilters($entityManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable filters for an given entity manager
|
||||
*
|
||||
* @param EntityManager $entityManager
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function enableFilters(EntityManager $entityManager)
|
||||
{
|
||||
if (empty($this->enabledFilters)) {
|
||||
|
@@ -23,31 +23,51 @@ class ClassMetadataCollection
|
||||
private $namespace;
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $metadata
|
||||
*/
|
||||
public function __construct(array $metadata)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $namespace
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
|
@@ -19,6 +19,9 @@ namespace Doctrine\Bundle\DoctrineBundle\Mapping;
|
||||
*/
|
||||
class DisconnectedMetadataFactory extends MetadataFactory
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassMetadataFactoryClass()
|
||||
{
|
||||
return 'Doctrine\\ORM\\Tools\\DisconnectedClassMetadataFactory';
|
||||
|
@@ -44,6 +44,7 @@ class MetadataFactory
|
||||
* @param BundleInterface $bundle A BundleInterface instance
|
||||
*
|
||||
* @return ClassMetadataCollection A ClassMetadataCollection instance
|
||||
* @throws \RuntimeException When bundle does not contain mapped entities
|
||||
*/
|
||||
public function getBundleMetadata(BundleInterface $bundle)
|
||||
{
|
||||
@@ -68,6 +69,7 @@ class MetadataFactory
|
||||
* @param string $path The path where the class is stored (if known)
|
||||
*
|
||||
* @return ClassMetadataCollection A ClassMetadataCollection instance
|
||||
* @throws MappingException When class is not valid entity or mapped superclass
|
||||
*/
|
||||
public function getClassMetadata($class, $path = null)
|
||||
{
|
||||
@@ -88,6 +90,7 @@ class MetadataFactory
|
||||
* @param string $path The path where the class is stored (if known)
|
||||
*
|
||||
* @return ClassMetadataCollection A ClassMetadataCollection instance
|
||||
* @throws \RuntimeException When namespace not contain mapped entities
|
||||
*/
|
||||
public function getNamespaceMetadata($namespace, $path = null)
|
||||
{
|
||||
@@ -105,8 +108,9 @@ class MetadataFactory
|
||||
* Find and configure path and namespace for the metadata collection.
|
||||
*
|
||||
* @param ClassMetadataCollection $metadata
|
||||
* @param string|null $path
|
||||
* @return void
|
||||
* @param string|null $path
|
||||
*
|
||||
* @throws \RuntimeException When unable to determine the path
|
||||
*/
|
||||
public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadata, $path = null)
|
||||
{
|
||||
@@ -122,11 +126,21 @@ class MetadataFactory
|
||||
$metadata->setNamespace(isset($r) ? $r->getNamespaceName() : $all[0]->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a base path for a class
|
||||
*
|
||||
* @param string $name class name
|
||||
* @param string $namespace class namespace
|
||||
* @param string $path class path
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException When base path not found
|
||||
*/
|
||||
private function getBasePathForClass($name, $namespace, $path)
|
||||
{
|
||||
$namespace = str_replace('\\', '/', $namespace);
|
||||
$search = str_replace('\\', '/', $path);
|
||||
$destination = str_replace('/'.$namespace, '', $search, $c);
|
||||
$destination = str_replace('/' . $namespace, '', $search, $c);
|
||||
|
||||
if ($c != 1) {
|
||||
throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
|
||||
@@ -135,6 +149,11 @@ class MetadataFactory
|
||||
return $destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return ClassMetadataCollection
|
||||
*/
|
||||
private function getMetadataForNamespace($namespace)
|
||||
{
|
||||
$metadata = array();
|
||||
@@ -147,6 +166,11 @@ class MetadataFactory
|
||||
return new ClassMetadataCollection($metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entity
|
||||
*
|
||||
* @return ClassMetadataCollection
|
||||
*/
|
||||
private function getMetadataForClass($entity)
|
||||
{
|
||||
foreach ($this->getAllMetadata() as $metadata) {
|
||||
@@ -158,11 +182,15 @@ class MetadataFactory
|
||||
return new ClassMetadataCollection(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getAllMetadata()
|
||||
{
|
||||
$metadata = array();
|
||||
foreach ($this->registry->getManagers() as $em) {
|
||||
$class = $this->getClassMetadataFactoryClass();
|
||||
/** @var $cmf \Doctrine\ORM\Mapping\ClassMetadataFactory */
|
||||
$cmf = new $class();
|
||||
$cmf->setEntityManager($em);
|
||||
foreach ($cmf->getAllMetadata() as $m) {
|
||||
@@ -173,6 +201,9 @@ class MetadataFactory
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassMetadataFactoryClass()
|
||||
{
|
||||
return 'Doctrine\\ORM\\Mapping\\ClassMetadataFactory';
|
||||
|
@@ -27,6 +27,15 @@ use Doctrine\ORM\EntityManager;
|
||||
*/
|
||||
class Registry extends ManagerRegistry implements RegistryInterface
|
||||
{
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
* @param array $connections
|
||||
* @param array $entityManagers
|
||||
* @param string $defaultConnection
|
||||
* @param string $defaultEntityManager
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
|
||||
{
|
||||
$this->setContainer($container);
|
||||
|
@@ -150,7 +150,7 @@ certain classes, but those are for very advanced use-cases only.
|
||||
Caching Drivers
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
For the caching drivers you can specify the values "array", "apc", "memcache"
|
||||
For the caching drivers you can specify the values "array", "apc", "memcache", "memcached"
|
||||
or "xcache".
|
||||
|
||||
The following example shows an overview of the caching configurations:
|
||||
|
@@ -37,6 +37,7 @@
|
||||
"psr-0": { "Doctrine\\Bundle\\DoctrineBundle": "" }
|
||||
},
|
||||
"target-dir": "Doctrine/Bundle/DoctrineBundle",
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
|
@@ -124,8 +124,15 @@ class EntityRepository implements ObjectRepository
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($lockMode !== LockMode::NONE) {
|
||||
$this->_em->lock($entity, $lockMode, $lockVersion);
|
||||
switch ($lockMode) {
|
||||
case LockMode::OPTIMISTIC:
|
||||
$this->_em->lock($entity, $lockMode, $lockVersion);
|
||||
break;
|
||||
case LockMode::PESSIMISTIC_READ:
|
||||
case LockMode::PESSIMISTIC_WRITE:
|
||||
$persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);
|
||||
$persister->refresh($sortedId, $entity, $lockMode);
|
||||
break;
|
||||
}
|
||||
|
||||
return $entity; // Hit!
|
||||
|
@@ -364,7 +364,19 @@ class BasicEntityPersister
|
||||
$targetMapping = $this->_em->getClassMetadata($this->_class->associationMappings[$idField]['targetEntity']);
|
||||
$where[] = $this->_class->associationMappings[$idField]['joinColumns'][0]['name'];
|
||||
$params[] = $id[$idField];
|
||||
$types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
|
||||
|
||||
switch (true) {
|
||||
case (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])):
|
||||
$types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
|
||||
break;
|
||||
|
||||
case (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])):
|
||||
$types[] = $targetMapping->associationMappings[$targetMapping->identifier[0]]['type'];
|
||||
break;
|
||||
|
||||
default:
|
||||
throw ORMException::unrecognizedField($targetMapping->identifier[0]);
|
||||
}
|
||||
} else {
|
||||
$where[] = $this->_class->getQuotedColumnName($idField, $this->_platform);
|
||||
$params[] = $id[$idField];
|
||||
@@ -690,9 +702,9 @@ class BasicEntityPersister
|
||||
* column or field names to values.
|
||||
* @param object $entity The entity to refresh.
|
||||
*/
|
||||
public function refresh(array $id, $entity)
|
||||
public function refresh(array $id, $entity, $lockMode = 0)
|
||||
{
|
||||
$sql = $this->_getSelectEntitiesSQL($id);
|
||||
$sql = $this->_getSelectEntitiesSQL($id, null, $lockMode);
|
||||
list($params, $types) = $this->expandParameters($id);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
|
||||
|
@@ -184,7 +184,19 @@ class ProxyFactory
|
||||
|
||||
$file = str_replace($placeholders, $replacements, $file);
|
||||
|
||||
file_put_contents($fileName, $file, LOCK_EX);
|
||||
$parentDirectory = dirname($fileName);
|
||||
|
||||
if ( ! is_dir($parentDirectory)) {
|
||||
if (false === @mkdir($parentDirectory, 0775, true)) {
|
||||
throw ProxyException::proxyDirectoryNotWritable();
|
||||
}
|
||||
} else if ( ! is_writable($parentDirectory)) {
|
||||
throw ProxyException::proxyDirectoryNotWritable();
|
||||
}
|
||||
|
||||
$tmpFileName = $fileName . '.' . uniqid("", true);
|
||||
file_put_contents($tmpFileName, $file);
|
||||
rename($tmpFileName, $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -136,6 +136,23 @@ public function <methodName>(<methodTypeHint>$<variableName>)
|
||||
<spaces>return $this;
|
||||
}';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $_removeMethodTemplate =
|
||||
'/**
|
||||
* <description>
|
||||
*
|
||||
* @param <variableType$<variableName>
|
||||
*/
|
||||
public function <methodName>(<methodTypeHint>$<variableName>)
|
||||
{
|
||||
<spaces>$this-><fieldName>->removeElement($<variableName>);
|
||||
}';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $_lifecycleCallbackMethodTemplate =
|
||||
'/**
|
||||
* @<name>
|
||||
@@ -672,6 +689,9 @@ public function <methodName>()
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'remove', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
@@ -756,12 +776,9 @@ public function <methodName>()
|
||||
|
||||
private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
|
||||
{
|
||||
if ($type == "add") {
|
||||
$addMethod = explode("\\", $typeHint);
|
||||
$addMethod = end($addMethod);
|
||||
$methodName = $type . $addMethod;
|
||||
} else {
|
||||
$methodName = $type . Inflector::classify($fieldName);
|
||||
$methodName = $type . Inflector::classify($fieldName);
|
||||
if (in_array($type, array("add", "remove")) && substr($methodName, -1) == "s") {
|
||||
$methodName = substr($methodName, 0, -1);
|
||||
}
|
||||
|
||||
if ($this->_hasMethod($methodName, $metadata)) {
|
||||
|
@@ -1118,6 +1118,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if (isset($this->entityIdentifiers[$oid])) {
|
||||
$this->addToIdentityMap($entity);
|
||||
}
|
||||
|
||||
if ($entity instanceof NotifyPropertyChanged) {
|
||||
$entity->addPropertyChangedListener($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1296,10 +1300,6 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$this->identityMap[$className][$idHash] = $entity;
|
||||
|
||||
if ($entity instanceof NotifyPropertyChanged) {
|
||||
$entity->addPropertyChangedListener($this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1649,7 +1649,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$oid = spl_object_hash($entity);
|
||||
|
||||
if (isset($visited[$oid])) {
|
||||
return; // Prevent infinite recursion
|
||||
return $visited[$oid]; // Prevent infinite recursion
|
||||
}
|
||||
|
||||
$visited[$oid] = $entity; // mark visited
|
||||
@@ -2356,11 +2356,12 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
} else {
|
||||
$entity = $this->newInstance($class);
|
||||
$oid = spl_object_hash($entity);
|
||||
$oid = spl_object_hash($entity);
|
||||
|
||||
$this->entityIdentifiers[$oid] = $id;
|
||||
$this->entityStates[$oid] = self::STATE_MANAGED;
|
||||
$this->entityIdentifiers[$oid] = $id;
|
||||
$this->entityStates[$oid] = self::STATE_MANAGED;
|
||||
$this->originalEntityData[$oid] = $data;
|
||||
|
||||
$this->identityMap[$class->rootEntityName][$idHash] = $entity;
|
||||
|
||||
if ($entity instanceof NotifyPropertyChanged) {
|
||||
@@ -2790,6 +2791,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$this->originalEntityData[$oid] = $data;
|
||||
|
||||
$this->addToIdentityMap($entity);
|
||||
|
||||
if ($entity instanceof NotifyPropertyChanged) {
|
||||
$entity->addPropertyChangedListener($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user