Verified Commit 1704f119 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2896993 by cburschka, andypost, mxr576, jedihe: Decorated services crash on serialization

(cherry picked from commit b16df24b)
parent 4f0778d2
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -16,12 +16,34 @@ class DependencySerializationTraitPass implements CompilerPassInterface {
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) {
    $decorations = new \SplPriorityQueue();
    $order = PHP_INT_MAX;

    foreach ($container->getDefinitions() as $service_id => $definition) {
      // Only add the property to services that are public (as private services
      // can not be reloaded through Container::get()) and are objects.
      if (!$definition->hasTag('parameter_service') && $definition->isPublic()) {
        $definition->setProperty('_serviceId', $service_id);
      }

      if ($decorated = $definition->getDecoratedService()) {
        $decorations->insert([$service_id, $definition], [$decorated[2], --$order]);
      }
    }

    foreach ($decorations as list($service_id, $definition)) {
      list($inner, $renamedId) = $definition->getDecoratedService();
      if (!$renamedId) {
        $renamedId = $service_id . '.inner';
      }

      $original = $container->getDefinition($inner);
      if ($original->isPublic()) {
        // The old service is renamed.
        $original->setProperty('_serviceId', $renamedId);
        // The decorating service takes over the old ID.
        $definition->setProperty('_serviceId', $inner);
      }
    }
  }

+5 −0
Original line number Diff line number Diff line
name: 'Decorated Service Test'
type: module
description: 'Support module for decorated service test.'
package: Testing
version: VERSION
+17 −0
Original line number Diff line number Diff line
services:
  test_service:
    class: 'Drupal\decorated_service_test\TestService'
  test_service_decorator:
    class: 'Drupal\decorated_service_test\TestServiceDecorator'
    public: false
    decorates: test_service
  test_service2:
    class: 'Drupal\decorated_service_test\TestService'
  test_service2_decorator:
    class: 'Drupal\decorated_service_test\TestServiceDecorator'
    public: false
    decorates: test_service2
  test_service2_decorator2:
    class: 'Drupal\decorated_service_test\TestServiceDecorator'
    public: false
    decorates: test_service2
+7 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\decorated_service_test;

class TestService {

}
+7 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\decorated_service_test;

class TestServiceDecorator extends TestService {

}
Loading