作者:pouliko
项目:readlate
protected function _getMigrationConfiguration(InputInterface $input, OutputInterface $output)
{
if (!$this->_configuration) {
$outputWriter = new OutputWriter(function ($message) use($output) {
return $output->writeln($message);
});
$em = $this->getHelper('em')->getEntityManager();
if ($input->getOption('configuration')) {
$info = pathinfo($input->getOption('configuration'));
$class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration';
$configuration = new $class($em->getConnection(), $outputWriter);
$configuration->load($input->getOption('configuration'));
} else {
if (file_exists('migrations.xml')) {
$configuration = new XmlConfiguration($em->getConnection(), $outputWriter);
$configuration->load('migrations.xml');
} else {
if (file_exists('migrations.yml')) {
$configuration = new YamlConfiguration($em->getConnection(), $outputWriter);
$configuration->load('migrations.yml');
} else {
$configuration = new Configuration($em->getConnection(), $outputWriter);
}
}
}
$this->_configuration = $configuration;
}
return $this->_configuration;
}
作者:jsugg
项目:BBM_ol
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
// Delete first
$query = $em->createQuery('delete from BBM\\Play');
$query->execute();
$query = $em->createQuery('delete from BBM\\Game');
$query->execute();
$count = 0;
$gameFactory = new GameFactory($em);
$currec = array();
if (($handle = fopen(DATADIR . "/game_events/2008ATL.EVN", "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
if ($data[0] === 'id' && sizeof($currec) !== 0) {
$game = $gameFactory->createGameFromRetrosheetRecords($currec);
$em->persist($game);
if ($count % 10 == 0) {
$em->flush();
$em->clear();
}
$output->writeln($game);
unset($currec);
$count++;
}
$currec[] = $data;
}
}
fclose($handle);
$em->flush();
}
作者:nicolasmarti
项目:symfon
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$output->writeln('called');
}
作者:khalid0
项目:symfon
protected function execute(InputInterface $input, OutputInterface $output)
{
$filterBundle = $input->getOption('bundle') ? str_replace('/', '\\', $input->getOption('bundle')) : false;
$filterEntity = $filterBundle ? $filterBundle . '\\Entities\\' . str_replace('/', '\\', $input->getOption('entity')) : false;
if (!isset($filterBundle) && isset($filterEntity)) {
throw new \InvalidArgumentException(sprintf('Unable to specify an entity without also specifying a bundle.'));
}
$entityGenerator = $this->getEntityGenerator();
$bundleDirs = $this->container->getKernelService()->getBundleDirs();
foreach ($this->container->getKernelService()->getBundles() as $bundle) {
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
$namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($tmp);
if ($filterBundle && $filterBundle != $namespace . '\\' . $class) {
continue;
}
if (isset($bundleDirs[$namespace])) {
$destination = realpath($bundleDirs[$namespace] . '/..');
if ($metadatas = $this->getBundleMetadatas($bundle)) {
$output->writeln(sprintf('Generating entities for "<info>%s</info>"', $class));
foreach ($metadatas as $metadata) {
if ($filterEntity && strpos($metadata->name, $filterEntity) !== 0) {
continue;
}
$output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name));
$entityGenerator->generate(array($metadata), $destination);
}
}
}
}
}
作者:jacques-sounv
项目:addressboo
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
$destPath = realpath($input->getArgument('dest-path'));
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
if (count($metadatas)) {
$numRepositories = 0;
$generator = new EntityRepositoryGenerator();
foreach ($metadatas as $metadata) {
if ($metadata->customRepositoryClassName) {
$output->write(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL);
$generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath);
$numRepositories++;
}
}
if ($numRepositories) {
// Outputting information message
$output->write(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Repository classes were found to be processed.' . PHP_EOL);
}
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
作者:jacques-sounv
项目:addressboo
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
if (($destPath = $input->getArgument('dest-path')) === null) {
$destPath = $em->getConfiguration()->getProxyDir();
}
if (!is_dir($destPath)) {
mkdir($destPath, 0777, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
}
// Generating Proxies
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
// Outputting information message
$output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
作者:skoo
项目:symfony-sandbo
protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
{
try {
$output->writeln('<info>' . $this->runIndexUpdates($input->getOption('mode'), $input->getOption('class')) . '</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
}
}
作者:skoo
项目:symfony-sandbo
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('xml')) {
$output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
} else {
$output->writeln($this->application->asText($input->getArgument('namespace')));
}
}
作者:jaros
项目:symfon
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundleClass = null;
$bundleDirs = $this->container->getKernelService()->getBundleDirs();
foreach ($this->container->getKernelService()->getBundles() as $bundle) {
if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) {
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
$namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($tmp);
if (isset($bundleDirs[$namespace])) {
$destPath = realpath($bundleDirs[$namespace]) . '/' . $class;
$bundleClass = $class;
break;
}
}
}
$type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
if ($type === 'annotation') {
$destPath .= '/Entities';
} else {
$destPath .= '/Resources/config/doctrine/metadata';
}
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
if ($type === 'annotation') {
$entityGenerator = $this->getEntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$emName = $input->getOption('em') ? $input->getOption('em') : 'default';
$emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
$em = $this->container->getService($emServiceName);
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
$cmf = new DisconnectedClassMetadataFactory($em);
$metadata = $cmf->getAllMetadata();
if ($metadata) {
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
$filesystem = new Filesystem();
foreach ($metadata as $class) {
$className = $class->name;
$class->name = $namespace . '\\' . $bundleClass . '\\Entities\\' . $className;
if ($type === 'annotation') {
$path = $destPath . '/' . $className . '.php';
} else {
$path = $destPath . '/' . str_replace('\\', '.', $class->name) . '.dcm.xml';
}
$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
$code = $exporter->exportClassMetadata($class);
if (!is_dir($dir = dirname($path))) {
$filesystem->mkdirs($dir);
}
file_put_contents($path, $code);
}
} else {
$output->writeln('Database does not have any mapping information.' . PHP_EOL, 'ERROR');
}
}
作者:khalid0
项目:symfon
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundleClass = null;
$bundleDirs = $this->container->getKernelService()->getBundleDirs();
foreach ($this->container->getKernelService()->getBundles() as $bundle) {
if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) {
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
$namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($tmp);
if (isset($bundleDirs[$namespace])) {
$destPath = realpath($bundleDirs[$namespace]) . '/' . $class;
$bundleClass = $class;
break;
}
}
}
$type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
if ($type === 'annotation') {
$destPath .= '/Entities';
} else {
$destPath .= '/Resources/config/doctrine/metadata';
}
// adjust so file naming works
if ($type === 'yaml') {
$type = 'yml';
}
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
if ($type === 'annotation') {
$entityGenerator = $this->getEntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$converter = new ConvertDoctrine1Schema($input->getArgument('d1-schema'));
$metadata = $converter->getMetadata();
if ($metadata) {
$output->writeln(sprintf('Converting Doctrine 1 schema "<info>%s</info>"', $input->getArgument('d1-schema')));
foreach ($metadata as $class) {
$className = $class->name;
$class->name = $namespace . '\\' . $bundleClass . '\\Entities\\' . $className;
if ($type === 'annotation') {
$path = $destPath . '/' . $className . '.php';
} else {
$path = $destPath . '/' . str_replace('\\', '.', $class->name) . '.dcm.' . $type;
}
$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
$code = $exporter->exportClassMetadata($class);
if (!is_dir($dir = dirname($path))) {
mkdir($dir, 0777, true);
}
file_put_contents($path, $code);
}
} else {
$output->writeln('Database does not have any mapping information.' . PHP_EOL, 'ERROR');
}
}
作者:pouliko
项目:readlate
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->command) {
$this->command = $this->application->getCommand($input->getArgument('command_name'));
}
if ($input->getOption('xml')) {
$output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
} else {
$output->writeln($this->command->asText());
}
}
作者:KernelMadnes
项目:ContainerKi
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$container = $this->application->getController()->getContainer($name);
if (!$container) {
$output->writeln("<error>Container {$name} does not exists</error>");
} else {
$editor = $this->application->getController()->getExecutable('editor');
\ContainerKit\Console\Launcher::launch("{$editor} {$container->getConfigPath()}");
}
}
作者:jacques-sounv
项目:addressboo
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
if ($input->getOption('dump-sql') === true) {
$sqls = $schemaTool->getDropSchemaSql($metadatas);
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
$output->write('Dropping database schema...' . PHP_EOL);
$schemaTool->dropSchema($metadatas);
$output->write('Database schema dropped successfully!' . PHP_EOL);
}
}
作者:pgode
项目:PageRolle
protected function dropDatabaseForConnection(Connection $connection, OutputInterface $output)
{
$params = $connection->getParams();
$name = isset($params['path']) ? $params['path'] : $params['dbname'];
try {
$connection->getSchemaManager()->dropDatabase($name);
$output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
作者:klaas
项目:symfony-sandbo
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return Configuration
*/
protected function _getMigrationConfiguration(InputInterface $input, OutputInterface $output)
{
if (!$this->_configuration) {
$outputWriter = new OutputWriter(function ($message) use($output) {
return $output->writeln($message);
});
if ($this->application->getHelperSet()->has('db')) {
$conn = $this->getHelper('db')->getConnection();
} else {
if ($input->getOption('db-configuration')) {
if (!file_exists($input->getOption('db-configuration'))) {
throw new \InvalidArgumentException("The specified connection file is a valid file.");
}
$params = (include $input->getOption('db-configuration'));
if (!is_array($params)) {
throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($params);
} else {
if (file_exists('migrations-db.php')) {
$params = (include "migrations-db.php");
if (!is_array($params)) {
throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($params);
} else {
throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.');
}
}
}
if ($input->getOption('configuration')) {
$info = pathinfo($input->getOption('configuration'));
$class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration';
$configuration = new $class($conn, $outputWriter);
$configuration->load($input->getOption('configuration'));
} else {
if (file_exists('migrations.xml')) {
$configuration = new XmlConfiguration($conn, $outputWriter);
$configuration->load('migrations.xml');
} else {
if (file_exists('migrations.yml')) {
$configuration = new YamlConfiguration($conn, $outputWriter);
$configuration->load('migrations.yml');
} else {
$configuration = new Configuration($conn, $outputWriter);
}
}
}
$this->_configuration = $configuration;
}
return $this->_configuration;
}
作者:jacques-sounv
项目:addressboo
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
// Defining if update is complete or not (--complete not defined means $saveMode = true)
$saveMode = $input->getOption('complete') === true;
if ($input->getOption('dump-sql') === true) {
$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
$output->write('Updating database schema...' . PHP_EOL);
$schemaTool->updateSchema($metadatas, $saveMode);
$output->write('Database schema updated successfully!' . PHP_EOL);
}
}
作者:kdambekaln
项目:framework-bench
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$kernel = $this->container->getKernelService();
$container = new Builder($kernel->getDefaultParameters());
$configuration = new BuilderConfiguration();
foreach ($kernel->getBundles() as $bundle) {
$configuration->merge($bundle->buildContainer($container));
}
$configuration->merge($kernel->registerContainerConfiguration());
$container->merge($configuration);
$kernel->optimizeContainer($container);
$container->setService('kernel', $kernel);
$dumper = new GraphvizDumper($container);
$output->write($dumper->dump(), Output::OUTPUT_RAW);
}
作者:bill9742
项目:symfon
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('sql')) {
$output->writeln('<info>Building model classes</info>');
$modelCommand = new BuildModelCommand();
$modelCommand->setApplication($this->application);
$modelCommand->execute($input, $output);
}
if (!$input->getOption('classes')) {
$output->writeln('<info>Building model sql</info>');
$sqlCommand = new BuildSQLCommand();
$sqlCommand->setApplication($this->application);
$sqlCommand->execute($input, $output);
}
}
作者:robo4
项目:symfon
protected function createDatabaseForConnection(Connection $connection, OutputInterface $output)
{
$params = $connection->getParams();
$name = isset($params['path']) ? $params['path'] : $params['dbname'];
unset($params['dbname']);
$tmpConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
try {
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
$tmpConnection->close();
}
作者:jsugg
项目:BBM_ol
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
if (($handle = fopen(DATADIR . "/teams/TEAMABR.TXT", "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
$team = new \BBM\Team($data[0]);
$team->setLeague($data[1]);
$team->setCity($data[2]);
$team->setNickname($data[3]);
$output->writeln($team);
$em->persist($team);
}
}
$em->flush();
}