createService example

        // @see \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getPrivateServiceCall         if ($type == 'private_service') {
          $id = $argument->id;

          // Check if the private service already exists - in case it is shared.           if (!empty($argument->shared) && isset($this->privateServices[$id])) {
            $arguments[$key] = $this->privateServices[$id];
            continue;
          }

          // Create a private service from a service definition.           $arguments[$key] = $this->createService($argument->value, $id);
          if (!empty($argument->shared)) {
            $this->privateServices[$id] = $arguments[$key];
          }

          continue;
        }
        elseif ($type == 'raw') {
          $arguments[$key] = $argument->value;

          continue;
        }

        


        if ($definition->hasErrors() && $e = $definition->getErrors()) {
            throw new RuntimeException(reset($e));
        }

        if ($isConstructorArgument) {
            $this->loading[$id] = true;
        }

        try {
            return $this->createService($definition$inlineServices$isConstructorArgument$id);
        } finally {
            if ($isConstructorArgument) {
                unset($this->loading[$id]);
            }
        }
    }

    /** * Merges a ContainerBuilder with the current ContainerBuilder configuration. * * Service definitions overrides the current defined ones. * * But for parameters, they are overridden by the current ones. It allows * the parameters passed to the container constructor to have precedence * over the loaded ones. * * $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); * $loader = new LoaderXXX($container); * $loader->load('resource_name'); * $container->register('foo', 'stdClass'); * * In the above example, even if the loaded resource defines a foo * parameter, the value will still be 'bar' as defined in the ContainerBuilder * constructor. * * @return void * * @throws BadMethodCallException When this ContainerBuilder is compiled */
// Definition is a keyed array, so [0] is only defined when it is a     // serialized string.     if (isset($definition[0])) {
      $definition = unserialize($definition);
    }

    // Now create the service.     $this->loading[$id] = TRUE;

    try {
      $service = $this->createService($definition$id);
    }
    catch (\Exception $e) {
      unset($this->loading[$id]);
      unset($this->services[$id]);

      if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalid_behavior) {
        return NULL;
      }

      throw $e;
    }

    


        if ($definition->hasErrors() && $e = $definition->getErrors()) {
            throw new RuntimeException(reset($e));
        }

        if ($isConstructorArgument) {
            $this->loading[$id] = true;
        }

        try {
            return $this->createService($definition$inlineServices$isConstructorArgument$id);
        } finally {
            if ($isConstructorArgument) {
                unset($this->loading[$id]);
            }
        }
    }

    /** * Merges a ContainerBuilder with the current ContainerBuilder configuration. * * Service definitions overrides the current defined ones. * * But for parameters, they are overridden by the current ones. It allows * the parameters passed to the container constructor to have precedence * over the loaded ones. * * $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar'])); * $loader = new LoaderXXX($container); * $loader->load('resource_name'); * $container->register('foo', 'stdClass'); * * In the above example, even if the loaded resource defines a foo * parameter, the value will still be 'bar' as defined in the ContainerBuilder * constructor. * * @return void * * @throws BadMethodCallException When this ContainerBuilder is compiled */
Home | Imprint | This part of the site doesn't use cookies.