Skip to content

Commit

Permalink
[DoctrineBundle] made the ORM integration of DoctrineBundle usable
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage authored and fabpot committed Feb 22, 2010
1 parent 0dcaabf commit f87f890
Show file tree
Hide file tree
Showing 14 changed files with 654 additions and 23 deletions.
27 changes: 26 additions & 1 deletion src/Symfony/Framework/DoctrineBundle/Bundle.php
Expand Up @@ -22,11 +22,36 @@
*
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class Bundle extends BaseBundle
{
public function buildContainer(ContainerInterface $container)
{
Loader::registerExtension(new DoctrineExtension());

$metadataDirs = array();
$entityDirs = array();
$bundleDirs = $container->getParameter('kernel.bundle_dirs');
foreach ($container->getParameter('kernel.bundles') as $className)
{
$tmp = dirname(str_replace('\\', '/', $className));
$namespace = dirname($tmp);
$class = basename($tmp);

if (isset($bundleDirs[$namespace]))
{
if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata'))
{
$metadataDirs[] = $dir;
}
if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities'))
{
$entityDirs[] = $dir;
}
}
}
$container->setParameter('doctrine.orm.metadata_driver_impl.dirs', $metadataDirs);
$container->setParameter('doctrine.entity_dirs', $entityDirs);
}
}
}
@@ -0,0 +1,62 @@
<?php

namespace Symfony\Framework\DoctrineBundle\Command;

use Symfony\Components\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output;
use Symfony\Framework\WebBundle\Util\Filesystem;
use Doctrine\Common\Cli\Configuration;
use Doctrine\Common\Cli\CliController as DoctrineCliController;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* Manage the cache clearing of the Doctrine ORM.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class ClearCacheDoctrineCommand extends DoctrineCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('doctrine:clear-cache')
->setDescription('Clear cache from configured query, result and metadata drivers.')
->setAliases(array('doctrine:cc'))
->addOption('query', null, null, 'Clear the query cache.')
->addOption('metadata', null, null, 'Clear the metadata cache.')
->addOption('result', null, null, 'Clear the result cache.')
->addOption('id', null, null, 'Clear a cache entry by its id.')
->addOption('regex', null, null, 'Clear cache entries that match a regular expression.')
->addOption('prefix', null, null, 'Clear cache entries that match a prefix.')
->addOption('suffix', null, null, 'Clear cache entries that match a suffix.')
;
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$options = $this->buildDoctrineCliTaskOptions($input, array(
'query', 'metadata', 'result', 'id', 'regex', 'prefix', 'suffix'
));
$this->runDoctrineCliTask('orm:clear-cache', $options);
}
}
@@ -0,0 +1,58 @@
<?php

namespace Symfony\Framework\DoctrineBundle\Command;

use Symfony\Components\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output;
use Symfony\Framework\WebBundle\Util\Filesystem;
use Doctrine\Common\Cli\Configuration;
use Doctrine\Common\Cli\CliController as DoctrineCliController;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* Convert Doctrine ORM metadata mapping information between the various supported
* formats.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class ConvertMappingDoctrineCommand extends DoctrineCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('doctrine:convert-mapping')
->setDescription('Convert mapping information between supported formats.')
->addOption('from', null, null, 'The source to convert from.')
->addOption('to', null, null, 'The type of mapping to convert to.')
->addOption('dest', null, null, 'Where to output the converted source.')
;
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$options = $this->buildDoctrineCliTaskOptions($input, array(
'from', 'to', 'dest'
));
$this->runDoctrineCliTask('orm:convert-mapping', $options);
}
}
47 changes: 45 additions & 2 deletions src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php
Expand Up @@ -10,6 +10,7 @@
use Symfony\Components\Console\Output\Output;
use Symfony\Framework\WebBundle\Util\Filesystem;
use Doctrine\Common\Cli\Configuration;
use Doctrine\Common\Cli\CliController as DoctrineCliController;

/*
* This file is part of the symfony framework.
Expand All @@ -21,12 +22,54 @@
*/

/**
*
* Base class for Doctrine consol commands to extend from.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class DoctrineCommand extends Command
{
}
protected $cli;

protected function getDoctrineCli()
{
if ($this->cli === null)
{
$configuration = new Configuration();
$configuration->setAttribute('em', $this->container->getDoctrine_Orm_EntityManagerService());
$this->cli = new DoctrineCliController($configuration);
}
return $this->cli;
}

protected function runDoctrineCliTask($name, $options = array())
{
$builtOptions = array();
foreach ($options as $key => $value)
{
if ($value === null)
{
$builtOptions[] = sprintf('--%s', $key);
}
else
{
$builtOptions[] = sprintf('--%s=%s', $key, $value);
}
}
return $this->getDoctrineCli()->run(array_merge(array('doctrine', $name), $builtOptions));
}

public function buildDoctrineCliTaskOptions(InputInterface $input, array $options)
{
$taskOptions = array();
foreach ($options as $option)
{
if ($value = $input->getOption($option))
{
$options[$option] = $value;
}
}
return $options;
}
}
@@ -0,0 +1,51 @@
<?php

namespace Symfony\Framework\DoctrineBundle\Command;

use Symfony\Components\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption;
use Symfony\Components\Console\Input\InputInterface;
use Symfony\Components\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output;
use Symfony\Framework\WebBundle\Util\Filesystem;
use Doctrine\Common\Cli\Configuration;
use Doctrine\Common\Cli\CliController as DoctrineCliController;

/*
* This file is part of the symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* Ensure the Doctrine ORM is configured properly for a production environment.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class EnsureProductionSettingsDoctrineCommand extends DoctrineCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('doctrine:ensure-production-settings')
->setDescription('Verify that Doctrine is properly configured for a production environment.')
;
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->runDoctrineCliTask('orm:ensure-production-settings');
}
}
Expand Up @@ -8,8 +8,6 @@
use Symfony\Components\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\Output;
use Symfony\Framework\WebBundle\Util\Filesystem;
use Doctrine\Common\Cli\Configuration;
use Doctrine\Common\Cli\CliController as DoctrineCliController;

/*
* This file is part of the symfony framework.
Expand All @@ -21,7 +19,7 @@
*/

/**
*
* Generate the Doctrine ORM entity proxies to your cache directory.
*
* @package symfony
* @subpackage console
Expand All @@ -36,6 +34,7 @@ protected function configure()
{
$this
->setName('doctrine:generate-proxies')
->setDescription('Generates proxy classes for entity classes.')
;
}

Expand All @@ -44,9 +43,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configuration = new Configuration();
$configuration->setAttribute('em', $this->container->getDoctrine_Orm_ManagerService());

$dirs = array();
$bundleDirs = $this->container->getKernelService()->getBundleDirs();
foreach ($this->container->getKernelService()->getBundles() as $bundle)
Expand All @@ -55,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$namespace = dirname($tmp);
$class = basename($tmp);

if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Model/Doctrine'))
if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities'))
{
$dirs[] = $dir;
}
Expand All @@ -66,10 +62,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
mkdir($dir, 0777, true);
}

$cli = new DoctrineCliController($configuration);
foreach ($dirs as $dir)
{
$cli->run(array('doctrine', 'orm:generate-proxies', '--class-dir='.$dir));
$this->runDoctrineCliTask('orm:generate-proxies', array('class-dir' => $dir));
}
}
}
}

0 comments on commit f87f890

Please sign in to comment.