@param bool $autoRun

@return Application
@author: Eddilbert Macharia (http://eddmash.com)<edd.cowan@gmail.com>

@throws \Exception
960936
public static function run($autoRun = true, InputInterface $input = null, OutputInterface $output = null)
    {
        $console = new Application('');
        $def = new ListCommand();
        $console->add($def);
        $console->setDefaultCommand($def->getName());

        $console->addCommands(self::getCommands());
        if (null === $output) {
            $output = new ConsoleOutput();
        }
        self::warningText($output);
        self::errorText($output);

        if ($autoRun) {
            $console->run($input, $output);
        }

        return $console;
    }
1187960
public static function autorun()
    {
        /* @var $classes string[] */
        $classes = array_reverse( get_declared_classes() );

        foreach( $classes as $class )
        {
            $type = new \ReflectionClass( $class );
            $abstract = $type->isAbstract();

            if( is_subclass_of( $class, MRPCJsonWebService::class ) === false || $abstract === true )
            {
                continue;
            }

            /* @var $webService MRPCJsonWebService */
            $webService = new $class();

            // If the definitions are requested
            if( $_SERVER['QUERY_STRING'] == 'definition' )
            {
                $definition = new MRPCJsonWebServiceDefinition( $class );

                $webService->getHttpResponse()->setContentType( ContentType::TEXT_HTML );
                $webService->getHttpResponse()->setOutput( (string)$definition );
            }
            // Normal web service execution
            else
            {
                $webService->getHttpResponse()->setContentType( ContentType::APPLICATION_JSON );

                try
                {
                    $webService->execute( $class );
                    $webService->getResponse()->setId( $webService->getRequest()->getId() );
                } catch( MRPCJsonServerException $ex )
                {
                    $error = new MRPCJsonError();
                    $error->setCode( -1 );
                    $error->setMessage( $ex->getMessage() );

                    $webService->response = new MRPCJsonResponse();
                    $webService->response->setError( $error );
                }

                $webService->getHttpResponse()->setOutput( $webService->getResponse()->toJSON() );
            }

            return $webService;
        }

        return null;
    }
701857
public function withAutoplay(bool $autoPlay): self
    {
        if ($this->autoPlay == $autoPlay) {
            return $this;
        }

        $url = clone $this;
        $url->autoPlay = $autoPlay;

        return $url;
    }
420187
public function start($start = null, $autoseek = true)
    {
        if (!func_num_args()) {
            return $this->_start;
        }
        $this->_start = (int) $start;

        if ($autoseek) {
            $this->rewind();
        }
        return $this;
    }
533361
public function run() {
        $results = [
            $this->simulateDelete(),
            $this->simulateUpdate(),
            $this->simulateCreate()
        ];
        
        return array_search(false, $results, true) === false;
    }
1171616
public function onRun()
    {
        /*
         * Redirect to HTTPS checker
         */
        if ($redirect = $this->redirectForceSecure()) {
            return $redirect;
        }

        /*
         * Activation code supplied
         */
        if ($code = $this->activationCode()) {
            $this->onActivate($code);
        }

        $this->prepareVars();
    }
1078060
public function run()
    {

        // register the default autoloader
        require SERVER_AUTOLOADER;

        // synchronize the application instance and register the class loaders
        $application = $this->application;
        $application->registerClassLoaders();

        // register the applications annotation registries
        $application->registerAnnotationRegistries();

        // sychronize timer instance
        $timer = $this->timer;

        // we lock the timer for this check, because if a cancel is in progress then we do not want to
        // do the isActive check, but wait for the cancelling transaction to finish one way or another
        $timer->lock();

        try {
            // check if the timer is active
            if ($timer->isActive() === false) {
                // create the actual date
                $now = new \DateTime('now');
                // log an info that the timer is NOT active
                $application->getInitialContext()->getSystemLogger()->info(
                    sprintf(
                        'Timer is not active, skipping this scheduled execution at: %s for %s',
                        $now->format('Y-m-d'),
                        $timer->getId()
                    )
                );

                return; // return without do anything
            }

            // set the current date as the "previous run" of the timer
            $timer->setPreviousRun(new \DateTime());

            // set the next timeout, if one is available
            if ($nextTimeout = $this->calculateNextTimeout($timer)) {
                $timer->setNextTimeout($nextTimeout->format(ScheduleExpression::DATE_FORMAT));
            } else {
                $timer->setNextTimeout(null);
            }

            // change the state to mark it as in timeout method
            $timer->setTimerState(TimerState::IN_TIMEOUT);

            // persist changes
            $timer->getTimerService()->persistTimer($timer, false);

        } catch (\Exception $e) {
            $application->getInitialContext()->getSystemLogger()->error($e->__toString());
        }

        // unlock after timeout recalculation
        $timer->unlock();

        // call timeout method
        $this->callTimeout($timer);
    }
89782
public function run($connections, $autorun = true)
    {
        if (!is_array($connections)) {
            $connections = array($connections);
        }

        $this->on('connect.error', function($message, $connection, $logger) {
            $logger->error($message);
        });

        $this->emit('connect.before.all', array($connections));

        foreach ($connections as $connection) {
            $this->addConnection($connection);
        }

        $writes = array_map(
            function($connection) {
                return $connection->getData('write');
            },
            $connections
        );
        $this->emit('connect.after.all', array($connections, $writes));

        if ($autorun) {
            $this->getLoop()->run();
        }
    }
896556
public function run($console = false)
    {
        $commands = $this->commands;

        is_string($commands) && $commands = $this->classes();

        foreach ((array) $commands as $command) {
            $item = $this->container->get($command);

            $this->console->add($instance = $item);
        }

        $console === false && $this->console->run();

        return $this->console;
    }
578316
public function run()
    {
        $this->init();
        try {
            $this->bootstrap();
            $this->route();
            $this->dispatch();
        } catch (Exception $e) {
            if (APPLICATION_ENV == self::ENV_DEV) {
                var_dump($e);
            } else {
                throw $e;
            }
        }
        return $this;
    }
1173516
public function discover()
    {
        $result = $this->tryTLD();

        if ($result === false) {
            $result = $this->trySubdomain();
        }

        if ($result === false) {
            $result = $this->trySubdomainUnauthenticatedGet();
        }

        if ($result === false) {
            $result = $this->trySRVRecord();
        }

        if ($result === false) {
            throw new \RuntimeException('Autodiscovery failed.');
        }

        return $result;
    }
844416
public static function run()
    {
        \Swoole\Runtime::enableCoroutine();
        self::$debug = new \swoole_atomic(0);
        self::$xdebug = false;
        self::$coverage = false;
        self::$leader = new \swoole_atomic(0);
        self::$xdebug_table = new \swoole_table(1);
        self::$xdebug_table->column('wid', \swoole_table::TYPE_INT, 8);
        self::$xdebug_table->column('cid', \swoole_table::TYPE_INT, 8);
        self::$xdebug_table->create();
        self::$startTime = date('Y-m-d H:i:s');
        self::$startMillisecond = getMillisecond();
        self::setProcessTitle(getServerName());
        $application = new Application();
        $input = new ArgvInput();
        $output = new ConsoleOutput();
        self::$io = new SymfonyStyle($input, $output);
        self::addDirCommand(SERVER_DIR, "Server", $application);
        self::addDirCommand(APP_DIR, "app", $application);
        $application->run($input, $output);
    }
373780
public static function run($run = true) {
        $console = Pool::value(get_called_class(),function () {
            $config = Config::$o->console;
            // 实例化 console
            $console = new self($config['name'], $config['version'], $config['user']);
            if(isset($config['commands']) && is_array($config['commands'])) {
                $console->defaultCommands = array_merge(
                    $console->defaultCommands,
                    $config['commands']
                );
            }
            return $console;
        });
        if ($run) {
            // 运行
            return $console->execute();
        }
        return $console;
    }
44903
public function run()
    {

        // register a shutdown handler for controlled shutdown
        register_shutdown_function(array(&$this, 'shutdown'));

        // we need the autloader again
        require SERVER_AUTOLOADER;

        // create the service emitter
        $emitter = new Emitter();

        // load the bootstrap configuration
        /** @var \AppserverIo\Appserver\Core\Api\Node\BootstrapNodeInterface $bootstrapNode */
        $bootstrapNode = $this->doLoadBootstrap($this->getBootstrapConfigurationFilename());

        // iterate over the listeners and add them to the emitter
        /** @var \AppserverIo\Appserver\Core\Api\Node\ListenerNodeInterface $listener */
        foreach ($bootstrapNode->getListeners() as $listener) {
            // load the listener class name
            $listenerClassName = $listener->getType();

            // create a new instance of the listener class
            /** @var \League\Event\ListenerInterface $listenerInstance */
            $listenerInstance = new $listenerClassName();

            // query whether we've to inject the application server instance or not
            if ($listenerInstance instanceof ApplicationServerAwareListenerInterface) {
                $listenerInstance->injectApplicationServer($this);
            }

            // add the listeners
            $emitter->addListener($listener->getEvent(), $listenerInstance);
        }

        // synchronize the emitter
        $this->emitter = $emitter;

        // override the default runlevel with the value found in the bootstrap configuration
        $this->runlevel = $this->runlevelFromString($bootstrapNode->getDefaultRunlevel());

        // flag to keep the server running or to stop it
        $keepRunning = true;

        // initialize the actual runlevel with -1
        $actualRunlevel = -1;

        // start with the default runlevel
        $this->init(null, $this->runlevel);

        do {
            try {
                switch ($this->command) {
                    case InitCommand::COMMAND:
                        // copy command params -> the requested runlevel in that case
                        $this->runlevel = $this->params;

                        if ($this->runlevel == ApplicationServerInterface::REBOOT) {
                            // backup the runlevel
                            $backupRunlevel = $actualRunlevel;

                            // shutdown the application server
                            for ($i = $actualRunlevel; $i >= ApplicationServerInterface::SHUTDOWN; $i--) {
                                $this->emitter->emit(sprintf('leave.runlevel.%s', $this->runlevelToString($i)), $i);
                                // stop the services of the PREVIOUS runlevel
                                $this->doStopServices($i + 1);
                            }

                            // switch back to the runlevel we backed up before
                            for ($z = ApplicationServerInterface::SHUTDOWN; $z <= $backupRunlevel; $z++) {
                                $this->emitter->emit(sprintf('enter.runlevel.%s', $this->runlevelToString($z)), $z);
                            }

                            // set the runlevel to the one before we restart
                            $actualRunlevel = $backupRunlevel;

                            // reset the runlevel and the params
                            $this->runlevel = $this->params = $actualRunlevel;

                        } elseif ($actualRunlevel == ApplicationServerInterface::SHUTDOWN) {
                            // we want to shutdown the application server
                            $keepRunning = false;

                        } elseif ($actualRunlevel < $this->runlevel) {
                            // switch to the requested runlevel
                            for ($i = $actualRunlevel + 1; $i <= $this->runlevel; $i++) {
                                $this->emitter->emit(sprintf('enter.runlevel.%s', $this->runlevelToString($i)), $i);
                            }

                            // set the new runlevel
                            $actualRunlevel = $this->runlevel;

                        } elseif ($actualRunlevel > $this->runlevel) {
                            // switch down to the requested runlevel
                            for ($i = $actualRunlevel; $i >= $this->runlevel; $i--) {
                                $this->emitter->emit(sprintf('leave.runlevel.%s', $this->runlevelToString($i)), $i);
                                // stop the services of the PREVIOUS runlevel
                                $this->doStopServices($i + 1);
                            }

                            // set the new runlevel
                            $actualRunlevel = $this->runlevel;

                        } else {
                            // signal that we've finished switching the runlevels and wait
                            $this->locked = false;
                            $this->command = null;

                            // print a message and wait
                            $this->getSystemLogger()->info(sprintf('Switched to runlevel %s!!!', $actualRunlevel));

                            // wait for a new command
                            $this->synchronized(function ($self) {
                                $self->wait();
                            }, $this);
                        }

                        break;

                    case ModeCommand::COMMAND:

                        // switch the application server mode
                        $this->doSwitchSetupMode($this->params, $this->getConfigurationFilename());

                        // singal that we've finished setting umask and wait
                        $this->locked = false;
                        $this->command = null;

                        // wait for a new command
                        $this->synchronized(function ($self) {
                            $self->wait();
                        }, $this);

                        break;

                    default:

                        // print a message and wait
                         $this->getSystemLogger()->info('Can\'t find any command!!!');

                        // singal that we've finished setting umask and wait
                        $this->locked = false;

                        // wait for a new command
                        $this->synchronized(function ($self) {
                            $self->wait();
                        }, $this);

                        break;
                }

            } catch (\Exception $e) {
                $this->getSystemLogger()->error($e->getMessage());
            }

        } while ($keepRunning);
    }
936933
public function doRun(InputInterface $input, OutputInterface $output)
    {
        app()->add('input', $input);
        app()->add('output', $output);

        try {
            return parent::doRun($input, $output);
        } catch (\Exception $exception) {
            app()->handleException($exception);
        }

        throw $exception;
    }
1025616
public function loop($main = true) {
		if ($main && $this->manager) {
			$this->manager->onStartup($this);
		}
		
		while (($line = $this->connection->recv())) {
			if (preg_match("~^ping :(.*)?~i", $line, $pong)) {
				if (!$this->connection->send("PONG {$pong[1]}")) {
					throw new \RuntimeException(
						"failed to send PONG to {$this->server}");
				}
			} else {
				$message = new Message($line);
				
				/* management interface invokation */
				if ($main && $this->manager) {
					switch ($message->getType()) {
						case Message::join: $this->manager->onJoin($this, $message); break;
						case Message::part: $this->manager->onPart($this, $message); break;
						case Message::nick: $this->manager->onNick($this, $message); break;
						case Message::priv: $this->manager->onPriv($this, $message); break;
						/* and so on ... */
					}
				}
				
				/* listener interface invokation */
				foreach ($this->listeners as $listener) {
					$response = $listener
						->onReceive($this->connection, $message);
					if ($response) {
						if (($response instanceof Task)) {
							$this->pool
								->submit($response);
							continue;
						}
						
						throw new \RuntimeException(sprintf(
							"%s returned an invalid response, ".
							"expected Task object or nothing",
							get_class($listener)));
					}
				}
			}
			
			if (!$main)
				break;

			$this->pool->collect(function($responder) {
				if ($responder instanceof Task) {
					return $responder->isGarbage();
				} else return true;
			});
		}
		
		if ($main && $this->manager) {
			$this->manager->onShutdown($this);
		}

		return $main ? 
			$this->loop($main) : $this;
	}
943388
public static function opauth($autoRun = false, $config = array()) {
		if(!isset(self::$opauth)) {
			self::$opauth = new Opauth(self::get_opauth_config($config), $autoRun);
		}
		return self::$opauth;
	}