作者: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;
}
作者:KernelMadnes
项目:ContainerKi
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$selector = $input->getArgument('selector');
if (!$selector) {
$containers = $this->application->getController()->getContainers();
} else {
$containers = $this->application->getController()->selectContainers($selector);
}
$l = Formatter::calculateNamelength($containers) + 1;
$FORMAT = "%{$l}s %s\n";
printf($FORMAT, 'Name', 'Tags');
array_walk($containers, function (&$container, $key) use($FORMAT) {
$tags = $container->getTags();
if (empty($tags)) {
vprintf($FORMAT, array($container->getName(), '<none>'));
}
foreach ($tags as $key => $tag) {
if ($key === 0) {
vprintf($FORMAT, array($container->getName(), $tag));
} else {
vprintf($FORMAT, array('', $tag));
}
}
});
}
作者: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
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);
}
}
作者: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);
}
}
作者:KernelMadnes
项目:ContainerKi
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$selector = $input->getArgument('selector');
$this->application->getController()->restart($selector, function ($message) {
echo \Console_Color::convert(" %g>>%n ") . $message . "\n";
});
}
作者:jacques-sounv
项目:addressboo
public function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em'));
$configuration = $this->_getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrationsForBundle($this->application, $input->getOption('bundle'), $configuration);
parent::execute($input, $output);
}
作者:jacques-sounv
项目:addressboo
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$cacheDriver = $em->getConfiguration()->getResultCacheImpl();
if (!$cacheDriver) {
throw new \InvalidArgumentException('No Result cache driver is configured on given EntityManager.');
}
$outputed = false;
// Removing based on --id
if (($ids = $input->getOption('id')) !== null && $ids) {
foreach ($ids as $id) {
$output->write($outputed ? PHP_EOL : '');
$output->write(sprintf('Clearing Result cache entries that match the id "<info>%s</info>"', $id) . PHP_EOL);
$deleted = $cacheDriver->delete($id);
if (is_array($deleted)) {
$this->_printDeleted($output, $deleted);
} else {
if (is_bool($deleted) && $deleted) {
$this->_printDeleted($output, array($id));
}
}
$outputed = true;
}
}
// Removing based on --regex
if (($regexps = $input->getOption('regex')) !== null && $regexps) {
foreach ($regexps as $regex) {
$output->write($outputed ? PHP_EOL : '');
$output->write(sprintf('Clearing Result cache entries that match the regular expression "<info>%s</info>"', $regex) . PHP_EOL);
$this->_printDeleted($output, $cacheDriver->deleteByRegex('/' . $regex . '/'));
$outputed = true;
}
}
// Removing based on --prefix
if (($prefixes = $input->getOption('prefix')) !== null & $prefixes) {
foreach ($prefixes as $prefix) {
$output->write($outputed ? PHP_EOL : '');
$output->write(sprintf('Clearing Result cache entries that have the prefix "<info>%s</info>"', $prefix) . PHP_EOL);
$this->_printDeleted($output, $cacheDriver->deleteByPrefix($prefix));
$outputed = true;
}
}
// Removing based on --suffix
if (($suffixes = $input->getOption('suffix')) !== null && $suffixes) {
foreach ($suffixes as $suffix) {
$output->write($outputed ? PHP_EOL : '');
$output->write(sprintf('Clearing Result cache entries that have the suffix "<info>%s</info>"', $suffix) . PHP_EOL);
$this->_printDeleted($output, $cacheDriver->deleteBySuffix($suffix));
$outputed = true;
}
}
// Removing ALL entries
if (!$ids && !$regexps && !$prefixes && !$suffixes) {
$output->write($outputed ? PHP_EOL : '');
$output->write('Clearing ALL Result cache entries' . PHP_EOL);
$this->_printDeleted($output, $cacheDriver->deleteAll());
$outputed = true;
}
}
作者:avalanche12
项目:ServerBundl
/**
* @see Command
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->container = $this->application->getKernel()->getContainer();
$this->server = $this->container->getServerService();
if (!$input->getOption('verbose')) {
$this->server->setConsole(new Console($output));
}
}
作者: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')));
}
}
作者:pgode
项目:PageRolle
/**
* Runs the current application.
*
* @param InputInterface $input An Input instance
* @param OutputInterface $output An Output instance
*
* @return integer 0 if everything went fine, or an error code
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
if (true === $input->hasParameterOption(array('--shell', '-s'))) {
$shell = new Shell($this);
$shell->run();
return 0;
}
return parent::doRun($input, $output);
}
作者:KernelMadnes
项目:ContainerKi
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$selector = $input->getArgument('selector');
$tag = $input->getArgument('tag');
$containers = $this->application->getController()->selectContainers($selector);
array_walk($containers, function (&$container, $key, $tag) {
$container->addTag($tag);
}, $tag);
}
作者:KernelMadnes
项目:ContainerKi
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$ip = $input->getArgument('ip');
$container = $this->application->getController()->getContainer($name);
if (!$container) {
throw new \Exception('Container does not exists!');
}
$container->addAllowedIp($ip);
}
作者:khalid0
项目:symfon
/**
* @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!preg_match('/Bundle$/', $bundle = $input->getArgument('bundle'))) {
throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\\MySampleBundle".');
}
$dirs = $this->container->getKernelService()->getBundleDirs();
$tmp = str_replace('\\', '/', $bundle);
$namespace = str_replace('/', '\\', dirname($tmp));
$bundle = basename($tmp);
if (!isset($dirs[$namespace])) {
throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace));
}
$entity = $input->getArgument('entity');
$entityNamespace = $namespace . '\\' . $bundle . '\\Entities';
$fullEntityClassName = $entityNamespace . '\\' . $entity;
$tmp = str_replace('\\', '/', $fullEntityClassName);
$tmp = str_replace('/', '\\', dirname($tmp));
$className = basename($tmp);
$mappingType = $input->getOption('mapping-type');
$mappingType = $mappingType ? $mappingType : 'xml';
$class = new ClassMetadataInfo($fullEntityClassName);
$class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
// Map the specified fields
$fields = $input->getOption('fields');
if ($fields) {
$e = explode(' ', $fields);
foreach ($e as $value) {
$e = explode(':', $value);
$name = $e[0];
$type = isset($e[1]) ? $e[1] : 'string';
preg_match_all('/(.*)\\((.*)\\)/', $type, $matches);
$type = isset($matches[1][0]) ? $matches[1][0] : 'string';
$length = isset($matches[2][0]) ? $matches[2][0] : null;
$class->mapField(array('fieldName' => $name, 'type' => $type, 'length' => $length));
}
}
// Setup a new exporter for the mapping type specified
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($mappingType);
if ($mappingType === 'annotation') {
$path = $dirs[$namespace] . '/' . $bundle . '/Entities/' . str_replace($entityNamespace . '\\', null, $fullEntityClassName) . '.php';
$exporter->setEntityGenerator($this->getEntityGenerator());
} else {
$mappingType = $mappingType == 'yaml' ? 'yml' : $mappingType;
$path = $dirs[$namespace] . '/' . $bundle . '/Resources/config/doctrine/metadata/' . str_replace('\\', '.', $fullEntityClassName) . '.dcm.' . $mappingType;
}
$code = $exporter->exportClassMetadata($class);
if (!is_dir($dir = dirname($path))) {
mkdir($dir, 0777, true);
}
$output->writeln(sprintf('Generating entity for "<info>%s</info>"', $bundle));
$output->writeln(sprintf(' > generating <comment>%s</comment>', $fullEntityClassName));
file_put_contents($path, $code);
}
作者: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);
}
}
作者: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()}");
}
}
作者: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());
}
}
作者: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;
}
作者:avalanche12
项目:ServerBundl
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/**
* @TODO implement mongrel_rails like runtime configuration
* @link http://github.com/fauna/mongrel/blob/master/bin/mongrel_rails#L22
*
* Sequence
* 1) runtime configuration [-defaults]
* 2) config.yml
* 3) server.xml
*/
$this->server->start($input->getOption('daemonize'));
}