feature #26308 [Config] Introduce BuilderAwareInterface (ro0NL)

This PR was squashed before being merged into the 4.1-dev branch (closes #26308).

Discussion
----------

[Config] Introduce BuilderAwareInterface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Split `ParentNodeDefinitionInterface` into `BuilderAwareInterface`.

Use case is custom node definition  (extended from VariableNodeDef) with a corresponding prototyped array node.

To set the actual prototype i need the builder at definition level, provided by `ParentNodeDefinitionInterface`. However i don't implement `children()` + `append()`, i solely need the builder scope.

To go after #26297

Commits
-------

1353694 [Config] Introduce BuilderAwareInterface
This commit is contained in:
Nicolas Grekas 2018-03-19 17:48:53 +01:00
commit 6059bdc80e
3 changed files with 24 additions and 4 deletions

View File

@ -0,0 +1,22 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Config\Definition\Builder;
/**
* An interface that can be implemented by nodes which build other nodes.
*
* @author Roland Franssen <franssen.roland@gmail.com>
*/
interface BuilderAwareInterface
{
public function setBuilder(NodeBuilder $builder);
}

View File

@ -179,7 +179,7 @@ class NodeBuilder implements NodeParentInterface
*/
public function append(NodeDefinition $node)
{
if ($node instanceof ParentNodeDefinitionInterface) {
if ($node instanceof BuilderAwareInterface) {
$builder = clone $this;
$builder->setParent(null);
$node->setBuilder($builder);

View File

@ -18,7 +18,7 @@ namespace Symfony\Component\Config\Definition\Builder;
*
* @method NodeDefinition[] getChildNodeDefinitions() should be implemented since 4.1
*/
interface ParentNodeDefinitionInterface
interface ParentNodeDefinitionInterface extends BuilderAwareInterface
{
/**
* @return NodeBuilder
@ -26,6 +26,4 @@ interface ParentNodeDefinitionInterface
public function children();
public function append(NodeDefinition $node);
public function setBuilder(NodeBuilder $builder);
}