本文整理汇总了PHP中Drupal\Core\DrupalKernel::findSitePath方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalKernel::findSitePath方法的具体用法?PHP DrupalKernel::findSitePath怎么用?PHP DrupalKernel::findSitePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\DrupalKernel
的用法示例。
在下文中一共展示了DrupalKernel::findSitePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.")));
}
}
示例2: 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');
}
示例3: 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();
}
示例4: 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();
}
示例5: 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));
}
示例6:
function conf_path($require_settings = TRUE, $reset = FALSE, Request $request = NULL)
{
if (!isset($request)) {
if (\Drupal::hasRequest()) {
$request = \Drupal::request();
} else {
$request = Request::createFromGlobals();
}
}
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('kernel')->getSitePath();
}
if (!isset($site_path) || empty($site_path)) {
$site_path = DrupalKernel::findSitePath($request, $require_settings);
}
return $site_path;
}
示例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: 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);
}
}
}
示例10: 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();
}
示例11: exclude
/**
* @param $migration
*
* @return array
*/
public function exclude($migration)
{
$exclude = array('.', '..', '.git', '.svn', 'CVS', '.bzr');
// Exclude the migration directory.
$exclude[] = basename($migration['dir']);
if (!\Drupal::config('acquia_connector.settings')->get('migrate.files')) {
$exclude[] = \Drupal::service('file_system')->realpath(DrupalKernel::findSitePath(\Drupal::request()) . DIRECTORY_SEPARATOR . 'files');
}
return $exclude;
}
示例12: dirname
<?php
/**
* @file
* Rebuilds all Drupal caches even when Drupal itself does not work.
*
* Needs a token query argument which can be calculated using the
* scripts/rebuild_token_calculator.sh script.
*
* @see drupal_rebuild()
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
// Change the directory to the Drupal root.
chdir('..');
$autoloader = (require_once __DIR__ . '/vendor/autoload.php');
require_once __DIR__ . '/includes/utility.inc';
$request = Request::createFromGlobals();
// Manually resemble early bootstrap of DrupalKernel::boot().
require_once __DIR__ . '/includes/bootstrap.inc';
DrupalKernel::bootEnvironment();
Settings::initialize(DrupalKernel::findSitePath($request), $autoloader);
if (Settings::get('rebuild_access', FALSE) || $request->get('token') && $request->get('timestamp') && REQUEST_TIME - $request->get('timestamp') < 300 && $request->get('token') === Crypt::hmacBase64($request->get('timestamp'), Settings::get('hash_salt'))) {
drupal_rebuild($autoloader, $request);
drupal_set_message('Cache rebuild complete.');
}
$base_path = dirname(dirname($request->getBaseUrl()));
header('Location: ' . $base_path);
示例13: 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));
}
}
示例14: 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;
}
示例15: 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);
}