/** * Gets a service. * * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * * @return object The associated service * * @throws \InvalidArgumentException if the service is not defined * @throws \LogicException if the service has a circular reference to itself * * @see Reference */ public function getService($id, $invalidBehavior = Container::EXCEPTION_ON_INVALID_REFERENCE) { try { return parent::getService($id, Container::EXCEPTION_ON_INVALID_REFERENCE); } catch (\InvalidArgumentException $e) { if (isset($this->loading[$id])) { throw new \LogicException(sprintf('The service "%s" has a circular reference to itself.', $id)); } if (!$this->hasDefinition($id) && isset($this->aliases[$id])) { return $this->getService($this->aliases[$id]); } try { $definition = $this->getDefinition($id); } catch (\InvalidArgumentException $e) { if (Container::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { return null; } throw $e; } $this->loading[$id] = true; $service = $this->createService($definition, $id); unset($this->loading[$id]); return $service; } }
/** * Execute validator * * @param Container $container * @param string $validatorName * @param mixed $value * @return string */ public function validate(Container $container, $validatorName, $value) { $validator = new $validatorName(); return $container->getService('validator')->validate($validator, $value); }
/** * Get service * * @param string $name service name * @return object */ public function getService($name) { return $this->container->getService($name); }
/** * * @param Container $container * @param string $mapperName * @param mixed $value * @return mixed */ public function cast(Container $container, $mapperName, $value) { return $container->getService('mapper')->cast($mapperName, $value); }