本文整理汇总了PHP中Container::getService方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::getService方法的具体用法?PHP Container::getService怎么用?PHP Container::getService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container::getService方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getService
/**
* 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;
}
}
示例2: validate
/**
* 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);
}
示例3: getService
/**
* Get service
*
* @param string $name service name
* @return object
*/
public function getService($name)
{
return $this->container->getService($name);
}
示例4: cast
/**
*
* @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);
}