本文整理汇总了PHP中Drupal\Core\DrupalKernel类的典型用法代码示例。如果您正苦于以下问题:PHP DrupalKernel类的具体用法?PHP DrupalKernel怎么用?PHP DrupalKernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DrupalKernel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:11,代码来源:DiscoverServiceProvidersTest.php
示例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.")));
}
}
开发者ID:AohRveTPV,项目名称:security_review,代码行数:35,代码来源:BaseUrl.php
示例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);
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:11,代码来源:ValidateHostnameTest.php
示例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');
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:8,代码来源:StreamWrapperTest.php
示例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();
}
开发者ID:nuwud,项目名称:drush,代码行数:9,代码来源:DrupalBoot8.php
示例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();
}
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:10,代码来源:StreamWrapperTest.php
示例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());
});
}
开发者ID:philrennie,项目名称:boris-loader,代码行数:14,代码来源:Drupal8.php
示例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();
}
开发者ID:sarahwillem,项目名称:OD8,代码行数:21,代码来源:InstallerExistingSettingsNoProfileTest.php
示例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;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:31,代码来源:DrupalKernelTest.php
示例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));
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:25,代码来源:DrupalKernelTest.php
示例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();
}
开发者ID:dliau,项目名称:DrupalDriver,代码行数:21,代码来源:Drupal8.php
示例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;
}
开发者ID:php-pm,项目名称:php-pm-drupal,代码行数:21,代码来源:Drupal.php
示例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;
}
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:26,代码来源:ConfigInstallerTestBase.php
示例14: setUp
protected function setUp()
{
parent::setUp();
// Change the root path which Update Manager uses to install and update
// projects to be inside the testing site directory. See
// \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
// test child site.
$request = \Drupal::request();
$update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
$this->container->set('update.root', $update_root);
\Drupal::setContainer($this->container);
// Create the directories within the root path within which the Update
// Manager will install projects.
foreach (drupal_get_updaters() as $updater_info) {
$updater = $updater_info['class'];
$install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
if (!is_dir($install_directory)) {
mkdir($install_directory);
}
}
}
开发者ID:318io,项目名称:318-io,代码行数:21,代码来源:UpdateTestBase.php
示例15: setUp
/**
* {@inheritdoc}
*
* Fully configures a preexisting settings.php file 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);
// During interactive install we'll change this to a different profile and
// this test will ensure that the new value is written to settings.php.
$this->settings['settings']['install_profile'] = (object) array('value' => 'minimal', '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);
// Use the kernel to find the site path because the site.path service should
// not be available at this point in the install process.
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
// Pre-configure config directories.
$this->settings['config_directories'] = array(CONFIG_SYNC_DIRECTORY => (object) array('value' => $site_path . '/files/config_sync', 'required' => TRUE));
mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
parent::setUp();
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:27,代码来源:InstallerExistingSettingsTest.php
示例16: validateDrupalSite
/**
* {@inheritdoc}
*/
public function validateDrupalSite()
{
if ('default' !== $this->uri) {
// Fake the necessary HTTP headers that Drupal needs:
$drupal_base_url = parse_url($this->uri);
// If there's no url scheme set, add http:// and re-parse the url
// so the host and path values are set accurately.
if (!array_key_exists('scheme', $drupal_base_url)) {
$drupal_base_url = parse_url($this->uri);
}
// Fill in defaults.
$drupal_base_url += array('path' => NULL, 'host' => NULL, 'port' => NULL);
$_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
if ($drupal_base_url['port']) {
$_SERVER['HTTP_HOST'] .= ':' . $drupal_base_url['port'];
}
$_SERVER['SERVER_PORT'] = $drupal_base_url['port'];
if (array_key_exists('path', $drupal_base_url)) {
$_SERVER['PHP_SELF'] = $drupal_base_url['path'] . '/index.php';
} else {
$_SERVER['PHP_SELF'] = '/index.php';
}
} else {
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
}
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = NULL;
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['HTTP_USER_AGENT'] = NULL;
$conf_path = DrupalKernel::findSitePath(Request::createFromGlobals());
$conf_file = $this->drupalRoot . "/{$conf_path}/settings.php";
if (!file_exists($conf_file)) {
throw new BootstrapException(sprintf('Could not find a Drupal settings.php file at "%s"', $conf_file));
}
}
开发者ID:lmakarov,项目名称:DrupalDriver,代码行数:40,代码来源:Drupal8.php
示例17: 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' => '[email protected]', '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;
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:71,代码来源:InstallerTestBase.php
示例18: scan
/**
* Discovers available extensions of a given type.
*
* Finds all extensions (modules, themes, etc) that exist on the site. It
* searches in several locations. For instance, to discover all available
* modules:
* @code
* $listing = new ExtensionDiscovery(\Drupal::root());
* $modules = $listing->scan('module');
* @endcode
*
* The following directories will be searched (in the order stated):
* - the core directory; i.e., /core
* - the installation profile directory; e.g., /core/profiles/standard
* - the legacy site-wide directory; i.e., /sites/all
* - the site-wide directory; i.e., /
* - the site-specific directory; e.g., /sites/example.com
*
* The information is returned in an associative array, keyed by the extension
* name (without .info.yml extension). Extensions found later in the search
* will take precedence over extensions found earlier - unless they are not
* compatible with the current version of Drupal core.
*
* @param string $type
* The extension type to search for. One of 'profile', 'module', 'theme', or
* 'theme_engine'.
* @param bool $include_tests
* (optional) Whether to explicitly include or exclude test extensions. By
* default, test extensions are only discovered when in a test environment.
*
* @return \Drupal\Core\Extension\Extension[]
* An associative array of Extension objects, keyed by extension name.
*/
public function scan($type, $include_tests = NULL)
{
// Determine the installation profile directories to scan for extensions,
// unless explicit profile directories have been set. Exclude profiles as we
// cannot have profiles within profiles.
if (!isset($this->profileDirectories) && $type != 'profile') {
$this->setProfileDirectoriesFromSettings();
}
// Search the core directory.
$searchdirs[static::ORIGIN_CORE] = 'core';
// Search the legacy sites/all directory.
$searchdirs[static::ORIGIN_SITES_ALL] = 'sites/all';
// Search for contributed and custom extensions in top-level directories.
// The scan uses a whitelist to limit recursion to the expected extension
// type specific directory names only.
$searchdirs[static::ORIGIN_ROOT] = '';
// Simpletest uses the regular built-in multi-site functionality of Drupal
// for running web tests. As a consequence, extensions of the parent site
// located in a different site-specific directory are not discovered in a
// test site environment, because the site directories are not the same.
// Therefore, add the site directory of the parent site to the search paths,
// so that contained extensions are still discovered.
// @see \Drupal\simpletest\WebTestBase::setUp()
if ($parent_site = Settings::get('test_parent_site')) {
$searchdirs[static::ORIGIN_PARENT_SITE] = $parent_site;
}
// Find the site-specific directory to search. Since we are using this
// method to discover extensions including profiles, we might be doing this
// at install time. Therefore Kernel service is not always available, but is
// preferred.
if (\Drupal::hasService('kernel')) {
$searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path');
} else {
$searchdirs[static::ORIGIN_SITE] = $this->sitePath ?: DrupalKernel::findSitePath(Request::createFromGlobals());
}
// Unless an explicit value has been passed, manually check whether we are
// in a test environment, in which case test extensions must be included.
// Test extensions can also be included for debugging purposes by setting a
// variable in settings.php.
if (!isset($include_tests)) {
$include_tests = Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua();
}
$files = array();
foreach ($searchdirs as $dir) {
// Discover all extensions in the directory, unless we did already.
if (!isset(static::$files[$dir][$include_tests])) {
static::$files[$dir][$include_tests] = $this->scanDirectory($dir, $include_tests);
}
// Only return extensions of the requested type.
if (isset(static::$files[$dir][$include_tests][$type])) {
$files += static::$files[$dir][$include_tests][$type];
}
}
// If applicable, filter out extensions that do not belong to the current
// installation profiles.
$files = $this->filterByProfileDirectories($files);
// Sort the discovered extensions by their originating directories.
$origin_weights = array_flip($searchdirs);
$files = $this->sort($files, $origin_weights);
// Process and return the list of extensions keyed by extension name.
return $this->process($files);
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:95,代码来源:ExtensionDiscovery.php
示例19: DrupalKernel
<?php
/**
* @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 Symfony\Component\HttpFoundation\Request;
$autoloader = (require_once 'autoload.php');
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
开发者ID:favish,项目名称:drupal-archetype,代码行数:17,代码来源:index.php
示例20: terminate
public function terminate()
{
if ($this->booted) {
$response = Response::create('');
$this->kernel->terminate($this->request, $response);
}
}
开发者ID:amira2r,项目名称:DrupalConsole,代码行数:7,代码来源:KernelHelper.php
注:本文中的Drupal\Core\DrupalKernel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论