Issue #2498293 by cilefen, Fabianx: Only allow lowercase service and parameter names
parent
fde956156b
commit
c219ec8fcd
|
@ -41,6 +41,9 @@ class ContainerBuilder extends SymfonyContainerBuilder {
|
||||||
* services in a frozen builder.
|
* services in a frozen builder.
|
||||||
*/
|
*/
|
||||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
|
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);
|
SymfonyContainer::set($id, $service, $scope);
|
||||||
|
|
||||||
// Ensure that the _serviceId property is set on synthetic services as well.
|
// Ensure that the _serviceId property is set on synthetic services as well.
|
||||||
|
@ -49,6 +52,26 @@ class ContainerBuilder extends SymfonyContainerBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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.
|
* Synchronizes a service change.
|
||||||
*
|
*
|
||||||
|
|
|
@ -977,7 +977,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
||||||
*/
|
*/
|
||||||
protected function getServicesToPersist(ContainerInterface $container) {
|
protected function getServicesToPersist(ContainerInterface $container) {
|
||||||
$persist = array();
|
$persist = array();
|
||||||
foreach ($container->getParameter('persistIds') as $id) {
|
foreach ($container->getParameter('persist_ids') as $id) {
|
||||||
// It's pointless to persist services not yet initialized.
|
// It's pointless to persist services not yet initialized.
|
||||||
if ($container->initialized($id)) {
|
if ($container->initialized($id)) {
|
||||||
$persist[$id] = $container->get($id);
|
$persist[$id] = $container->get($id);
|
||||||
|
@ -1127,7 +1127,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
||||||
$persist_ids[] = $id;
|
$persist_ids[] = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$container->setParameter('persistIds', $persist_ids);
|
$container->setParameter('persist_ids', $persist_ids);
|
||||||
|
|
||||||
$container->compile();
|
$container->compile();
|
||||||
return $container;
|
return $container;
|
||||||
|
|
|
@ -53,12 +53,12 @@ class DefaultConfigTest extends KernelTestBase {
|
||||||
*/
|
*/
|
||||||
public function containerBuild(ContainerBuilder $container) {
|
public function containerBuild(ContainerBuilder $container) {
|
||||||
parent::containerBuild($container);
|
parent::containerBuild($container);
|
||||||
$container->register('DefaultConfigTest.schema_storage')
|
$container->register('default_config_test.schema_storage')
|
||||||
->setClass('\Drupal\config_test\TestInstallStorage')
|
->setClass('\Drupal\config_test\TestInstallStorage')
|
||||||
->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
|
->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
|
||||||
|
|
||||||
$definition = $container->getDefinition('config.typed');
|
$definition = $container->getDefinition('config.typed');
|
||||||
$definition->replaceArgument(1, new Reference('DefaultConfigTest.schema_storage'));
|
$definition->replaceArgument(1, new Reference('default_config_test.schema_storage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,7 @@ form_test.route2:
|
||||||
form_test.route3:
|
form_test.route3:
|
||||||
path: '/form-test/object-service-builder'
|
path: '/form-test/object-service-builder'
|
||||||
defaults:
|
defaults:
|
||||||
_form: 'form_test.form.serviceForm'
|
_form: 'form_test.form.serviceform'
|
||||||
requirements:
|
requirements:
|
||||||
_access: 'TRUE'
|
_access: 'TRUE'
|
||||||
|
|
||||||
|
|
|
@ -38,4 +38,36 @@ class ContainerBuilderTest extends UnitTestCase {
|
||||||
$this->assertEquals('bar', $class->_serviceId);
|
$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');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue