Puli\Manager\Api\Container::start PHP Метод

start() публичный Метод

Starts the service container.
public start ( )
    public function start()
    {
        if ($this->started) {
            throw new LogicException('Puli is already started');
        }
        if (null !== $this->rootDir) {
            $this->context = $this->createProjectContext($this->rootDir, $this->env);
            $bootstrapFile = $this->context->getConfig()->get(Config::BOOTSTRAP_FILE);
            // Run the project's bootstrap file to enable project-specific
            // autoloading
            if (null !== $bootstrapFile) {
                // Backup autoload functions of the PHAR
                $autoloadFunctions = spl_autoload_functions();
                foreach ($autoloadFunctions as $autoloadFunction) {
                    spl_autoload_unregister($autoloadFunction);
                }
                // Add project-specific autoload functions
                require_once Path::makeAbsolute($bootstrapFile, $this->rootDir);
                // Prepend autoload functions of the PHAR again
                // This is needed if the user specific autoload functions were
                // added with $prepend=true (as done by Composer)
                // Classes in the PHAR should always take precedence
                for ($i = count($autoloadFunctions) - 1; $i >= 0; --$i) {
                    spl_autoload_register($autoloadFunctions[$i], true, true);
                }
            }
        } else {
            $this->context = $this->createGlobalContext();
        }
        $this->dispatcher = $this->context->getEventDispatcher();
        $this->started = true;
        // Start plugins once the container is running
        if ($this->rootDir && $this->pluginsEnabled) {
            $this->activatePlugins();
        }
    }

Usage Example

Пример #1
0
 /**
  * Creates the configuration.
  *
  * @param Container $puli The Puli service container
  */
 public function __construct(Container $puli = null)
 {
     // Start Puli already so that plugins can change the CLI configuration
     $this->puli = $puli ?: new Container(getcwd());
     if (!$this->puli->isStarted()) {
         $this->puli->start();
     }
     parent::__construct();
 }