本文整理汇总了PHP中Drupal\Core\DrupalKernel::createFromRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalKernel::createFromRequest方法的具体用法?PHP DrupalKernel::createFromRequest怎么用?PHP DrupalKernel::createFromRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\DrupalKernel
的用法示例。
在下文中一共展示了DrupalKernel::createFromRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getKernel
/**
* @return \Drupal\Core\DrupalKernel
*/
public function getKernel()
{
if (!$this->kernel) {
$this->request = Request::createFromGlobals();
$this->kernel = DrupalKernel::createFromRequest($this->request, $this->class_loader, $this->environment);
}
return $this->kernel;
}
示例2:
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();
}
示例3: createFromRequest
/**
* {@inheritdoc}
*/
public static function createFromRequest(Request $request, ClassLoader $class_loader, $environment, $allow_dumping = TRUE)
{
// Include our bootstrap file.
require_once __DIR__ . '/../../../../includes/bootstrap.inc';
// Exit if we should be in a test environment but aren't.
if (!drupal_valid_test_ua()) {
header($request->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
exit;
}
return parent::createFromRequest($request, $class_loader, $environment, $allow_dumping);
}
示例4: 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());
});
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
示例8: 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;
}
示例9: initKernel
/**
* Initializes the kernel after installation.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* Request object.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
* The container.
*/
protected function initKernel(Request $request)
{
$this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
$this->kernel->prepareLegacyRequest($request);
// Force the container to be built from scratch instead of loaded from the
// disk. This forces us to not accidentally load the parent site.
return $this->kernel->rebuildContainer();
}
示例10: setUp
/**
* Overrides WebTestBase::setUp().
*/
protected function setUp()
{
$this->isInstalled = FALSE;
// Define information about the user 1 account.
$this->root_user = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => 'admin@example.com', 'pass_raw' => $this->randomMachineName()));
// If any $settings are defined for this test, copy and prepare an actual
// settings.php, so as to resemble a regular installation.
if (!empty($this->settings)) {
// Not using File API; a potential error must trigger a PHP warning.
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
$this->writeSettings($this->settings);
}
// Note that WebTestBase::installParameters() returns form input values
// suitable for a programmed drupal_form_submit().
// @see WebTestBase::translatePostValues()
$this->parameters = $this->installParameters();
// Set up a minimal container (required by WebTestBase).
// @see install_begin_request()
$request = Request::create($GLOBALS['base_url'] . '/core/install.php');
$this->container = new ContainerBuilder();
$request_stack = new RequestStack();
$request_stack->push($request);
$this->container->set('request_stack', $request_stack);
$this->container->setParameter('language.default_values', Language::$defaultValues);
$this->container->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')->addArgument('%language.default_values%');
$this->container->register('language_manager', 'Drupal\\Core\\Language\\LanguageManager')->addArgument(new Reference('language.default'));
$this->container->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')->addArgument(new Reference('language_manager'));
\Drupal::setContainer($this->container);
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
// Select language.
$this->setUpLanguage();
// Select profile.
$this->setUpProfile();
// Configure settings.
$this->setUpSettings();
// @todo Allow test classes based on this class to act on further installer
// screens.
// Configure site.
$this->setUpSite();
// Import new settings.php written by the installer.
$request = Request::createFromGlobals();
$class_loader = (require DRUPAL_ROOT . '/core/vendor/autoload.php');
Settings::initialize(DrupalKernel::findSitePath($request), $class_loader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
// After writing settings.php, the installer removes write permissions
// from the site directory. To allow drupal_generate_test_ua() to write
// a file containing the private key for drupal_valid_test_ua(), the site
// directory has to be writable.
// WebTestBase::tearDown() will delete the entire test site directory.
// Not using File API; a potential error must trigger a PHP warning.
chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777);
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel->prepareLegacyRequest($request);
$this->container = $this->kernel->getContainer();
$config = $this->container->get('config.factory');
// Manually configure the test mail collector implementation to prevent
// tests from sending out e-mails and collect them in state instead.
$config->get('system.mail')->set('interface.default', 'test_mail_collector')->save();
// When running from run-tests.sh we don't get an empty current path which
// would indicate we're on the home page.
$path = current_path();
if (empty($path)) {
_current_path('run-tests');
}
$this->isInstalled = TRUE;
}
示例11: installDrupal
/**
* Installs Drupal into the Simpletest site.
*/
public function installDrupal()
{
// Define information about the user 1 account.
$this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => 'admin@example.com', 'passRaw' => $this->randomMachineName()));
// The child site derives its session name from the database prefix when
// running web tests.
$this->generateSessionName($this->databasePrefix);
// Get parameters for install_drupal() before removing global variables.
$parameters = $this->installParameters();
// Prepare installer settings that are not install_drupal() parameters.
// Copy and prepare an actual settings.php, so as to resemble a regular
// installation.
// Not using File API; a potential error must trigger a PHP warning.
$directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
// All file system paths are created by System module during installation.
// @see system_requirements()
// @see TestBase::prepareEnvironment()
$settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE);
$this->writeSettings($settings);
// Allow for test-specific overrides.
$settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSiteDirectory . '/settings.testing.php';
if (file_exists($settings_testing_file)) {
// Copy the testing-specific settings.php overrides in place.
copy($settings_testing_file, $directory . '/settings.testing.php');
// Add the name of the testing class to settings.php and include the
// testing specific overrides.
file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
}
$settings_services_file = DRUPAL_ROOT . '/' . $this->originalSiteDirectory . '/testing.services.yml';
if (file_exists($settings_services_file)) {
// Copy the testing-specific service overrides in place.
copy($settings_services_file, $directory . '/services.yml');
}
// Since Drupal is bootstrapped already, install_begin_request() will not
// bootstrap into DRUPAL_BOOTSTRAP_CONFIGURATION (again). Hence, we have to
// reload the newly written custom settings.php manually.
Settings::initialize(DRUPAL_ROOT, $directory, $this->classLoader);
// Execute the non-interactive installer.
require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
install_drupal($parameters);
// Import new settings.php written by the installer.
Settings::initialize(DRUPAL_ROOT, $directory, $this->classLoader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
// After writing settings.php, the installer removes write permissions from
// the site directory. To allow drupal_generate_test_ua() to write a file
// containing the private key for drupal_valid_test_ua(), the site directory
// has to be writable.
// TestBase::restoreEnvironment() will delete the entire site directory. Not
// using File API; a potential error must trigger a PHP warning.
chmod($directory, 0777);
$request = \Drupal::request();
$this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
$this->kernel->prepareLegacyRequest($request);
// Force the container to be built from scratch instead of loaded from the
// disk. This forces us to not accidentally load the parent site.
$container = $this->kernel->rebuildContainer();
$config = $container->get('config.factory');
// Manually create and configure private and temporary files directories.
// While these could be preset/enforced in settings.php like the public
// files directory above, some tests expect them to be configurable in the
// UI. If declared in settings.php, they would no longer be configurable.
file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY);
$config->getEditable('system.file')->set('path.private', $this->privateFilesDirectory)->set('path.temporary', $this->tempFilesDirectory)->save();
// Manually configure the test mail collector implementation to prevent
// tests from sending out emails and collect them in state instead.
// While this should be enforced via settings.php prior to installation,
// some tests expect to be able to test mail system implementations.
$config->getEditable('system.mail')->set('interface.default', 'test_mail_collector')->save();
// By default, verbosely display all errors and disable all production
// environment optimizations for all tests to avoid needless overhead and
// ensure a sane default experience for test authors.
// @see https://www.drupal.org/node/2259167
$config->getEditable('system.logging')->set('error_level', 'verbose')->save();
$config->getEditable('system.performance')->set('css.preprocess', FALSE)->set('js.preprocess', FALSE)->save();
// Collect modules to install.
$class = get_class($this);
$modules = array();
while ($class) {
if (property_exists($class, 'modules')) {
$modules = array_merge($modules, $class::$modules);
}
$class = get_parent_class($class);
}
if ($modules) {
$modules = array_unique($modules);
$success = $container->get('module_installer')->install($modules, TRUE);
$this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
$this->rebuildContainer();
}
// Reset/rebuild all data structures after enabling the modules, primarily
// to synchronize all data structures and caches between the test runner and
// the child site.
// Affects e.g. StreamWrapperManagerInterface::getWrappers().
//.........这里部分代码省略.........
示例12: dirname
<?php
/**
* @file
* Handles counts of node views via AJAX with minimal bootstrap.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
chdir('../../..');
$autoloader = (require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php');
$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod');
$kernel->boot();
$views = $kernel->getContainer()->get('config.factory')->get('statistics.settings')->get('count_content_views');
if ($views) {
$nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
if ($nid) {
\Drupal::database()->merge('node_counter')->key('nid', $nid)->fields(array('daycount' => 1, 'totalcount' => 1, 'timestamp' => REQUEST_TIME))->expression('daycount', 'daycount + 1')->expression('totalcount', 'totalcount + 1')->execute();
}
}
示例13: catch
/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
*/
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$autoloader = (require_once 'autoload.php');
try {
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$response = $kernel->handle($request)->prepare($request)->send();
$kernel->terminate($request, $response);
} catch (HttpExceptionInterface $e) {
$response = new Response($e->getMessage(), $e->getStatusCode());
$response->prepare($request)->send();
} catch (Exception $e) {
$message = 'If you have just changed code (for example deployed a new module or moved an existing one) read <a href="http://drupal.org/documentation/rebuild">http://drupal.org/documentation/rebuild</a>';
if (Settings::get('rebuild_access', FALSE)) {
$rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
$message .= " or run the <a href=\"{$rebuild_path}\">rebuild script</a>";
}
// Set the response code manually. Otherwise, this response will default to a
// 200.
http_response_code(500);
print $message;
示例14: setUp
/**
* Sets up a Drupal site for running functional and integration tests.
*
* Installs Drupal with the installation profile specified in
* \Drupal\simpletest\WebTestBase::$profile into the prefixed database.
*
* Afterwards, installs any additional modules specified in the static
* \Drupal\simpletest\WebTestBase::$modules property of each class in the
* class hierarchy.
*
* After installation all caches are flushed and several configuration values
* are reset to the values of the parent site executing the test, since the
* default values may be incompatible with the environment in which tests are
* being executed.
*/
protected function setUp()
{
// When running tests through the Simpletest UI (vs. on the command line),
// Simpletest's batch conflicts with the installer's batch. Batch API does
// not support the concept of nested batches (in which the nested is not
// progressive), so we need to temporarily pretend there was no batch.
// Backup the currently running Simpletest batch.
$this->originalBatch = batch_get();
// Define information about the user 1 account.
$this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => 'admin@example.com', 'pass_raw' => $this->randomMachineName()));
// The child site derives its session name from the database prefix when
// running web tests.
$this->generateSessionName($this->databasePrefix);
// Reset the static batch to remove Simpletest's batch operations.
$batch =& batch_get();
$batch = array();
// Get parameters for install_drupal() before removing global variables.
$parameters = $this->installParameters();
// Prepare installer settings that are not install_drupal() parameters.
// Copy and prepare an actual settings.php, so as to resemble a regular
// installation.
// Not using File API; a potential error must trigger a PHP warning.
$directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
copy(DRUPAL_ROOT . '/sites/default/default.services.yml', $directory . '/services.yml');
// All file system paths are created by System module during installation.
// @see system_requirements()
// @see TestBase::prepareEnvironment()
$settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE);
$settings['settings']['file_private_path'] = (object) array('value' => $this->privateFilesDirectory, 'required' => TRUE);
// Save the original site directory path, so that extensions in the
// site-specific directory can still be discovered in the test site
// environment.
// @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
$settings['settings']['test_parent_site'] = (object) array('value' => $this->originalSite, 'required' => TRUE);
// Add the parent profile's search path to the child site's search paths.
// @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
$settings['conf']['simpletest.settings']['parent_profile'] = (object) array('value' => $this->originalProfile, 'required' => TRUE);
$settings['settings']['apcu_ensure_unique_prefix'] = (object) array('value' => FALSE, 'required' => TRUE);
$this->writeSettings($settings);
// Allow for test-specific overrides.
$settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
if (file_exists($settings_testing_file)) {
// Copy the testing-specific settings.php overrides in place.
copy($settings_testing_file, $directory . '/settings.testing.php');
// Add the name of the testing class to settings.php and include the
// testing specific overrides
file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
}
$settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
if (file_exists($settings_services_file)) {
// Copy the testing-specific service overrides in place.
copy($settings_services_file, $directory . '/services.yml');
}
if ($this->strictConfigSchema) {
// Add a listener to validate configuration schema on save.
$yaml = new \Symfony\Component\Yaml\Yaml();
$services = $yaml->parse($directory . '/services.yml');
$services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed'], 'tags' => [['name' => 'event_subscriber']]];
file_put_contents($directory . '/services.yml', $yaml->dump($services));
}
// Since Drupal is bootstrapped already, install_begin_request() will not
// bootstrap again. Hence, we have to reload the newly written custom
// settings.php manually.
$class_loader = (require DRUPAL_ROOT . '/autoload.php');
Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
// Execute the non-interactive installer.
require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
install_drupal($class_loader, $parameters);
// Import new settings.php written by the installer.
Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
// After writing settings.php, the installer removes write permissions
// from the site directory. To allow drupal_generate_test_ua() to write
// a file containing the private key for drupal_valid_test_ua(), the site
// directory has to be writable.
// TestBase::restoreEnvironment() will delete the entire site directory.
// Not using File API; a potential error must trigger a PHP warning.
chmod($directory, 0777);
$request = \Drupal::request();
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', TRUE);
$this->kernel->prepareLegacyRequest($request);
// Force the container to be built from scratch instead of loaded from the
//.........这里部分代码省略.........
示例15: createFromRequest
/**
* {@inheritdoc}
*/
public static function createFromRequest(Request $request, $class_loader, $environment = 'test_runner', $allow_dumping = TRUE)
{
return parent::createFromRequest($request, $class_loader, $environment);
}