App::run

Run cli-app

@return static
@throws \ReflectionException
428570
public function run()
    {
        $command = new \ReflectionClass($this);
        $options = input()->get();

        if (empty($options)) {
            if ($this->welcomeNote instanceof Format or $this->welcomeNote instanceof Text) {
                output()->write($this->welcomeNote);
            } elseif (is_string($this->welcomeNote) and $this->welcomeNote !== '') {
                output()->write(
                    (new Format())
                        ->setString(language()->getLine($this->welcomeNote))
                        ->setNewLinesAfter(1)
                );
            }

            output()->write(
                (new Format())
                    ->setString($this->name . ' v' . $this->version)
                    ->setNewLinesBefore(2)
                    ->setNewLinesAfter(1)
            );

            // Run help option
            $this->optionHelp();
        } else {

            foreach ($options as $method => $arguments) {

                if ($method === 'h') {
                    $method = 'help';
                } elseif ($method === 'v') {
                    $method = 'version';
                } elseif ($method === 'vv') {
                    $method = 'verbose';
                }

                $optionMethod = camelcase('option-' . $method);

                if ($command->hasMethod($optionMethod)) {

                    $commandMethod = $command->getMethod($optionMethod);

                    if ($commandMethod->getNumberOfRequiredParameters() == 0) {
                        call_user_func([&$this, $optionMethod]);
                    } else {
                        $optionArguments = is_array($arguments)
                            ? $arguments
                            : [$arguments];

                        call_user_func_array([&$this, $optionMethod], $optionArguments);
                    }
                }
            }
        }
    }
1242267
public function run()
    {
        // Add registered command to console 
        foreach ($this->commands as $command) {
            $this->consoleApp->add($command);
        }

        $this->consoleApp->run();
    }
262856
public function run()
    {
        if (!isset($_SERVER['argv'][1])) {
            $_SERVER['argv'][1] = 'commands';
        }

        $input = $_SERVER['argv'][1];

        // Force `commands` command
        if (in_array(strtolower(trim($input)), ['-h', '--help', 'help'], true)) {
            $input = $_SERVER['argv'][1] = 'commands';
        }

        if (in_array(strtolower(trim($input)), ['--version', '-v', '--info'], true)) {
            $input = $_SERVER['argv'][1] = 'info';
        }

        // Try to dispatch the command
        foreach ($this->_commands as $command) {
            if ($command->hasIdentifier($input)) {
                return $this->dispatch($command);
            }
        }

        // Check for alternatives
        $available = [];
        foreach ($this->_commands as $command) {
            $providedCommands = $command->getCommands();
            foreach ($providedCommands as $alias) {
                $soundex = soundex($alias);
                if (!isset($available[$soundex])) {
                    $available[$soundex] = [];
                }

                $available[$soundex][] = $alias;
            }
        }

        // Show exception with/without alternatives
        $soundex = soundex($input);
        $message = sprintf('%s is not a recognized command.', $input);

        if (isset($available[$soundex])) {
            throw new ScriptException(sprintf('%s Did you mean: %s?', $message, join(' or ', $available[$soundex])));
        }

        throw new ScriptException($message);
    }
703217
public function run($app)
    {
        foreach ($app->getApplicationModules() as $id => $module) {
            $folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands';
            if (file_exists($folder) && is_dir($folder)) {
                foreach (FileHelper::findFiles($folder) as $file) {
                    $module->controllerNamespace = $module->namespace . '\commands';
                    
                    $className = '\\'.$module->getNamespace().'\\commands\\' . pathinfo($file, PATHINFO_FILENAME);

                    $command = str_replace('-controller', '', $module->id . '/' . Inflector::camel2id(pathinfo($file, PATHINFO_FILENAME)));
                    
                    Yii::$app->controllerMap[$command] = ['class' => $className];
                }
            }
        }
    }
274042
def run(self):
        
        self.call_plugins("on_run")
        if vars(self.arguments).get("version", None):
            self.logger.info("{app_name}: {version}".format(app_name=self.app_name, version=self.version))
        else:
            if self.arguments.command == "main":
                self.main()
            else:
                self.subcommands[self.arguments.command].run()
        self.call_plugins("on_end")
782523
function run()
    {
        $xml = simplexml_load_file($this->structureXmlFile);

        $this->getClassDefinitions($xml);

        foreach ($this->classDefinitions as $className => $classInfo) {
            $this->expandMethods($className);
            $this->expandProperties($className);
        }

        return $this->classDefinitions;
    }
775791
public function runApplication()
    {
        $routeCollection = $this->createRouteCollection();
        $dispatcher = $routeCollection->getDispatcher();

        $request = $this->createRequest();
        $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
        $response->send();
    }
141518
public function run()
    {
        $this->loadMiddleware();

        //~ Default response
        $response = new HttpMessage\Response();
        //$response->getBody()->write('-- static --');

        //~ Get response
        $stack    = new HttpMiddleware\Stack($response, $this->middleware);
        $response = $stack->process(HttpMessage\ServerRequest::createFromGlobal());

        //~ Send response
        (new HttpMessage\ResponseSender($response))->send();
    }
