Created
June 24, 2014 16:45
-
-
Save eftakhairul/b0cd8e0d5b74895edfa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Tools\Console\Commands; | |
use Symfony\Component\Console\Input\InputArgument, | |
Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Command\Command; | |
/** | |
* Add into all XML Map a Repository Class with name {NameClass}.'Repository' | |
* | |
* @param map-path directory where there are Generated Map XML | |
* @author Gianluca Arbezzano {gianarb92@gmail.com} | |
*/ | |
class AddRepositoryClassXML | |
extends Command | |
{ | |
/** | |
* | |
*/ | |
protected function configure() | |
{ | |
$this->setName('orm:add-repositoryclass-xml') | |
->setDescription('Add repository Class into all XML Map.') | |
->setDefinition(array( | |
new InputArgument( | |
'map-path', InputArgument::REQUIRED, | |
'The path into have create xmp map.' | |
) | |
)) | |
->setHelp(<<<EOT | |
Add into all XML Map the Repository Class, if namespace class is | |
Application\Entity\Location\Airports it create | |
repository-class="Application\Entity\Location\AirportsRepository" | |
EOT | |
); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) { | |
$listFile = scandir($input->getArgument('map-path')); | |
foreach($listFile as $fileName){ | |
if(strstr($fileName, ".xml")){ | |
$listXmlFile[]= $fileName; | |
} | |
}; | |
if($listXmlFile){ | |
foreach($listXmlFile as $fileXmlName){ | |
$xml = simplexml_load_file($input->getArgument('map-path').DIRECTORY_SEPARATOR.$fileXmlName); | |
$rep = $name = $xml->children()->entity['repository-class'] = $xml->children()->entity['name']."Repository"; | |
$output = $xml->asXML(); | |
$f = fopen($input->getArgument('map-path').DIRECTORY_SEPARATOR.$fileXmlName, 'w'); | |
fwrite($f, $output); | |
fclose($f); | |
} | |
} | |
echo 'Repository Class add into all XML Maps'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//configuration file /doctrine.php | |
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; | |
use Doctrine\DBAL\Tools\Console\Helper\EntityManagerHelper; | |
use Doctrine\ORM\Tools\Console\ConsoleRunner; | |
//use Symfony\Component\Console\Helper\HelperSet; | |
use Symfony\Component\Console\Application; | |
use Doctrine\ORM\Configuration; | |
require_once 'Doctrine/Common/ClassLoader.php'; | |
define('APPLICATION_ENV', "development"); | |
error_reporting(E_ALL); | |
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); | |
$classLoader->register(); | |
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__ . '/library/Entity'); | |
$classLoader->register(); | |
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__ . '/application/persistent'); | |
$classLoader->register(); | |
$config = new Configuration(); | |
$config->setProxyDir(__DIR__ . '/application/persistent/Proxies'); | |
$config->setProxyNamespace('Proxies'); | |
$driverImpl = new \Doctrine\ORM\Mapping\Driver\XmlDriver('generated'); | |
$config->setMetadataDriverImpl($driverImpl); | |
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == "development")); | |
$connectionOptions = array( | |
'driver' => 'pdo_mysql', | |
'host' => 'localhost', | |
'dbname' => 'test', | |
'user' => 'root', | |
'password' => '' | |
); | |
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); | |
$helperSet = new Symfony\Component\Console\Helper\HelperSet(array( | |
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), | |
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) | |
)); | |
ConsoleRunner::run($helperSet); | |
$cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION); | |
$cli->setCatchExceptions(true); | |
$cli->setHelperSet($helperSet); | |
ConsoleRunner::addCommands($cli); | |
$cli->addCommand(new \Application\Tools\Console\Commands\AddRepositoryClassXML); | |
$cli->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment