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
c219ec8f
Commit
c219ec8f
authored
Jun 04, 2015
by
catch
Browse files
Issue
#2498293
by cilefen, Fabianx: Only allow lowercase service and parameter names
parent
fde95615
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
View file @
c219ec8f
...
...
@@ -41,6 +41,9 @@ public function __construct(ParameterBagInterface $parameterBag = NULL) {
* services in a frozen builder.
*/
public
function
set
(
$id
,
$service
,
$scope
=
self
::
SCOPE_CONTAINER
)
{
if
(
strtolower
(
$id
)
!==
$id
)
{
throw
new
\
InvalidArgumentException
(
"Service ID names must be lowercase:
$id
"
);
}
SymfonyContainer
::
set
(
$id
,
$service
,
$scope
);
// Ensure that the _serviceId property is set on synthetic services as well.
...
...
@@ -49,6 +52,26 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
}
}
/**
* {@inheritdoc}
*/
public
function
register
(
$id
,
$class
=
null
)
{
if
(
strtolower
(
$id
)
!==
$id
)
{
throw
new
\
InvalidArgumentException
(
"Service ID names must be lowercase:
$id
"
);
}
return
parent
::
register
(
$id
,
$class
);
}
/**
* {@inheritdoc}
*/
public
function
setParameter
(
$name
,
$value
)
{
if
(
strtolower
(
$name
)
!==
$name
)
{
throw
new
\
InvalidArgumentException
(
"Parameter names must be lowercase:
$name
"
);
}
parent
::
setParameter
(
$name
,
$value
);
}
/**
* Synchronizes a service change.
*
...
...
core/lib/Drupal/Core/DrupalKernel.php
View file @
c219ec8f
...
...
@@ -977,7 +977,7 @@ protected function initializeRequestGlobals(Request $request) {
*/
protected
function
getServicesToPersist
(
ContainerInterface
$container
)
{
$persist
=
array
();
foreach
(
$container
->
getParameter
(
'persist
I
ds'
)
as
$id
)
{
foreach
(
$container
->
getParameter
(
'persist
_i
ds'
)
as
$id
)
{
// It's pointless to persist services not yet initialized.
if
(
$container
->
initialized
(
$id
))
{
$persist
[
$id
]
=
$container
->
get
(
$id
);
...
...
@@ -1127,7 +1127,7 @@ protected function compileContainer() {
$persist_ids
[]
=
$id
;
}
}
$container
->
setParameter
(
'persist
I
ds'
,
$persist_ids
);
$container
->
setParameter
(
'persist
_i
ds'
,
$persist_ids
);
$container
->
compile
();
return
$container
;
...
...
core/modules/config/src/Tests/DefaultConfigTest.php
View file @
c219ec8f
...
...
@@ -53,12 +53,12 @@ protected function setUp() {
*/
public
function
containerBuild
(
ContainerBuilder
$container
)
{
parent
::
containerBuild
(
$container
);
$container
->
register
(
'
D
efault
C
onfig
T
est.schema_storage'
)
$container
->
register
(
'
d
efault
_c
onfig
_t
est.schema_storage'
)
->
setClass
(
'\Drupal\config_test\TestInstallStorage'
)
->
addArgument
(
InstallStorage
::
CONFIG_SCHEMA_DIRECTORY
);
$definition
=
$container
->
getDefinition
(
'config.typed'
);
$definition
->
replaceArgument
(
1
,
new
Reference
(
'
D
efault
C
onfig
T
est.schema_storage'
));
$definition
->
replaceArgument
(
1
,
new
Reference
(
'
d
efault
_c
onfig
_t
est.schema_storage'
));
}
/**
...
...
core/modules/system/tests/modules/form_test/form_test.routing.yml
View file @
c219ec8f
...
...
@@ -15,7 +15,7 @@ form_test.route2:
form_test.route3
:
path
:
'
/form-test/object-service-builder'
defaults
:
_form
:
'
form_test.form.service
F
orm'
_form
:
'
form_test.form.service
f
orm'
requirements
:
_access
:
'
TRUE'
...
...
core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
View file @
c219ec8f
...
...
@@ -38,4 +38,36 @@ public function testSet() {
$this
->
assertEquals
(
'bar'
,
$class
->
_serviceId
);
}
/**
* @covers ::set
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Service ID names must be lowercase: Bar
*/
public
function
testSetException
()
{
$container
=
new
ContainerBuilder
();
$class
=
new
BarClass
();
$container
->
set
(
'Bar'
,
$class
);
$this
->
assertNotEquals
(
'bar'
,
$class
->
_serviceId
);
}
/**
* @covers ::setParameter
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Parameter names must be lowercase: Buzz
*/
public
function
testSetParameterException
()
{
$container
=
new
ContainerBuilder
();
$container
->
setParameter
(
'Buzz'
,
'buzz'
);
}
/**
* @covers ::register
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Service ID names must be lowercase: Bar
*/
public
function
testRegisterException
()
{
$container
=
new
ContainerBuilder
();
$container
->
register
(
'Bar'
);
}
}
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