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);
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * @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')));
     }
 }
Пример #3
0
 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>');
     }
 }
Пример #4
0
 /**
  * @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());
     }
 }
 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()));
     }
 }
 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();
 }
Пример #7
0
 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();
 }
Пример #8
0
 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;
 }
Пример #9
0
  protected function execute(InputInterface $input, OutputInterface $output)
  {
    $this->input = $input;
    $this->output = $output;

    $output->writeln('called');
  }
 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');
     }
 }
 /**
  * @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');
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $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 (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) {
                     $output->writeln(sprintf('  > generating <comment>%s</comment>', $metadata->name));
                     $entityGenerator->generate(array($metadata), $destination);
                 }
             }
         }
     }
 }
Пример #13
0
 /**
  * @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()}");
     }
 }
Пример #14
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $playerRepository = new PlayerRepository($em);
     $pitchers = $playerRepository->getAllPitchers();
     $count = 0;
     $stats = array();
     foreach ($pitchers as $pitcher) {
         $output->writeln($pitcher);
         $matchups = $pitcher->getPitchingMatchupsAsPitcher();
         $runsAllowed = 0;
         $totalMatchups = 0;
         foreach ($matchups as $matchup) {
             $runsAllowed += $matchup->getRunsScored();
             //$output->writeln($matchup);
             $totalMatchups++;
         }
         $output->writeln('Total Matchups: ' . $totalMatchups);
         $output->writeln('Runs allowed: ' . $runsAllowed);
     }
 }
Пример #15
0
 /**
  * @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;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $generator = new EntityRepositoryGenerator();
     $kernel = $this->application->getKernel();
     $bundleDirs = $kernel->getBundleDirs();
     foreach ($kernel->getBundles() as $bundle) {
         $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
         $namespace = str_replace('/', '\\', dirname($tmp));
         $class = basename($tmp);
         if (isset($bundleDirs[$namespace])) {
             $destination = realpath($bundleDirs[$namespace] . '/..');
             if ($metadatas = $this->getBundleMetadatas($bundle)) {
                 $output->writeln(sprintf('Generating entity repositories for "<info>%s</info>"', $class));
                 foreach ($metadatas as $metadata) {
                     if ($metadata->customRepositoryClassName) {
                         $output->writeln(sprintf('  > generating <comment>%s</comment>', $metadata->customRepositoryClassName));
                         $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destination);
                     }
                 }
             }
         }
     }
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $this->buildDoctrineCliTaskOptions($input, array('create', 'drop', 'update', 'complete-update', 're-create', 'dump-sql'));
     $entityDirs = $this->container->getParameter('doctrine.orm.entity_dirs');
     $options['class-dir'] = implode(', ', $entityDirs);
     $found = false;
     $ems = $this->getDoctrineEntityManagers();
     foreach ($ems as $name => $em) {
         if ($input->getOption('connection') && $name !== $input->getOption('connection')) {
             continue;
         }
         $this->em = $em;
         $this->runDoctrineCliTask('orm:schema-tool', $options);
         $found = true;
     }
     if ($found === false) {
         if ($input->getOption('connection')) {
             $output->writeln(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $input->getOption('connection')));
         } else {
             $output->writeln(sprintf('<error>Could not find any configured connections</error>', $input->getOption('connection')));
         }
     }
 }
Пример #18
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $this->gameDir = $this->container['lichess.persistence.dir'];
     $this->socketDir = $this->container['kernel.root_dir'] . '/cache/socket';
     $nbGames = $this->getNbGames();
     $nbSockets = $this->getNbSockets();
     $maxNbGames = $this->getMaxNbGames();
     $output->writeln(sprintf('%s sockets, %d games, %d max.', $nbSockets, $nbGames, $maxNbGames));
     if ($nbGames <= $maxNbGames) {
         $output->writeln('Exit.');
         return;
     }
     $nbOldGames = $nbGames - $maxNbGames;
     $output->writeln(sprintf('Will remove %d games.', $nbOldGames));
     $gameHashes = $this->runCommand(sprintf('ls -tu %s | tail -%d', $this->gameDir, $nbOldGames));
     foreach ($gameHashes as $gameHash) {
         $this->deleteGame($gameHash);
     }
     $output->writeln('Done');
     $nbGames = $this->getNbGames();
     $nbSockets = $this->getNbSockets();
     $output->writeln(sprintf('%s sockets, %d games.', $nbSockets, $nbGames));
 }
Пример #19
0
 /**
  * @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);
     }
 }
Пример #20
0
 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();
 }
Пример #21
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!is_dir($input->getArgument('target'))) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $filesystem = new Filesystem();
     foreach ($this->container->getKernelService()->getBundles() as $bundle) {
         if (is_dir($originDir = $bundle->getPath() . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($bundle->getName()));
             $filesystem->remove($targetDir);
             mkdir($targetDir, 0777, true);
             $filesystem->mirror($originDir, $targetDir);
         }
     }
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $error = false;
     try {
         $em->getConfiguration()->ensureProductionSettings();
         if ($input->getOption('complete') !== null) {
             $em->getConnection()->connect();
         }
     } catch (\Exception $e) {
         $error = true;
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
     if ($error === false) {
         $output->write('<info>Environment is correctly configured for production.</info>' . PHP_EOL);
     }
 }
Пример #23
0
 /**
  * Asks for a value and validates the response.
  *
  * @param OutputInterface $output
  * @param string|array    $question
  * @param Closure         $validator
  * @param integer         $attempts Max number of times to ask before giving up (false by default, which means infinite)
  *
  * @return mixed
  *
  * @throws \Exception When any of the validator returns an error
  */
 public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
 {
     // @codeCoverageIgnoreStart
     $error = null;
     while (false === $attempts || $attempts--) {
         if (null !== $error) {
             $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
         }
         $value = $this->ask($output, $question, null);
         try {
             return $validator($value);
         } catch (\Exception $error) {
         }
     }
     throw $error;
     // @codeCoverageIgnoreEnd
 }