237434
public function run()
    {
        if ($this->app->getName()) {
            $this->output->writeln($this->app->getName());
            $this->output->newline();
        }

        $commandName = $this->parameter->getArgument('command_name');

        if ($this->parameter->getCommandName() === $this->name && $commandName) {
            $this->showCommandHelp($this->parameter->getArgument('command_name'));
        } else {
            $this->showGeneralHelp();
        }

        return $this;
    }
1334707
public function run()
    {
        session_start();
        self::$_app = $this;
        if (empty($this->_runtimePath)) {
            $this->_runtimePath = $this->_basePath . '/runtime';
        }
        $application = $this->getComponent('application');
        $application->runController();
    }
1035331
public static function run(Application $app)
    {
        $config = Config::getOrEmpty('application');
        $debug  = (bool)Arr::get($config, 'debug', false);
        define('DEBUG', $debug);

        self::setUpErrorHandling($debug);
        self::configure($config);
        self::bootstrap($config);
        self::initAPI($config, $app);

        Session::start();

        foreach (Arr::get($config, 'response.defaultHeaders', []) as $header) {
            header($header);
        }
    }
928709
public function run()
    {
        $keys = array_merge($this->keys(), array_keys($this->definitions));
        foreach ($keys as $key) {
            $content = $this->get($key);

            if (is_object($content)) {
                try {
                    $reflection = new ReflectionClass($content);
                    if ($reflection->hasMethod('run')) {
                        $content->run();
                    }
                } catch (ReflectionException $e) {
                }
            }
        }
    }
