本文整理汇总了PHP中Symfony\Components\Console\Output\OutputInterface::write方法的典型用法代码示例。如果您正苦于以下问题:PHP OutputInterface::write方法的具体用法?PHP OutputInterface::write怎么用?PHP OutputInterface::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Components\Console\Output\OutputInterface
的用法示例。
在下文中一共展示了OutputInterface::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @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);
}
}
示例2: execute
/**
* @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);
}
}
示例3: executeSchemaCommand
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);
}
}
示例4: executeSchemaCommand
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);
}
}
示例5: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$conn = $this->getHelper('db')->getConnection();
if (($fileNames = $input->getArgument('file')) !== null) {
foreach ((array) $fileNames as $fileName) {
$fileName = realpath($fileName);
if (!file_exists($fileName)) {
throw new \InvalidArgumentException(sprintf("SQL file '<info>%s</info>' does not exist.", $fileName));
} else {
if (!is_readable($fileName)) {
throw new \InvalidArgumentException(sprintf("SQL file '<info>%s</info>' does not have read permissions.", $fileName));
}
}
$output->write(sprintf("Processing file '<info>%s</info>'... ", $fileName));
$sql = file_get_contents($fileName);
if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
// PDO Drivers
try {
$lines = 0;
$stmt = $conn->prepare($sql);
$stmt->execute();
do {
// Required due to "MySQL has gone away!" issue
$stmt->fetch();
$stmt->closeCursor();
$lines++;
} while ($stmt->nextRowset());
$output->write(sprintf('%d statements executed!', $lines) . PHP_EOL);
} catch (\PDOException $e) {
$output->write('error!' . PHP_EOL);
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
}
} else {
// Non-PDO Drivers (ie. OCI8 driver)
$stmt = $conn->prepare($sql);
$rs = $stmt->execute();
if ($rs) {
$printer->writeln('OK!');
} else {
$error = $stmt->errorInfo();
$output->write('error!' . PHP_EOL);
throw new \RuntimeException($error[2], $error[0]);
}
$stmt->closeCursor();
}
}
}
}
示例6: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();
if (!$cacheDriver) {
throw new \InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
}
$output->write('Clearing ALL Query cache entries' . PHP_EOL);
$cacheIds = $cacheDriver->deleteAll();
if ($cacheIds) {
foreach ($cacheIds as $cacheId) {
$output->write(' - ' . $cacheId . PHP_EOL);
}
} else {
$output->write('No entries to be deleted.' . PHP_EOL);
}
}
示例7: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$emHelper = $this->getHelper('em');
/* @var $em \Doctrine\ORM\EntityManager */
$em = $emHelper->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
if (!empty($metadatas)) {
// Create SchemaTool
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$updateSql = $tool->getUpdateSchemaSql($metadatas, false);
if (count($updateSql) == 0) {
$output->write("[Database] OK - Metadata schema exactly matches the database schema.");
} else {
$output->write("[Database] FAIL - There are differences between metadata and database schema.");
}
} else {
$output->write("No metadata mappings found");
}
}
示例8: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
if (!$cacheDriver) {
throw new \InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');
}
if ($cacheDriver instanceof \Doctrine\Common\Cache\ApcCache) {
throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
}
$output->write('Clearing ALL Metadata cache entries' . PHP_EOL);
$cacheIds = $cacheDriver->deleteAll();
if ($cacheIds) {
foreach ($cacheIds as $cacheId) {
$output->write(' - ' . $cacheId . PHP_EOL);
}
} else {
$output->write('No entries to be deleted.' . PHP_EOL);
}
}
示例9: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$validator = new \Doctrine\ORM\Tools\SchemaValidator($em);
$errors = $validator->validateMapping();
$exit = 0;
if ($errors) {
foreach ($errors as $className => $errorMessages) {
$output->write("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n");
foreach ($errorMessages as $errorMessage) {
$output->write('* ' . $errorMessage . "\n");
}
$output->write("\n");
}
$exit += 1;
} else {
$output->write('<info>[Mapping] OK - The mapping files are correct.</info>' . "\n");
}
if (!$validator->schemaInSyncWithMetadata()) {
$output->write('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>' . "\n");
$exit += 2;
} else {
$output->write('<info>[Database] OK - The database schema is in sync with the mapping files.</info>' . "\n");
}
exit($exit);
}
示例10: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$cmf = new DisconnectedClassMetadataFactory($em);
$metadatas = $cmf->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)) {
// Create EntityGenerator
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
$entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
$entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
foreach ($metadatas as $metadata) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
}
// Generating Entities
$entityGenerator->generate($metadatas, $destPath);
// Outputting information message
$output->write(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例11: execute
/**
* @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);
}
示例12: execute
/**
* @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);
}
}
示例13: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
if ($input->getOption('from-database') === true) {
$em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager()));
}
$cmf = new DisconnectedClassMetadataFactory($em);
$metadata = $cmf->getAllMetadata();
$metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
// Process destination directory
if (!is_dir($destPath = $input->getArgument('dest-path'))) {
mkdir($destPath, 0777, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
$toType = strtolower($input->getArgument('to-type'));
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($toType, $destPath);
if ($toType == 'annotation') {
$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
}
if (count($metadata)) {
foreach ($metadata as $class) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $class->name) . PHP_EOL);
}
$exporter->setMetadata($metadata);
$exporter->export();
$output->write(PHP_EOL . sprintf('Exporting "<info>%s</info>" mapping information to "<info>%s</info>"' . PHP_EOL, $toType, $destPath));
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例14: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
// Process source directories
$fromPaths = array_merge(array($input->getArgument('from-path')), $input->getOption('from'));
foreach ($fromPaths as &$dirName) {
$dirName = realpath($dirName);
if (!file_exists($dirName)) {
throw new \InvalidArgumentException(sprintf("Doctrine 1.X schema directory '<info>%s</info>' does not exist.", $dirName));
} else {
if (!is_readable($dirName)) {
throw new \InvalidArgumentException(sprintf("Doctrine 1.X schema directory '<info>%s</info>' does not have read permissions.", $dirName));
}
}
}
// Process destination directory
$destPath = realpath($input->getArgument('dest-path'));
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Doctrine 2.X mapping destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Doctrine 2.X mapping destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
$toType = $input->getArgument('to-type');
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($toType, $destPath);
if (strtolower($toType) === 'annotation') {
$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
}
$converter = new ConvertDoctrine1Schema($fromPaths);
$metadata = $converter->getMetadata();
if ($metadata) {
$output->write(PHP_EOL);
foreach ($metadata as $class) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $class->name) . PHP_EOL);
}
$exporter->setMetadata($metadata);
$exporter->export();
$output->write(PHP_EOL . sprintf('Converting Doctrine 1.X schema to "<info>%s</info>" mapping type in "<info>%s</info>"', $toType, $destPath));
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例15: _printDeleted
private function _printDeleted(Console\Output\OutputInterface $output, array $items)
{
if ($items) {
foreach ($items as $item) {
$output->write(' - ' . $item . PHP_EOL);
}
} else {
$output->write('No entries to be deleted.' . PHP_EOL);
}
}