Пример #24
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->callPhing('sql', array('propel.packageObjectModel' => false));
     $filesystem = new Filesystem();
     $basePath = $this->application->getKernel()->getRootDir() . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql';
     $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
     foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
         $sqlFile = str_replace('.xml', '.sql', $schemaFile);
         $targetSqlFile = $schemaDetails['bundle'] . '-' . str_replace('.xml', '.sql', $schemaDetails['basename']);
         $targetSqlFilePath = $basePath . DIRECTORY_SEPARATOR . $targetSqlFile;
         $sqlMap = str_replace($sqlFile, $targetSqlFile, $sqlMap);
         $filesystem->remove($targetSqlFilePath);
         $filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath);
         $output->writeln(sprintf('Wrote SQL file for bundle "<info>%s</info>" in "<info>%s</info>"', $schemaDetails['bundle'], $targetSqlFilePath));
     }
     file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
 }
Пример #25
0
 /**
  * @throws \InvalidArgumentException When route does not exist
  */
 protected function outputRoute(OutputInterface $output, $routes, $name)
 {
     $output->writeln($this->getHelper('formatter')->formatSection('router', sprintf('Route "%s"', $name)));
     if (!isset($routes[$name])) {
         throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
     }
     $route = $routes[$name];
     $output->writeln(sprintf('<comment>Name</comment>         %s', $name));
     $output->writeln(sprintf('<comment>Pattern</comment>      %s', $route->getPattern()));
     $output->writeln(sprintf('<comment>Class</comment>        %s', get_class($route)));
     $defaults = '';
     $d = $route->getDefaults();
     ksort($d);
     foreach ($d as $name => $value) {
         $defaults .= ($defaults ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Defaults</comment>     %s', $defaults));
     $requirements = '';
     $r = $route->getRequirements();
     ksort($r);
     foreach ($r as $name => $value) {
         $requirements .= ($requirements ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Requirements</comment> %s', $requirements));
     $options = '';
     $o = $route->getOptions();
     ksort($o);
     foreach ($o as $name => $value) {
         $options .= ($options ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Options</comment>      %s', $options));
     $output->write('<comment>Regex</comment>        ');
     $output->writeln(preg_replace('/^             /', '', preg_replace('/^/m', '             ', $route->getRegex())), Output::OUTPUT_RAW);
     $tokens = '';
     foreach ($route->getTokens() as $token) {
         if (!$tokens) {
             $tokens = $this->displayToken($token);
         } else {
             $tokens .= "\n" . str_repeat(' ', 13) . $this->displayToken($token);
         }
     }
     $output->writeln(sprintf('<comment>Tokens</comment>       %s', $tokens));
 }
Пример #26
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $count = 0;
     if (($handle = fopen(DATADIR . "/people/people.txt", "r")) !== FALSE) {
         while (($data = fgetcsv($handle)) !== FALSE) {
             $type = substr($data[2], 5, 1);
             switch ($type) {
                 case 0:
                 case 1:
                     // This is a player
                     $player = new Player($data[2]);
                     $player->setName($data[1], $data[0]);
                     $em->persist($player);
                     //$output->writeln($player);
                     break;
                 case 8:
                     // Managers and coaches
                     $coach = new Coach($data[2]);
                     $coach->setName($data[1], $data[0]);
                     $em->persist($coach);
                     break;
                 case 9:
                     // Umpires
                     $umpire = new Umpire($data[2]);
                     $umpire->setName($data[1], $data[0]);
                     $em->persist($umpire);
                     break;
                 default:
                     throw new \Exception('Unknown type of person record');
             }
             if ($count % 500 == 0) {
                 $em->flush();
                 $em->clear();
                 $output->writeln("flusing {$count}");
             }
             $count++;
         }
     }
     fclose($handle);
     $em->flush();
 }
Пример #27
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!is_dir($input->getArgument('target'))) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $filesystem = new Filesystem();
     $dirs = $this->container->getKernelService()->getBundleDirs();
     foreach ($this->container->getKernelService()->getBundles() as $bundle) {
         $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
         $namespace = dirname($tmp);
         $class = basename($tmp);
         if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace] . '/' . $class . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($class));
             $filesystem->remove($targetDir);
             mkdir($targetDir, 0755, true);
             $filesystem->mirror($originDir, $targetDir);
         }
     }
 }
