protected function getServiceCall($id, Reference $reference = null) { if ('service_container' === $id) { return '$this'; } if (null !== $reference && Container::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { return sprintf('$this->getService(\'%s\', Container::NULL_ON_INVALID_REFERENCE)', $id); } else { if ($this->container->hasAlias($id)) { $id = $this->container->getAlias($id); } if ($this->container->hasDefinition($id)) { return sprintf('$this->get%sService()', Container::camelize($id)); } return sprintf('$this->getService(\'%s\')', $id); } }
protected function addServiceAlias($alias, $id) { $name = Container::camelize($alias); $type = 'Object'; if ($this->container->hasDefinition($id)) { $class = $this->container->getDefinition($id)->getClass(); $type = 0 === strpos($class, '%') ? 'Object' : $class; } return <<<EOF /** * Gets the {$alias} service alias. * * @return {$type} An instance of the {$id} service */ protected function get{$name}Service() { return {$this->getServiceCall($id)}; } EOF; }