1092067
protected static function execute()
    {
        try {
            $instance = static::getInstance();

            $reflectionMethod = new ReflectionMethod($instance, static::$method);

            return $reflectionMethod->invokeArgs($instance, static::$arguments);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
1217781
function runConsole()
    {
        $app = new  Symfony\Component\Console\Application("<info>Swoole Framework</info> Console Tool.");
        $app->add(new Swoole\Command\MakeController());
        $app->add(new Swoole\Command\MakeModel());
        $app->add(new Swoole\Command\MakeConfig());
        $app->run();
    }
692444
protected function startCommandsPlugin($app)
    {
        $this->onRegister('commands', function ($app) {
            /** @var \Illuminate\Foundation\Application $app */
            // Commands
            if ($app->runningInConsole()) {
                foreach ($this->findCommands as $path) {
                    $dir = path_get_directory((new ReflectionClass(get_called_class()))->getFileName());
                    $classes = $this->findCommandsIn(path_join($dir, $path), $this->findCommandsRecursive);

                    $this->commands = array_merge($this->commands, $classes);
                }
                if (is_array($this->commands) && count($this->commands) > 0) {
                    $commands = [];
                    foreach ($this->commands as $k => $v) {
                        if (is_string($k)) {
                            $app[ $this->commandPrefix.$k ] = $app->share(function ($app) use ($k, $v) {
                                return $app->build($v);
                            });

                            $commands[] = $this->commandPrefix.$k;
                        } else {
                            $commands[] = $v;
                        }
                    }
                    $this->commands($commands);
                }
            }
        });
    }
193580
public function run()
    {
        $this->extractInteractions();

        $this->data = $line = [];

        foreach ($this->interactions as $interaction) {
            foreach ($this->columns as $column => $config) {
                if (isset($config['callback'])
                    && method_exists($this, $config['callback']))
                {
                    $params = [];
                    if (isset($config['callbackParameters'])) {
                        $params = $config['callbackParameters'];
                    }
                    $functionCall = $config['callback'];
                    $callbackValue = call_user_func(array($this, $functionCall), $interaction, $params);
                    if (isset($config['valuesAsColumns'])) {
                        $line[$interaction['id']] = array_merge($line[$interaction['id']], $callbackValue);
                    } else {
                        $line[$interaction['id']][$column] = $callbackValue;
                    }
                }
            }
        }
        $this->data = $line;
        $this->columns = $this->interactions = [];
        return $this;
    }
339788
public function run()
    {
        gc_collect_cycles();
        gc_disable();

        if ($this->dryRun) {
            $this->verbose = true;
            $this->runScripts = false;
            $this->installationManager->addInstaller(new NoopInstaller);
            $this->mockLocalRepositories($this->repositoryManager);
        }

        // TODO remove this BC feature at some point
        // purge old require-dev packages to avoid conflicts with the new way of handling dev requirements
        $devRepo = new InstalledFilesystemRepository(new JsonFile($this->config->get('vendor-dir').'/composer/installed_dev.json'));
        if ($devRepo->getPackages()) {
            $this->io->writeError('<warning>BC Notice: Removing old dev packages to migrate to the new require-dev handling.</warning>');
            foreach ($devRepo->getPackages() as $package) {
                if ($this->installationManager->isPackageInstalled($devRepo, $package)) {
                    $this->installationManager->uninstall($devRepo, new UninstallOperation($package));
                }
            }
            unlink($this->config->get('vendor-dir').'/composer/installed_dev.json');
        }
        unset($devRepo, $package);
        // end BC

        if ($this->runScripts) {
            // dispatch pre event
            $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
            $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
        }

        $this->downloadManager->setPreferSource($this->preferSource);
        $this->downloadManager->setPreferDist($this->preferDist);

        // clone root package to have one in the installed repo that does not require anything
        // we don't want it to be uninstallable, but its requirements should not conflict
        // with the lock file for example
        $installedRootPackage = clone $this->package;
        $installedRootPackage->setRequires(array());
        $installedRootPackage->setDevRequires(array());

        // create installed repo, this contains all local packages + platform packages (php & extensions)
        $localRepo = $this->repositoryManager->getLocalRepository();
        if (!$this->update && $this->locker->isLocked()) {
            $platformOverrides = $this->locker->getPlatformOverrides();
        } else {
            $platformOverrides = $this->config->get('platform') ?: array();
        }
        $platformRepo = new PlatformRepository(array(), $platformOverrides);
        $repos = array(
            $localRepo,
            new InstalledArrayRepository(array($installedRootPackage)),
            $platformRepo,
        );
        $installedRepo = new CompositeRepository($repos);
        if ($this->additionalInstalledRepository) {
            $installedRepo->addRepository($this->additionalInstalledRepository);
        }

        $aliases = $this->getRootAliases();
        $this->aliasPlatformPackages($platformRepo, $aliases);

        try {
            $this->suggestedPackages = array();
            $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
            if ($res !== 0) {
                return $res;
            }
        } catch (\Exception $e) {
            $this->installationManager->notifyInstalls();

            throw $e;
        }
        $this->installationManager->notifyInstalls();

        // output suggestions if we're in dev mode
        if ($this->devMode) {
            foreach ($this->suggestedPackages as $suggestion) {
                $target = $suggestion['target'];
                foreach ($installedRepo->getPackages() as $package) {
                    if (in_array($target, $package->getNames())) {
                        continue 2;
                    }
                }

                $this->io->writeError($suggestion['source'].' suggests installing '.$suggestion['target'].' ('.$suggestion['reason'].')');
            }
        }

        # Find abandoned packages and warn user
        foreach ($localRepo->getPackages() as $package) {
            if (!$package instanceof CompletePackage || !$package->isAbandoned()) {
                continue;
            }

            $replacement = (is_string($package->getReplacementPackage()))
                ? 'Use ' . $package->getReplacementPackage() . ' instead'
                : 'No replacement was suggested';

            $this->io->writeError(
                sprintf(
                    "<warning>Package %s is abandoned, you should avoid using it. %s.</warning>",
                    $package->getPrettyName(),
                    $replacement
                )
            );
        }

        if (!$this->dryRun) {
            // write lock
            if ($this->update || !$this->locker->isLocked()) {
                $localRepo->reload();

                // if this is not run in dev mode and the root has dev requires, the lock must
                // contain null to prevent dev installs from a non-dev lock
                $devPackages = ($this->devMode || !$this->package->getDevRequires()) ? array() : null;

                // split dev and non-dev requirements by checking what would be removed if we update without the dev requirements
                if ($this->devMode && $this->package->getDevRequires()) {
                    $policy = $this->createPolicy();
                    $pool = $this->createPool(true);
                    $pool->addRepository($installedRepo, $aliases);

                    // creating requirements request
                    $request = $this->createRequest($this->package, $platformRepo);
                    $request->updateAll();
                    foreach ($this->package->getRequires() as $link) {
                        $request->install($link->getTarget(), $link->getConstraint());
                    }

                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
                    $solver = new Solver($policy, $pool, $installedRepo);
                    $ops = $solver->solve($request, $this->ignorePlatformReqs);
                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
                    foreach ($ops as $op) {
                        if ($op->getJobType() === 'uninstall') {
                            $devPackages[] = $op->getPackage();
                        }
                    }
                }

                $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
                $platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();

                $updatedLock = $this->locker->setLockData(
                    array_diff($localRepo->getCanonicalPackages(), (array) $devPackages),
                    $devPackages,
                    $platformReqs,
                    $platformDevReqs,
                    $aliases,
                    $this->package->getMinimumStability(),
                    $this->package->getStabilityFlags(),
                    $this->preferStable || $this->package->getPreferStable(),
                    $this->preferLowest,
                    $this->config->get('platform') ?: array()
                );
                if ($updatedLock) {
                    $this->io->writeError('<info>Writing lock file</info>');
                }
            }

            if ($this->dumpAutoloader) {
                // write autoloader
                if ($this->optimizeAutoloader) {
                    $this->io->writeError('<info>Generating optimized autoload files</info>');
                } else {
                    $this->io->writeError('<info>Generating autoload files</info>');
                }

                $this->autoloadGenerator->setDevMode($this->devMode);
                $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
            }

            if ($this->runScripts) {
                // dispatch post event
                $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
                $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
            }

            $vendorDir = $this->config->get('vendor-dir');
            if (is_dir($vendorDir)) {
                touch($vendorDir);
            }
        }

        return 0;
    }