Пример #28
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!preg_match('/Bundle$/', $namespace = $input->getArgument('namespace'))) {
         throw new \InvalidArgumentException('The namespace must end with Bundle.');
     }
     $dirs = $this->container->getKernelService()->getBundleDirs();
     $tmp = str_replace('\\', '/', $namespace);
     $namespace = str_replace('/', '\\', dirname($tmp));
     $bundle = basename($tmp);
     if (!isset($dirs[$namespace])) {
         throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle (%s not defined).', $namespace));
     }
     $dir = $dirs[$namespace];
     $output->writeln(sprintf('Initializing bundle "<info>%s</info>" in "<info>%s</info>"', $bundle, realpath($dir)));
     if (file_exists($targetDir = $dir . '/' . $bundle)) {
         throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
     }
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/bundle', $targetDir);
     Mustache::renderDir($targetDir, array('namespace' => $namespace, 'bundle' => $bundle));
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $defaultEm = $this->container->getDoctrine_ORM_EntityManagerService();
     $dirOrFile = $input->getOption('dir-or-file');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         $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 (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Resources/data/fixtures/doctrine')) {
                 $paths[] = $dir;
             }
         }
     }
     $files = array();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $found = Finder::type('file')->name('*.php')->in($path);
         } else {
             $found = array($path);
         }
         $files = array_merge($files, $found);
     }
     $ems = array();
     $emEntities = array();
     $files = array_unique($files);
     foreach ($files as $file) {
         $em = $defaultEm;
         $output->writeln(sprintf('<info>Loading data fixtures from <comment>"%s"</comment></info>', $file));
         $before = array_keys(get_defined_vars());
         include $file;
         $after = array_keys(get_defined_vars());
         $new = array_diff($after, $before);
         $params = $em->getConnection()->getParams();
         $emName = isset($params['path']) ? $params['path'] : $params['dbname'];
         $ems[$emName] = $em;
         $emEntities[$emName] = array();
         $variables = array_values($new);
         foreach ($variables as $variable) {
             $value = ${$variable};
             if (!is_object($value) || $value instanceof \Doctrine\ORM\EntityManager) {
                 continue;
             }
             $emEntities[$emName][] = $value;
         }
         foreach ($ems as $emName => $em) {
             if (!$input->getOption('append')) {
                 $output->writeln(sprintf('<info>Purging data from entity manager named <comment>"%s"</comment></info>', $emName));
                 $this->purgeEntityManager($em);
             }
             $entities = $emEntities[$emName];
             $numEntities = count($entities);
             $output->writeln(sprintf('<info>Persisting "%s" ' . ($numEntities > 1 ? 'entities' : 'entity') . '</info>', count($entities)));
             foreach ($entities as $entity) {
                 $output->writeln(sprintf('<info>Persisting "%s" entity:</info>', get_class($entity)));
                 $output->writeln('');
                 $output->writeln(var_dump($entity));
                 $em->persist($entity);
             }
             $output->writeln('<info>Flushing entity manager</info>');
             $em->flush();
         }
     }
 }
Пример #30
0
 /**
  * Renders a catched exception.
  *
  * @param Exception       $e      An exception instance
  * @param OutputInterface $output An OutputInterface instance
  */
 public function renderException($e, $output)
 {
     $strlen = function ($string) {
         return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
     };
     $title = sprintf('  [%s]  ', get_class($e));
     $len = $strlen($title);
     $lines = array();
     foreach (explode("\n", $e->getMessage()) as $line) {
         $lines[] = sprintf('  %s  ', $line);
         $len = max($strlen($line) + 4, $len);
     }
     $messages = array(str_repeat(' ', $len), $title . str_repeat(' ', $len - $strlen($title)));
     foreach ($lines as $line) {
         $messages[] = $line . str_repeat(' ', $len - $strlen($line));
     }
     $messages[] = str_repeat(' ', $len);
     $output->writeln("\n");
     foreach ($messages as $message) {
         $output->writeln("<error>{$message}</error>");
     }
     $output->writeln("\n");
     if (null !== $this->runningCommand) {
         $output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
         $output->writeln("\n");
     }
     if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
         $output->writeln('</comment>Exception trace:</comment>');
         // exception related properties
         $trace = $e->getTrace();
         array_unshift($trace, array('function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array()));
         for ($i = 0, $count = count($trace); $i < $count; $i++) {
             $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
             $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
             $function = $trace[$i]['function'];
             $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
             $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
             $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
         }
         $output->writeln("\n");
     }
 }