コード例 #1
0
ファイル: Drupal.php プロジェクト: ranqiangjun/DrupalConsole
 public function boot()
 {
     $logger = new Logger($this->root);
     if (!class_exists('Drupal\\Core\\DrupalKernel')) {
         $logger->writeln('Class Drupal\\Core\\DrupalKernel not found.');
         $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
         $container = $drupal->boot();
         $container->set('console.logger', $logger);
         return $container;
     }
     try {
         $argvInputReader = new ArgvInputReader();
         if ($argvInputReader->get('uri')) {
             $uri = $argvInputReader->get('uri');
             if (substr($uri, -1) != '/') {
                 $uri .= '/';
             }
             $uri .= 'index.php';
             $request = Request::create($uri, 'GET', array(), array(), array(), array('SCRIPT_NAME' => $this->appRoot . '/index.php'));
         } else {
             $request = Request::createFromGlobals();
         }
         $drupalKernel = DrupalKernel::createFromRequest($request, $this->autoload, 'prod', false);
         $drupalKernel->addServiceModifier(new DrupalServiceModifier($this->root, 'drupal.command', 'drupal.generator'));
         $drupalKernel->invalidateContainer();
         $drupalKernel->rebuildContainer();
         $drupalKernel->boot();
         $container = $drupalKernel->getContainer();
         $container->set('console.root', $this->root);
         $container->set('console.logger', $logger);
         AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
         $configuration = $container->get('console.configuration_manager')->loadConfiguration($this->root)->getConfiguration();
         $container->get('console.translator_manager')->loadCoreLanguage($configuration->get('application.language'), $this->root);
         $container->get('console.renderer')->setSkeletonDirs([$this->root . DRUPAL_CONSOLE . '/templates/', $this->root . DRUPAL_CONSOLE_CORE . '/templates/']);
         return $container;
     } catch (\Exception $e) {
         $logger->writeln($e->getMessage());
         $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
         $container = $drupal->boot();
         $container->set('console.logger', $logger);
         return $container;
     }
 }
コード例 #2
0
ファイル: Drupal.php プロジェクト: GDrupal/DrupalConsole
 public function boot()
 {
     if (!class_exists('Drupal\\Core\\DrupalKernel')) {
         $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
         return $drupal->boot();
     }
     try {
         // Add support for Acquia Dev Desktop sites on Mac OS X
         // @TODO: Check if this condition works in Windows
         $devDesktopSettingsDir = getenv('HOME') . "/.acquia/DevDesktop/DrupalSettings";
         if (file_exists($devDesktopSettingsDir)) {
             $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = $devDesktopSettingsDir;
         }
         $argvInputReader = new ArgvInputReader();
         if ($argvInputReader->get('uri')) {
             $uri = $argvInputReader->get('uri');
             if (substr($uri, -1) != '/') {
                 $uri .= '/';
             }
             $uri .= 'index.php';
             $request = Request::create($uri, 'GET', array(), array(), array(), array('SCRIPT_NAME' => $this->appRoot . '/index.php'));
         } else {
             $request = Request::createFromGlobals();
         }
         $drupalKernel = DrupalKernel::createFromRequest($request, $this->autoload, 'prod', false);
         $drupalKernel->addServiceModifier(new DrupalServiceModifier($this->root, 'drupal.command', 'drupal.generator'));
         $drupalKernel->invalidateContainer();
         $drupalKernel->rebuildContainer();
         $drupalKernel->boot();
         $container = $drupalKernel->getContainer();
         $container->set('console.root', $this->root);
         AnnotationRegistry::registerLoader([$this->autoload, "loadClass"]);
         $configuration = $container->get('console.configuration_manager')->loadConfiguration($this->root)->getConfiguration();
         $container->get('console.translator_manager')->loadCoreLanguage($configuration->get('application.language'), $this->root);
         $container->get('console.renderer')->setSkeletonDirs([$this->root . DRUPAL_CONSOLE . '/templates/', $this->root . DRUPAL_CONSOLE_CORE . '/templates/']);
         return $container;
     } catch (\Exception $e) {
         $drupal = new DrupalConsoleCore($this->root, $this->appRoot);
         return $drupal->boot();
     }
 }
コード例 #3
0
ファイル: drupal.php プロジェクト: GDrupal/DrupalConsole
if (isset($autoloader)) {
    $autoload = (require_once $autoloader);
} else {
    echo ' You must set up the project dependencies using `composer install`' . PHP_EOL;
    exit(1);
}
$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(getcwd());
$composerRoot = $drupalFinder->getComposerRoot();
$drupalRoot = $drupalFinder->getDrupalRoot();
if (!$drupalRoot || !$composerRoot) {
    echo ' DrupalConsole must be executed within a Drupal Site.' . PHP_EOL;
    exit(1);
}
chdir($drupalRoot);
$drupal = new Drupal($autoload, $composerRoot, $drupalRoot);
$container = $drupal->boot();
if (!$container) {
    echo ' Something goes wrong. Drupal can not be bootstrapped.';
    exit(1);
}
$configuration = $container->get('console.configuration_manager')->getConfiguration();
$translator = $container->get('console.translator_manager');
$argvInputReader = new ArgvInputReader();
if ($options = $configuration->get('application.options') ?: []) {
    $argvInputReader->setOptionsFromConfiguration($options);
}
$argvInputReader->setOptionsAsArgv();
$application = new Application($container);
$application->setDefaultCommand('about');
$application->run();