Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
331cff98
Commit
331cff98
authored
May 06, 2016
by
catch
Browse files
Issue
#2631362
by Mile23, hussainweb: Inject DRUPAL_ROOT into DrupalKernel
parent
0b1a646f
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/DrupalKernel.php
View file @
331cff98
...
...
@@ -248,15 +248,18 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
* @param bool $allow_dumping
* (optional) FALSE to stop the container from being written to or read
* from disk. Defaults to TRUE.
* @param string $app_root
* (optional) The path to the application root as a string. If not supplied,
* the application root will be computed.
*
* @return static
*
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* In case the host name in the request is not trusted.
*/
public
static
function
createFromRequest
(
Request
$request
,
$class_loader
,
$environment
,
$allow_dumping
=
TRUE
)
{
$kernel
=
new
static
(
$environment
,
$class_loader
,
$allow_dumping
);
static
::
bootEnvironment
();
public
static
function
createFromRequest
(
Request
$request
,
$class_loader
,
$environment
,
$allow_dumping
=
TRUE
,
$app_root
=
NULL
)
{
$kernel
=
new
static
(
$environment
,
$class_loader
,
$allow_dumping
,
$app_root
);
static
::
bootEnvironment
(
$app_root
);
$kernel
->
initializeSettings
(
$request
);
return
$kernel
;
}
...
...
@@ -273,12 +276,28 @@ public static function createFromRequest(Request $request, $class_loader, $envir
* @param bool $allow_dumping
* (optional) FALSE to stop the container from being written to or read
* from disk. Defaults to TRUE.
* @param string $app_root
* (optional) The path to the application root as a string. If not supplied,
* the application root will be computed.
*/
public
function
__construct
(
$environment
,
$class_loader
,
$allow_dumping
=
TRUE
)
{
public
function
__construct
(
$environment
,
$class_loader
,
$allow_dumping
=
TRUE
,
$app_root
=
NULL
)
{
$this
->
environment
=
$environment
;
$this
->
classLoader
=
$class_loader
;
$this
->
allowDumping
=
$allow_dumping
;
$this
->
root
=
dirname
(
dirname
(
substr
(
__DIR__
,
0
,
-
strlen
(
__NAMESPACE__
))));
if
(
$app_root
===
NULL
)
{
$app_root
=
static
::
guessApplicationRoot
();
}
$this
->
root
=
$app_root
;
}
/**
* Determine the application root directory based on assumptions.
*
* @return string
* The application root.
*/
protected
static
function
guessApplicationRoot
()
{
return
dirname
(
dirname
(
substr
(
__DIR__
,
0
,
-
strlen
(
__NAMESPACE__
))));
}
/**
...
...
@@ -320,6 +339,9 @@ public function __construct($environment, $class_loader, $allow_dumping = TRUE)
* Defaults to TRUE. During initial installation, this is set to FALSE so
* that Drupal can detect a matching directory, then create a new
* settings.php file in it.
* @param string $app_root
* (optional) The path to the application root as a string. If not supplied,
* the application root will be computed.
*
* @return string
* The path of the matching directory.
...
...
@@ -332,18 +354,22 @@ public function __construct($environment, $class_loader, $allow_dumping = TRUE)
* @see default.settings.php
* @see example.sites.php
*/
public
static
function
findSitePath
(
Request
$request
,
$require_settings
=
TRUE
)
{
public
static
function
findSitePath
(
Request
$request
,
$require_settings
=
TRUE
,
$app_root
=
NULL
)
{
if
(
static
::
validateHostname
(
$request
)
===
FALSE
)
{
throw
new
BadRequestHttpException
();
}
if
(
$app_root
===
NULL
)
{
$app_root
=
static
::
guessApplicationRoot
();
}
// Check for a simpletest override.
if
(
$test_prefix
=
drupal_valid_test_ua
())
{
return
'sites/simpletest/'
.
substr
(
$test_prefix
,
10
);
}
// Determine whether multi-site functionality is enabled.
if
(
!
file_exists
(
DRUPAL_ROOT
.
'/sites/sites.php'
))
{
if
(
!
file_exists
(
$app_root
.
'/sites/sites.php'
))
{
return
'sites/default'
;
}
...
...
@@ -355,17 +381,17 @@ public static function findSitePath(Request $request, $require_settings = TRUE)
$http_host
=
$request
->
getHttpHost
();
$sites
=
array
();
include
DRUPAL_ROOT
.
'/sites/sites.php'
;
include
$app_root
.
'/sites/sites.php'
;
$uri
=
explode
(
'/'
,
$script_name
);
$server
=
explode
(
'.'
,
implode
(
'.'
,
array_reverse
(
explode
(
':'
,
rtrim
(
$http_host
,
'.'
)))));
for
(
$i
=
count
(
$uri
)
-
1
;
$i
>
0
;
$i
--
)
{
for
(
$j
=
count
(
$server
);
$j
>
0
;
$j
--
)
{
$dir
=
implode
(
'.'
,
array_slice
(
$server
,
-
$j
))
.
implode
(
'.'
,
array_slice
(
$uri
,
0
,
$i
));
if
(
isset
(
$sites
[
$dir
])
&&
file_exists
(
DRUPAL_ROOT
.
'/sites/'
.
$sites
[
$dir
]))
{
if
(
isset
(
$sites
[
$dir
])
&&
file_exists
(
$app_root
.
'/sites/'
.
$sites
[
$dir
]))
{
$dir
=
$sites
[
$dir
];
}
if
(
file_exists
(
DRUPAL_ROOT
.
'/sites/'
.
$dir
.
'/settings.php'
)
||
(
!
$require_settings
&&
file_exists
(
DRUPAL_ROOT
.
'/sites/'
.
$dir
)))
{
if
(
file_exists
(
$app_root
.
'/sites/'
.
$dir
.
'/settings.php'
)
||
(
!
$require_settings
&&
file_exists
(
$app_root
.
'/sites/'
.
$dir
)))
{
return
"sites/
$dir
"
;
}
}
...
...
@@ -877,15 +903,23 @@ protected function initializeContainer() {
*
* This method sets PHP environment options we want to be sure are set
* correctly for security or just saneness.
*
* @param string $app_root
* (optional) The path to the application root as a string. If not supplied,
* the application root will be computed.
*/
public
static
function
bootEnvironment
()
{
public
static
function
bootEnvironment
(
$app_root
=
NULL
)
{
if
(
static
::
$isEnvironmentInitialized
)
{
return
;
}
// Determine the application root if it's not supplied.
if
(
$app_root
===
NULL
)
{
$app_root
=
static
::
guessApplicationRoot
();
}
// Include our bootstrap file.
$core_root
=
dirname
(
dirname
(
dirname
(
__DIR__
)));
require_once
$core_root
.
'/includes/bootstrap.inc'
;
require_once
$app_root
.
'/core/includes/bootstrap.inc'
;
// Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
error_reporting
(
E_STRICT
|
E_ALL
);
...
...
@@ -929,7 +963,7 @@ public static function bootEnvironment() {
// Log fatal errors to the test site directory.
ini_set
(
'log_errors'
,
1
);
ini_set
(
'error_log'
,
DRUPAL_ROOT
.
'/sites/simpletest/'
.
substr
(
$test_prefix
,
10
)
.
'/error.log'
);
ini_set
(
'error_log'
,
$app_root
.
'/sites/simpletest/'
.
substr
(
$test_prefix
,
10
)
.
'/error.log'
);
// Ensure that a rewritten settings.php is used if opcache is on.
ini_set
(
'opcache.validate_timestamps'
,
'on'
);
...
...
core/lib/Drupal/Core/Test/TestRunnerKernel.php
View file @
331cff98
...
...
@@ -15,15 +15,18 @@ class TestRunnerKernel extends DrupalKernel {
/**
* {@inheritdoc}
*/
public
static
function
createFromRequest
(
Request
$request
,
$class_loader
,
$environment
=
'test_runner'
,
$allow_dumping
=
TRUE
)
{
return
parent
::
createFromRequest
(
$request
,
$class_loader
,
$environment
);
public
static
function
createFromRequest
(
Request
$request
,
$class_loader
,
$environment
=
'test_runner'
,
$allow_dumping
=
TRUE
,
$app_root
=
NULL
)
{
return
parent
::
createFromRequest
(
$request
,
$class_loader
,
$environment
,
$allow_dumping
,
$app_root
);
}
/**
* {@inheritdoc}
*/
public
function
__construct
(
$environment
,
$class_loader
)
{
parent
::
__construct
(
$environment
,
$class_loader
,
FALSE
);
public
function
__construct
(
$environment
,
$class_loader
,
$allow_dumping
=
FALSE
,
$app_root
=
NULL
)
{
// Force $allow_dumping to FALSE, because the test runner kernel should
// always have to rebuild its container, and potentially avoid isolation
// issues against the tests.
parent
::
__construct
(
$environment
,
$class_loader
,
FALSE
,
$app_root
);
// Prime the module list and corresponding Extension objects.
// @todo Remove System module. Needed because
...
...
@@ -73,7 +76,7 @@ public function boot() {
$this
->
getContainer
()
->
get
(
'stream_wrapper_manager'
)
->
register
();
// Create the build/artifacts directory if necessary.
include_once
DRUPAL_ROOT
.
'/core/includes/file.inc'
;
include_once
$this
->
getAppRoot
()
.
'/core/includes/file.inc'
;
if
(
!
is_dir
(
'public://simpletest'
))
{
mkdir
(
'public://simpletest'
,
0777
,
TRUE
);
}
...
...
core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
View file @
331cff98
...
...
@@ -126,12 +126,12 @@ public function testFindSitePath() {
]
]]);
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
));
$this
->
assertEquals
(
'sites/example'
,
DrupalKernel
::
findSitePath
(
$request
,
TRUE
,
$vfs_root
->
url
(
'drupal_root'
)));
$this
->
assertEquals
(
'sites/example'
,
DrupalKernel
::
findSitePath
(
$request
,
FALSE
,
$vfs_root
->
url
(
'drupal_root'
)));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment