Commit c219ec8f authored by catch's avatar catch

Issue #2498293 by cilefen, Fabianx: Only allow lowercase service and parameter names

parent fde95615
......@@ -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.
*
......
......@@ -977,7 +977,7 @@ protected function initializeRequestGlobals(Request $request) {
*/
protected function getServicesToPersist(ContainerInterface $container) {
$persist = array();
foreach ($container->getParameter('persistIds') as $id) {
foreach ($container->getParameter('persist_ids') 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('persistIds', $persist_ids);
$container->setParameter('persist_ids', $persist_ids);
$container->compile();
return $container;
......
......@@ -53,12 +53,12 @@ protected function setUp() {
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
$container->register('DefaultConfigTest.schema_storage')
$container->register('default_config_test.schema_storage')
->setClass('\Drupal\config_test\TestInstallStorage')
->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY);
$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:
path: '/form-test/object-service-builder'
defaults:
_form: 'form_test.form.serviceForm'
_form: 'form_test.form.serviceform'
requirements:
_access: 'TRUE'
......
......@@ -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');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment