public function initTool() { $kernel = $this->container->get('kernel'); $this->console = new Application($kernel); $this->console->setAutoExit(false); $this->console->setCatchExceptions(false); $this->console->add(new GenerateEntitiesDoctrineCommand()); $this->console->add(new ConvertMappingDoctrineCommand()); $self = $this; $this->console->register('rm')->setDefinition([new InputArgument('path', InputArgument::REQUIRED)])->setCode(function (InputInterface $input, OutputInterface $output) use($self) { $path = $input->getArgument('path'); $cmd = 'rm -rf ' . $path . ' 2>&1'; $output->writeln(sprintf('<comment>%s</comment>', $cmd)); $self->runCmd($cmd, $output); }); $this->console->register('mkdir')->setDefinition([new InputArgument('path', InputArgument::REQUIRED)])->setCode(function (InputInterface $input, OutputInterface $output) use($self) { $path = $input->getArgument('path'); $cmd = 'mkdir ' . $path . ' 2>&1'; $output->writeln(sprintf('<comment>%s</comment>', $cmd)); $self->runCmd($cmd, $output); }); }
<?php require_once __DIR__ . '/../../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Yaml\Yaml; $console = new Application('Functionnal tests for dailymotion API'); $console->register('upload:dailymotion')->setDescription('Test upload on dailymotion API')->setCode(function (InputInterface $input, OutputInterface $output) use($core) { try { $configuration = Yaml::parse(__DIR__ . '/config/keys.conf.yml'); } catch (\Exception $e) { $output->writeln('<error>could not parse configuration file</error>'); return; } $appbox = \appbox::get_instance($core); $found = false; foreach ($appbox->get_databoxes() as $databox) { /* @var $databox \databox */ $sql = 'SELECT record_id FROM record WHERE type="video" AND ( mime="video/mp4" OR mime="video/quicktime" OR mime="video/x-msvideo" OR mime="video/x-msvideo" ) LIMIT 1'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute(); $rows = $stmt->fetch(\PDO::FETCH_ASSOC); if (1 === count($rows)) { $found = true; $record = $databox->get_record($rows['record_id']); break; } unset($stmt);
<<<CONFIG packages: - "fabpot/goutte: ~3.1" - "symfony/console: ~2.7" - "symfony/yaml: ~2.7" CONFIG; use Goutte\Client; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\Yaml\Yaml; $application = new Application('oEmbed Provider Scraper'); $command = $application->register('scrape:oembed'); $command->setDescription('Scrapes provider data from oembed.com'); $command->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (json or yaml)', 'json'); $command->setCode(function (InputInterface $input, OutputInterface $output) { $client = new Client(); /** @var Crawler $crawler */ $crawler = $client->request('get', 'http://www.oembed.com'); $crawler = $crawler->filterXPath('//a[@id = \'section7.1\']')->nextAll(); $crawler->removeAll($crawler->filterXPath('//a[@id = \'section7.2\']')->nextAll()); $crawler->removeAll($crawler->filterXPath('//a[@id = \'section7.2\']')); $data = $crawler->filterXPath('//p')->each(function (Crawler $nameCrawler, $i) use($crawler) { $data = array('name' => preg_replace('/^(.+?) \\(.+?\\)$/', '\\1', trim($nameCrawler->text())), 'url' => $nameCrawler->filterXPath('//a')->extract(array('href'))[0]); $siblings = $crawler->filterXPath('//p')->eq($i)->nextAll(); $siblings->removeAll($siblings->filterXPath('//p')->eq(0)->nextAll()); $siblings->removeAll($siblings->filterXPath('//p')->eq(0)); $providers = $siblings->filter('ul')->each(function (Crawler $crawler) {
<?php namespace UserApp\Api; use UserApp\Domain\User\Command\RegisterUser; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; require __DIR__ . '/../../vendor/autoload.php'; $app = (require __DIR__ . '/app.php'); $console = new Application(); $console->register('init')->setDescription('Initialize the api')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { //\Domain\Eventing\MySqlEventStore::createSchema($app['db']); }); $console->register('populate-test-data')->setCode(function () use($app) { // add some SQL }); $console->register('create-user')->setDefinition([new InputArgument('id', InputArgument::REQUIRED), new InputArgument('name', InputArgument::REQUIRED), new InputArgument('email', InputArgument::REQUIRED), new InputArgument('passwordHash', InputArgument::REQUIRED)])->setDescription('Create a user')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $app['interactor.user_register'](new RegisterUser(['id' => $input->getArgument('id'), 'name' => $input->getArgument('name'), 'email' => $input->getArgument('email'), 'password' => $input->getArgument('passwordHash')])); }); $console->run();
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; $console = new Application('Artsper Backoffice', 'n/a'); $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); $console->setDispatcher($app['dispatcher']); $console->register('my-command')->setDefinition(array())->setDescription('My command description')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { // do something }); return $console;
public function testRunWithDispatcherSkippingCommand() { $application = new Application(); $application->setDispatcher($this->getDispatcher(true)); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); }); $tester = new ApplicationTester($application); $exitCode = $tester->run(array('command' => 'foo')); $this->assertContains('before.after.', $tester->getDisplay()); $this->assertEquals(ConsoleCommandEvent::RETURN_CODE_DISABLED, $exitCode); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; $console = new Application('Jarvis - Symfony Flavored Edition', '0.1'); $console->register('hello:jarvis')->setDescription('The Hello World command from Jarvis')->setCode(function (InputInterface $input, OutputInterface $output) { $output = new SymfonyStyle($input, $output); $output->success('Hello World from Jarvis Symfony Flavored Edition !'); }); return $console->run();
/** * @expectedException \LogicException * @dataProvider getAddingAlreadySetDefinitionElementData */ public function testAddingAlreadySetDefinitionElementData($def) { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->register('foo')->setDefinition(array($def))->setCode(function (InputInterface $input, OutputInterface $output) { }); $input = new ArrayInput(array('command' => 'foo')); $output = new NullOutput(); $application->run($input, $output); }
* This file is part of the CRUD Admin Generator project. * * Author: Jon Segador <*****@*****.**> * Web: http://crud-admin-generator.com * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Doctrine\DBAL\Schema\Table; $console = new Application('CRUD Admin Generator command instalation', '1.0'); $console->register('generate:admin')->setDefinition(array())->setDescription("Generate administrator")->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $getTablesQuery = "SHOW TABLES"; $getTablesResult = $app['db']->fetchAll($getTablesQuery, array()); $_dbTables = array(); $dbTables = array(); foreach ($getTablesResult as $getTableResult) { $_dbTables[] = reset($getTableResult); $dbTables[] = array("name" => reset($getTableResult), "columns" => array()); } foreach ($dbTables as $dbTableKey => $dbTable) { $getTableColumnsQuery = "SHOW COLUMNS FROM `" . $dbTable['name'] . "`"; $getTableColumnsResult = $app['db']->fetchAll($getTableColumnsQuery, array()); foreach ($getTableColumnsResult as $getTableColumnResult) { $dbTables[$dbTableKey]['columns'][] = $getTableColumnResult; } }
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; $console = new Application('Hush', '0.1'); $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); $console->setDispatcher($app['dispatcher']); $console->register('database:create')->setDescription('Create sqlite dabatase')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $conn = $app['db']; $params = $conn->getParams(); if (!file_exists($params['path'])) { touch($params['path']); } $error = false; try { $conn->getSchemaManager()->createDatabase($params['path']); $output->writeln('<info>Database successfully created</info>'); } catch (\Exception $e) { $output->writeln('<error>Could not create database</error>'); $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); $error = true; } return (int) $error; }); $console->register('schema:load')->setDescription('Load database schema')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $schema = (require __DIR__ . '/../config/schema.php'); foreach ($schema->toSql($app['db']->getDatabasePlatform()) as $sql) { $app['db']->exec($sql . ';');
<?php /** * @author Petr Grishin <*****@*****.**> */ require_once __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; $console = new Application('Parallel unit test'); $console->register('test:parallel')->setDefinition(array(new InputArgument('home', InputArgument::REQUIRED, 'Home path for unit'), new InputArgument('group', InputArgument::OPTIONAL, 'Group test name', 'parallel'), new InputArgument('testPath', InputArgument::OPTIONAL, 'Test path', 'unit-parallel')))->setDescription('Run parallel unit test')->setCode(function (InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); $home = $input->getArgument('home'); $testsPath = $home . '/' . $input->getArgument('testPath'); $script = "for f in `cd {$testsPath}; ls *Test.php`\n" . "do\n" . "echo \"================\n=== Run test ===\n \$f\n================\"\n" . "phpunit --bootstrap={$home}/Bootstrap.php --group=before {$testsPath}/\$f\n" . "wait\n" . "for i in {1..3}\n do\n phpunit --bootstrap={$home}/Bootstrap.php --group={$group} {$testsPath}/\$f&\n done\n" . "for i in {1..3}\n do\n wait\n done\n" . "fg\n" . "done\n"; $output->writeln(`{$script}`); }); $console->run();
<?php require_once 'vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; $console = new Application(); // Symfony stufs $console->register('search:audio')->setDefinition(array(new InputArgument('search', InputArgument::OPTIONAL, 'Who shall we greet?', 'world')))->setDescription('Greet someone.')->setHelp('The <info>vk:find</info> search word')->setCode(function (InputInterface $input, OutputInterface $output) { // Callback $search = $input->getArgument('search'); $output->writeln('We search : ' . $search); $appIDIndex = 0; $appsList = (include __DIR__ . '/config/apps.php'); echo "\r\n{$appsList[$appIDIndex]['id']}\r\n"; $access_token = $appsList[$appIDIndex]['access_token']; $secret = $appsList[$appIDIndex]['secret']; // $access_token = '64059cedaa84400e0fa660fbcf7d588a78794e4ca8dfd7b861d2f556c49202a38cedff4c26a21b6f551fe'; // $secret = 'e72c2df9bce21df37c'; $vkApi = new \Parser\VK($access_token, $secret); $file_handle = fopen(__DIR__ . "/in/in.txt", "r"); $file = __DIR__ . "/out/out.txt"; file_put_contents($file, ''); while (!feof($file_handle)) { sleep(1); $line = fgets($file_handle); $response = $vkApi->api('audio.get', array('owner_id' => (int) $line, 'need_user' => 0)); if (isset($response['error']) && $response['error']['error_code'] == 9) { sleep(2);
#!/usr/bin/env php <?php require __DIR__ . '/vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; $application = new Application(); $application->register('json:update')->setDescription('Create a new data set')->addArgument('token', InputArgument::REQUIRED, 'Contentful token')->addArgument('space', InputArgument::REQUIRED, 'Contentful space id')->addArgument('content-type', InputArgument::REQUIRED, 'Contentful content type id')->addArgument('image-folder', InputArgument::REQUIRED, 'Folder for images')->setCode(function (InputInterface $input, OutputInterface $output) { $token = $input->getArgument('token'); $space = $input->getArgument('space'); $imageFolder = realpath($input->getArgument('image-folder')); $locale = 'da-DK'; $client = new \Contentful\Delivery\Client($token, $space); $query = new \Contentful\Delivery\Query(); $query->setInclude(10); $query->setLimit(1000); $query->setContentType($input->getArgument('content-type')); $entries = $client->getEntries($query); $fieldMapping = ['tags' => ['properties' => ['name' => 'name']], 'gameCategory' => ['properties' => ['category' => 'name']], 'gameArea' => ['properties' => ['area' => 'area']], 'images' => ['properties' => ['image' => 'image']], 'image' => ['properties' => ['file' => 'file']], 'file' => ['properties' => ['file' => 'url']]]; $field = function ($fieldName, \Contentful\Delivery\DynamicEntry $entry) use($fieldMapping, &$field, $locale) { try { $contentTypeField = $entry->getContentType()->getField($fieldName); if ($contentTypeField !== NULL) { $type = $contentTypeField->getType(); } else { $type = NULL; } $methodName = 'get' . ucfirst($fieldName); /** @var \Contentful\Delivery\ContentTypeField $value */ $value = $entry->{$methodName}($locale);
// Register console namespace use Symfony\Component\Console\Application; // Create new console application $console = new Application(); // Load any plugin functions $directory = dirname(__FILE__) . '/ConsolePlugins/'; if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) { foreach ($scanned_directory as $file) { if (is_dir($file)) { if (file_exists($directory . $file . '/Main.php')) { @(include $directory . $file . '/Main.php'); } } } } $console->register('makeconfig')->setDescription('Attempts to write configuration variables to a Known config.ini file')->setDefinition([new \Symfony\Component\Console\Input\InputArgument('dbuser', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database username'), new \Symfony\Component\Console\Input\InputArgument('dbpass', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database password'), new \Symfony\Component\Console\Input\InputArgument('dbname', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database name'), new \Symfony\Component\Console\Input\InputArgument('database', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Database type', 'mysql'), new \Symfony\Component\Console\Input\InputArgument('dbhost', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Database hostname', 'localhost'), new \Symfony\Component\Console\Input\InputArgument('filename', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Configuration filename', 'config.ini')])->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { if ($fp = fopen($input->getArgument('filename'), 'w')) { fwrite($fp, "[Database configuration]\n"); fwrite($fp, "database=" . $input->getArgument('database') . "\n"); fwrite($fp, "dbhost=" . $input->getArgument('dbhost') . "\n"); fwrite($fp, "dbname=" . $input->getArgument('dbname') . "\n"); fwrite($fp, "dbuser="******"\n"); fwrite($fp, "dbpass="******"\n"); fclose($fp); } else { $output->writeln("Couldn't open " . $input->getArgument('filename')); } }); $console->register('version')->setDescription('Returns the current Known version as defined in version.known')->setDefinition([])->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $output->writeln(file_get_contents(dirname(__FILE__) . '/version.known')); });
<?php require_once __DIR__ . '/../../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use ComponentInstaller\Installer; $console = new Application('Silex Markdown', '0.1'); $app->boot(); if (isset($app['cache.path'])) { $console->register('cache:clear')->setDescription('Clears the cache')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $cacheDir = $app['cache.path']; $finder = Finder::create()->in($cacheDir)->notName('.gitkeep'); $filesystem = new Filesystem(); $filesystem->remove($finder); $output->writeln(sprintf("%s <info>success</info>", 'cache:clear')); }); } if (isset($app['assetic.options'])) { $console->register('assetic:dump')->setDescription('Dumps all assets to the filesystem')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { if (!$app['assetic.enabled']) { return false; } $dumper = $app['assetic.dumper']; if (isset($app['twig'])) { $dumper->addTwigAssets();
* This file is part of the CRUD Admin Generator project. * * Author: Jon Segador <*****@*****.**> * Web: http://crud-admin-generator.com * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Doctrine\DBAL\Schema\Table; $console = new Application('CRUD Admin Generator command instalation', '1.0'); $console->register('generate:admin')->setDefinition(array())->setDescription("Generate administrator")->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $getTablesQuery = "SHOW TABLES"; $getTablesResult = $app['db']->fetchAll($getTablesQuery, array()); $_dbTables = array(); $dbTables = array(); foreach ($getTablesResult as $getTableResult) { $_dbTables[] = reset($getTableResult); $dbTables[] = array("name" => reset($getTableResult), "columns" => array()); } foreach ($dbTables as $dbTableKey => $dbTable) { $getTableColumnsQuery = "SHOW COLUMNS FROM `" . $dbTable['name'] . "`"; $getTableColumnsResult = $app['db']->fetchAll($getTableColumnsQuery, array()); foreach ($getTableColumnsResult as $getTableColumnResult) { $dbTables[$dbTableKey]['columns'][] = $getTableColumnResult; } }
public function testRunDispatchesAllEventsWithException() { $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); }
<?php $sc = (require_once __DIR__ . '/src/bootstrap.php'); // Render the site with the given config file use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; $console = new Application('SiteBuilder', '3.5.4'); $console->register('rebuild')->setDescription('Renders all content, writes to output folder')->setHelp(<<<'EOH' This command renders your content files and saves them in the output folder. Run it like this: %command.full_name% EOH )->setDefinition(array())->addOption('force', false, InputOption::VALUE_NONE, 'Overwrite all files, even if unchanged')->addOption('delete', false, InputOption::VALUE_NONE, 'Delete files from output if they aren\'t in content')->setCode(function (InputInterface $input, OutputInterface $output) use($sc) { $filesystem = $sc->get('sitebuilder_filesystem'); $output->writeln('<info>Copying and transforming content</info>'); $filesystem->mirror($sc->getParameter('content_dir'), $sc->getParameter('output_dir'), null, array('override' => $input->getOption('force'), 'delete' => $input->getOption('delete'))); }); $console->register('init')->setDescription('Create necessary folders')->setHelp(<<<'EOH' This command creates the content, output, and template folders that SiteBuilder expects. Run it like this: %command.full_name% EOH )->setDefinition(array())->setCode(function (InputInterface $input, OutputInterface $output) use($sc) { foreach (array('content', 'output', 'templates', 'cache') as $dir) { if (!is_dir($dir)) {
public function testRunDispatchesAllEventsWithException() { if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); }
<?php declare (strict_types=1); require __DIR__ . '/vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; $console = new Application(); $console->register('eval')->setDefinition(array(new InputArgument('expression', InputArgument::REQUIRED, 'Arithmetic expression to evaluate')))->setDescription('Evaluates a given arithmetic expression and writes the result to STDOUT')->setCode(function (InputInterface $input, OutputInterface $output) { }); $console->run();
public function testRegister() { $application = new Application(); $command = $application->register('foo'); $this->assertEquals('foo', $command->getName(), '->register() registers a new command'); }
} define('IMAGER_ABSPATH', __DIR__ . DIRECTORY_SEPARATOR); require_once dirname(__FILE__) . '/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Question\ConfirmationQuestion; use Imager\Imager; use Imager\Bundle\AbstractBundle; use Imager\Bundle\InvalidBundleException; use Imager\Bundle\BundleAlreadyRegisteredException; $console = new Application(); $console->register('init')->setDescription('Starts an interactive wizard for generating an imager.json file.')->setCode(function (InputInterface $input, OutputInterface $output) { $question = $this->getHelper('question'); $output->writeln('You are about to generate an imager.json file'); $output->writeln('for automated image generation.'); $output->write(PHP_EOL); $output->writeln('Once you have the file you\'ll be able to call'); $output->writeln('"php imager.phar generate imager.json".'); $output->writeln('or just "php imager.phar generate" in the same directory.'); $output->write(PHP_EOL); $imager = new Imager(); $filename = 'imager.json'; $json = array('run' => array(), 'bundles' => array(), 'options' => array()); if ($question->ask($input, $output, new ConfirmationQuestion('Would you like to register any custom bundles' . PHP_EOL . 'aside from the built in ones? [y/N] ', false))) { $output->write(PHP_EOL); while (true) { $class = $question->ask($input, $output, new Question('Bundle class name (enter to stop adding): '));
* Initialize autoloader */ require_once 'vendor/autoload.php'; /** * Initialize console */ use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; $console = new Application(); /** * Add commands */ $console->register('sync')->setDescription('Sync destination language file - add missing keys, rearrange order.')->setHelp(' The <info>sync</info> command will take the source language file and create destination language file maintaining original content line ordering and using existing destination language file contents if destination language file already exists. <comment>Samples:</comment> Default: sync english to slovenian: <info>sync</info> Sync english to croatian: <info>sync croatian</info> Sync german to serbian: <info>sync --source=german sebian</info> ')->setDefinition(array(new InputOption('source', 's', InputOption::VALUE_REQUIRED, 'Which language file to use as source?', 'english'), new InputArgument('destination', InputArgument::OPTIONAL, 'Destination language to update', 'slovenian')))->setCode(function (InputInterface $input, OutputInterface $output) { $srcLang = $input->getOption('source'); $destLang = $input->getArgument('destination'); // Switch to language directory
protected function registerCommand(Application $app, zCallable $function, array $opts) { foreach ($function->get('cli') as $ann) { $args = array_values($ann->getArgs()); if (empty($args)) { continue; } $question = $app->getHelperSet()->get('question'); $app->register($args[0])->setDescription(!empty($args[1]) ? $args[1] : $args[0])->setDefinition($opts)->setCode($this->wrapper($function, $question)); } }
(window.LocaleData || (window.LocaleData = {}))['{$name}'] = factory(); } }(typeof window !== "undefined" ? window : this, function() { return {$json}; })); EOF; } function store($name, array $data) { file_put_contents(__DIR__ . '/../data/' . $name . '.json', json_encode($data, JSON_PRETTY_PRINT) . PHP_EOL); file_put_contents(__DIR__ . '/../data/' . $name . '.js', js($name, $data) . PHP_EOL); file_put_contents(__DIR__ . '/../data/' . $name . '.php', '<?php return ' . var_export($data, true) . ';' . PHP_EOL); file_put_contents(__DIR__ . '/../data/' . $name . '.yml', Yaml::dump($data)); } $console = new Application('LocaleData', '1.1.2'); $console->register('generate')->setDefinition([new InputArgument('path', InputArgument::REQUIRED, 'The path to the glibc localedata/locales directory')])->setDescription('Generate localedata files.')->setCode(function (InputInterface $input, OutputInterface $output) { $path = $input->getArgument('path'); if (!is_dir($path)) { $output->writeln('<error>Path "' . $path . '" not found.</error>'); return; } $locales = array_filter(scandir($path), function ($path) { return '.' !== $path[0]; }); $availableLocales = array(); $root = (include __DIR__ . '/data_root.php'); foreach ($locales as $locale) { $output->write('Processing locale <comment>' . $locale . '</comment>...'); $data = parse($path, $locale); if (null === $data) { $output->writeln('<error>No data found</error>.');
<?php require_once __DIR__ . '/vendor/autoload.php'; $app = (require __DIR__ . '/app.php'); use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Exception\IOException; $console = new Application(); $console->register('cache:clear-old-file')->setDefinition(array(new InputOption('ttl', 't', InputOption::VALUE_OPTIONAL, 'ttl', 300), new InputOption('dry-run', null, InputOption::VALUE_NONE, ''), new InputOption('without-hashed-file', null, InputOption::VALUE_NONE, ''), new InputOption('hashed-file-ttl', null, InputOption::VALUE_OPTIONAL, '', 60 * 60 * 24 * 30 * 6)))->setDescription('Clear old cache files')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $ttl = $input->getOption('ttl'); $dryRun = $input->getOption('dry-run'); $dryRunText = ''; if ($dryRun) { $dryRunText = ' (dry-run)'; } $finder = new Finder(); $fs = new Filesystem(); $finder->files()->notName('/\\$[0-9a-f]+\\.json$/')->date('until ' . $ttl . ' sec ago')->in($app['cache_dir']); foreach ($finder as $file) { $output->writeln('<info>Remove ' . $file->getRealpath() . $dryRunText . '</info>'); if (!$dryRun) { $fs->remove($file); } } if (!$input->getOption('without-hashed-file')) { $hashedFileFinder = new Finder();
* User: sarel * Date: 2015/12/30 * Time: 12:51 */ use Afrihost\SwarmProcess\SwarmProcess; use Monolog\Logger; use Monolog\Processor\MemoryUsageProcessor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; chdir(__DIR__); require '../vendor/autoload.php'; $console = new Application(); $console->register('play')->setDescription('Play command for testing purposes')->setDefinition(array(new InputOption('use-run', null, InputOption::VALUE_NONE, 'Uses the ->run() method of SwarmProcess'), new InputOption('use-callable', null, InputOption::VALUE_NONE, 'Uses the ->run() method of SwarmProcess - but specifying a callable'), new InputOption('use-tick', null, InputOption::VALUE_NONE, 'Uses the ->tick() method of SwarmProcess'), new InputOption('concurrent-count', null, InputOption::VALUE_REQUIRED, 'Number of concurrent jobs to run', 5), new InputOption('number-of-jobs', null, InputOption::VALUE_REQUIRED, 'Number of jobs to run', 50)))->setCode(function (InputInterface $input, OutputInterface $output) { $concurrent = $input->getOption('concurrent-count'); $numberOfJobs = $input->getOption('number-of-jobs'); switch (true) { case $input->getOption('use-run'): useRun($concurrent, $numberOfJobs); break; case $input->getOption('use-tick'): useTick($concurrent, $numberOfJobs); break; case $input->getOption('use-callable'): useCallable($concurrent, $numberOfJobs); break; default: $output->writeln('<error>You should supply either --use-run or --use-tick to choose which way to use the system to test</error>'); }
<?php use MacFJA\Symfony\Console\Filechooser\FilechooserHelper; use MacFJA\Symfony\Console\Filechooser\FileFilter; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; require_once __DIR__ . '/../vendor/autoload.php'; $app = new Application(); $app->getHelperSet()->set(new FilechooserHelper()); $app->register('ask-path')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { // ask and validate the answer /** @var FilechooserHelper $dialog */ $dialog = $app->getHelperSet()->get('filechooser'); $filter = new FileFilter('Where is your file? '); //$filter->sortByType(); $color = $dialog->ask($input, $output, $filter); $output->writeln(sprintf('You have just entered: %s', $color)); }); $app->run();
public function testRunWithDispatcherAddingInputOptions() { $extraValue = null; $dispatcher = $this->getDispatcher(); $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use(&$extraValue) { $definition = $event->getCommand()->getDefinition(); $input = $event->getInput(); $definition->addOption(new InputOption('extra', null, InputOption::VALUE_REQUIRED)); $input->bind($definition); $extraValue = $input->getOption('extra'); }); $application = new Application(); $application->setDispatcher($dispatcher); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo', '--extra' => 'some test value')); $this->assertEquals('some test value', $extraValue); }
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Doctrine\DBAL\DriverManager; $console = new Application('Silex - Kitchen Edition', '0.1'); $console->register('assetic:dump')->setDescription('Dumps all assets to the filesystem')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $dumper = $app['assetic.dumper']; if (isset($app['twig'])) { $dumper->addTwigAssets(); } $dumper->dumpAssets(); $output->writeln('<info>Dump finished</info>'); }); $console->register('doctrine:schema:show')->setDescription('Output schema declaration')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $schema = (require __DIR__ . '/../resources/db/schema.php'); foreach ($schema->toSql($app['db']->getDatabasePlatform()) as $sql) { $output->writeln($sql . ';'); } }); $console->register('doctrine:schema:load')->setDescription('Load schema')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { $schema = (require __DIR__ . '/../resources/db/schema.php'); foreach ($schema->toSql($app['db']->getDatabasePlatform()) as $sql) { $app['db']->exec($sql . ';'); } }); $console->register('doctrine:database:drop')->setName('doctrine:database:drop')->setDescription('Drops the configured databases')->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action')->setHelp(<<<EOT The <info>doctrine:database:drop</info> command drops the default connections database: