本文整理汇总了PHP中Drupal\Core\DrupalKernel类的典型用法代码示例。如果您正苦于以下问题:PHP DrupalKernel类的具体用法?PHP DrupalKernel怎么用?PHP DrupalKernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DrupalKernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDiscoverServiceNoContainerYamls
/**
* Tests the exception when container_yamls is not set.
*/
public function testDiscoverServiceNoContainerYamls()
{
new Settings([]);
$kernel = new DrupalKernel('prod', new \Composer\Autoload\ClassLoader());
$kernel->discoverServiceProviders();
$expect = ['app' => ['core' => 'core/core.services.yml'], 'site' => []];
$this->assertAttributeSame($expect, 'serviceYamls', $kernel);
}
示例2: run
/**
* {@inheritdoc}
*/
public function run()
{
$settingsPath = DRUPAL_ROOT . '/' . DrupalKernel::findSitePath(Drupal::request()) . '/settings.php';
$result = CheckResult::FAIL;
$findings = array();
if (file_exists($settingsPath)) {
if ($this->settings()->get('method', 'token') === 'token') {
$content = file_get_contents($settingsPath);
$tokens = token_get_all($content);
foreach ($tokens as $token) {
if (is_array($token) && $token[0] === T_VARIABLE && $token[1] == '$base_url') {
$result = CheckResult::SUCCESS;
break;
}
}
} else {
include $settingsPath;
if (isset($base_url)) {
$result = CheckResult::SUCCESS;
}
}
global $base_url;
if ($result === CheckResult::FAIL) {
$findings[] = t('Your site is available at the following URL: !url.', array('!url' => $base_url));
$findings[] = t("If your site should only be available at that URL it is recommended that you set it as the \$base_url variable in the settings.php file at !file", array('!file' => $settingsPath));
$findings[] = t("Or, if you are using Drupal's multi-site functionality then you should set the \$base_url variable for the appropriate settings.php for your site.");
}
return $this->createResult($result, $findings);
} else {
return $this->createResult(CheckResult::INFO, array(t("Couldn't determine settings.php's path.")));
}
}
示例3: testValidateHostname
/**
* @covers ::validateHostname
* @dataProvider providerTestValidateHostname
*/
public function testValidateHostname($hostname, $message, $expected = FALSE)
{
$server = ['HTTP_HOST' => $hostname];
$request = new Request([], [], [], [], [], $server);
$validated_hostname = DrupalKernel::validateHostname($request);
$this->assertSame($expected, $validated_hostname, $message);
}
示例4: setUp
function setUp()
{
parent::setUp();
// Add file_private_path setting.
$request = Request::create('/');
$site_path = DrupalKernel::findSitePath($request);
$this->setSetting('file_private_path', $site_path . '/private');
}
示例5:
function bootstrap_drupal_configuration()
{
$this->request = Request::createFromGlobals();
$classloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
$this->kernel = DrupalKernel::createFromRequest($this->request, $classloader, 'prod');
// Unset drupal error handler and restore drush's one.
restore_error_handler();
parent::bootstrap_drupal_configuration();
}
示例6: setUp
function setUp()
{
// Add file_private_path setting.
$settings = Settings::getAll();
$request = Request::create('/');
$site_path = DrupalKernel::findSitePath($request);
$settings['file_private_path'] = $site_path . '/private';
new Settings($settings + Settings::getAll());
parent::setUp();
}
示例7: initialize
public function initialize(\Boris\Boris $boris, $dir)
{
parent::initialize($boris, $dir);
$classloader = (require_once $dir . '/core/vendor/autoload.php');
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$kernel = \Drupal\Core\DrupalKernel::createFromRequest($request, $classloader, 'dev');
$kernel->boot();
$kernel->prepareLegacyRequest($request);
\Drupal::getContainer()->set('request', $request);
$boris->onStart(function ($worker, $vars) use($kernel) {
$worker->setLocal('kernel', $kernel);
$worker->setLocal('container', $kernel->getContainer());
});
}
示例8: setUp
/**
* {@inheritdoc}
*
* Configures a preexisting settings.php file without an install_profile
* setting before invoking the interactive installer.
*/
protected function setUp()
{
// Pre-configure hash salt.
// Any string is valid, so simply use the class name of this test.
$this->settings['settings']['hash_salt'] = (object) array('value' => __CLASS__, 'required' => TRUE);
// Pre-configure database credentials.
$connection_info = Database::getConnectionInfo();
unset($connection_info['default']['pdo']);
unset($connection_info['default']['init_commands']);
$this->settings['databases']['default'] = (object) array('value' => $connection_info, 'required' => TRUE);
// Pre-configure config directories.
$this->settings['config_directories'] = array(CONFIG_SYNC_DIRECTORY => (object) array('value' => DrupalKernel::findSitePath(Request::createFromGlobals()) . '/files/config_sync', 'required' => TRUE));
mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
parent::setUp();
}
示例9: getTestKernel
/**
* Build a kernel for testings.
*
* Because the bootstrap is in DrupalKernel::boot and that involved loading
* settings from the filesystem we need to go to extra lengths to build a kernel
* for testing.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* A request object to use in booting the kernel.
* @param array $modules_enabled
* A list of modules to enable on the kernel.
* @param bool $read_only
* Build the kernel in a read only state.
* @return DrupalKernel
*/
protected function getTestKernel(Request $request, array $modules_enabled = NULL, $read_only = FALSE)
{
// Manually create kernel to avoid replacing settings.
$kernel = DrupalKernel::createFromRequest($request, drupal_classloader(), 'testing');
$this->settingsSet('hash_salt', $this->databasePrefix);
if (isset($modules_enabled)) {
$kernel->updateModules($modules_enabled);
}
$kernel->boot();
if ($read_only) {
$php_storage = Settings::get('php_storage');
$php_storage['service_container']['class'] = 'Drupal\\Component\\PhpStorage\\FileReadOnlyStorage';
$this->settingsSet('php_storage', $php_storage);
}
return $kernel;
}
示例10: testFindSitePath
/**
* Tests site path finding.
*
* This test is run in a separate process since it defines DRUPAL_ROOT. This
* stops any possible pollution of other tests.
*
* @covers ::findSitePath
* @runInSeparateProcess
*/
public function testFindSitePath()
{
$vfs_root = vfsStream::setup('drupal_root');
$sites_php = <<<'EOD'
<?php
$sites['8888.www.example.org'] = 'example';
EOD;
// Create the expected directory structure.
vfsStream::create(['sites' => ['sites.php' => $sites_php, 'example' => ['settings.php' => 'test']]]);
define('DRUPAL_ROOT', $vfs_root->url('drupal_root'));
$request = new Request();
$request->server->set('SERVER_NAME', 'www.example.org');
$request->server->set('SERVER_PORT', '8888');
$request->server->set('SCRIPT_NAME', '/index.php');
$this->assertEquals('sites/example', DrupalKernel::findSitePath($request));
}
示例11: bootstrap
/**
* {@inheritdoc}
*/
public function bootstrap()
{
// Validate, and prepare environment for Drupal bootstrap.
if (!defined('DRUPAL_ROOT')) {
define('DRUPAL_ROOT', $this->drupalRoot);
}
// Bootstrap Drupal.
chdir(DRUPAL_ROOT);
$autoloader = (require DRUPAL_ROOT . '/autoload.php');
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
$this->validateDrupalSite();
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
$kernel->prepareLegacyRequest($request);
// Initialise an anonymous session. required for the bootstrap.
\Drupal::service('session_manager')->start();
}
示例12: getApplication
/**
* Create a Drupal application.
*/
public function getApplication()
{
// Bootstrap Drupal.
// Bootstrap code is modeled on a few examples in core/scripts, such as
// db-tools.php.
// Assume we're in DRUPAL_ROOT/vendor/php-pm/httpkernel-adapter/Bootstraps.
// There may be a safer way to do this...
$drupal_root = dirname(dirname(dirname(dirname(__DIR__))));
// @todo: Is it necessary to call bootEnv()? It's called automatically by createFromRequest().
DrupalKernel::bootEnvironment();
$request = Request::createFromGlobals();
// @todo: Is it necessary to call initialize()? Is it called through createFromRequest()?
$autoloader = (include $drupal_root . '/autoload.php');
Settings::initialize($drupal_root, DrupalKernel::findSitePath($request), $autoloader);
$app = DrupalKernel::createFromRequest($request, $autoloader, $this->appenv);
$app->boot();
return $app;
}
示例13: setUpSite
/**
* Overrides method.
*
* We have several forms to navigate through.
*/
protected function setUpSite()
{
// Recreate the container so that we can simulate the submission of the
// SyncConfigureForm after the full bootstrap has occurred. Without out this
// drupal_realpath() does not work so uploading files through
// WebTestBase::postForm() is impossible.
$request = Request::createFromGlobals();
$class_loader = (require $this->container->get('app.root') . '/vendor/autoload.php');
Settings::initialize($this->container->get('app.root'), DrupalKernel::findSitePath($request), $class_loader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel->prepareLegacyRequest($request);
$this->container = $this->kernel->getContainer();
$this->setUpSyncForm();
$this->setUpInstallConfigureForm();
// If we've got to this point the site is installed using the regular
// installation workflow.
$this->isInstalled = TRUE;
}
示例14: terminate
public function terminate()
{
if ($this->booted) {
$response = Response::create('');
$this->kernel->terminate($this->request, $response);
}
}
示例15: discoverServiceProviders
/**
* {@inheritdoc}
*/
public function discoverServiceProviders()
{
parent::discoverServiceProviders();
// The test runner does not require an installed Drupal site to exist.
// Therefore, its environment is identical to that of the early installer.
$this->serviceProviderClasses['app']['Test'] = 'Drupal\\Core\\Installer\\InstallerServiceProvider';
}