Last active
September 2, 2015 17:14
-
-
Save LionsAd/a10b7d8bb17cebe35d92 to your computer and use it in GitHub Desktop.
Test script to test container decoration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require "autoload.php"; | |
| use Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper; | |
| use Drupal\Core\DependencyInjection\ContainerBuilder; | |
| use Symfony\Component\DependencyInjection\Reference; | |
| /* | |
| foo: | |
| class: \stdClass | |
| lazy: true | |
| bar: | |
| public: false | |
| class: \stdClass | |
| decorates: foo | |
| arguments: ['@bar.inner'] | |
| ----- | |
| drupal.proxy_original_service.foo: | |
| class: \stdClass | |
| foo: | |
| class: \FooProxyClass | |
| arguments: ['@service_container'] | |
| bar: | |
| public: false | |
| class: \stdClass | |
| decorates: foo | |
| arguments ['@bar.inner'] | |
| */ | |
| $container = new ContainerBuilder(); | |
| $container->register('service_container', 'stdClass') | |
| ->setSynthetic(TRUE); | |
| $container->register('drupal.proxy_original_service.foo', 'stdClass'); | |
| $container->register('foo', 'stdClass') | |
| ->addArgument(new Reference('service_container')); | |
| $container->register('bar', 'stdClass') | |
| ->addArgument(new Reference('bar.inner')) | |
| ->setPublic(false) | |
| ->setDecoratedService('foo'); | |
| $container->compile(); | |
| $dumper = new PhpArrayDumper($container); | |
| $definition = $dumper->getArray(); | |
| print_r($definition); | |
| // ---------- OUTPUT | |
| /* | |
| Array | |
| ( | |
| [aliases] => Array | |
| ( | |
| ) | |
| [parameters] => Array | |
| ( | |
| ) | |
| [services] => Array | |
| ( | |
| [service_container] => Array | |
| ( | |
| [class] => stdClass | |
| [synthetic] => 1 | |
| [arguments_count] => 0 | |
| ) | |
| [drupal.proxy_original_service.foo] => Array | |
| ( | |
| [class] => stdClass | |
| [arguments_count] => 0 | |
| ) | |
| [foo] => Array | |
| ( | |
| [class] => stdClass | |
| [arguments] => Array | |
| ( | |
| [0] => stdClass Object | |
| ( | |
| [type] => private_service | |
| [id] => private__0c4884282dbf6aa8e79e3b09da20c4c06c9456f6 | |
| [value] => Array | |
| ( | |
| [class] => stdClass | |
| [public] => | |
| [arguments] => Array | |
| ( | |
| [0] => @service_container | |
| ) | |
| [arguments_count] => 1 | |
| ) | |
| [shared] => | |
| ) | |
| ) | |
| [arguments_count] => 1 | |
| ) | |
| ) | |
| [frozen] => 1 | |
| [machine_format] => | |
| ) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment