当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::register方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Application::register方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::register方法的具体用法?PHP Application::register怎么用?PHP Application::register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Application的用法示例。


在下文中一共展示了Application::register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initTool

 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);
     });
 }
开发者ID:demboo,项目名称:mysql-workbench-schema-exporter-symfony2-bundle,代码行数:22,代码来源:Schema.php

示例2: Application

<?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);
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:31,代码来源:dailymotion.php

示例3: Application

<<<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) {
开发者ID:bangpound,项目名称:oembed,代码行数:30,代码来源:scraper.php

示例4: Application

<?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();
开发者ID:bashilbers,项目名称:hexagonal-event-sourced-user-app-example,代码行数:22,代码来源:console.php

示例5: Application

<?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;
开发者ID:streetcolor,项目名称:silex-mvc,代码行数:14,代码来源:console.php

示例6: testRunWithDispatcherSkippingCommand

 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);
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:13,代码来源:ApplicationTest.php

示例7: Application

<?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();
开发者ID:mickaelandrieu,项目名称:jarvis-symfony-edition,代码行数:13,代码来源:console.php

示例8: testAddingAlreadySetDefinitionElementData

 /**
  * @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);
 }
开发者ID:TeamA-ict,项目名称:TeamA,代码行数:15,代码来源:ApplicationTest.php

示例9: Application

 * This file is part of the CRUD Admin Generator project.
 *
 * Author: Jon Segador <jonseg@gmail.com>
 * 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;
        }
    }
开发者ID:rameduard,项目名称:bodeven,代码行数:31,代码来源:console.php

示例10: Application

<?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 . ';');
开发者ID:nclshart,项目名称:hush,代码行数:31,代码来源:console.php

示例11: Application

<?php

/**
 * @author Petr Grishin <petr.grishin@grishini.ru>
 */
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();
开发者ID:petrgrishin,项目名称:parallel-unit-test,代码行数:20,代码来源:cli.php

示例12: Application

<?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);
开发者ID:sektor-sumy,项目名称:parser,代码行数:31,代码来源:api.php

示例13: Application

#!/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);
开发者ID:Pilen,项目名称:legedatabasen,代码行数:31,代码来源:app.php

示例14: Application

// 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=" . $input->getArgument('dbuser') . "\n");
        fwrite($fp, "dbpass=" . $input->getArgument('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'));
});
开发者ID:jirkadus,项目名称:Known,代码行数:31,代码来源:known.php

示例15: Application

<?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();
开发者ID:ronanguilloux,项目名称:silexmarkdown,代码行数:31,代码来源:console.php


注:本文中的Symfony\Component\Console\Application::register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。