本文整理汇总了PHP中KServiceInterface::setAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP KServiceInterface::setAlias方法的具体用法?PHP KServiceInterface::setAlias怎么用?PHP KServiceInterface::setAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KServiceInterface
的用法示例。
在下文中一共展示了KServiceInterface::setAlias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
/**
* Force creation of a singleton.
*
* @param KConfigInterface $config An optional KConfig object with configuration options
* @param KServiceInterface $container A KServiceInterface object
*
* @return KServiceInstantiatable
*/
public static function getInstance(KConfigInterface $config, KServiceInterface $container)
{
if (!$container->has($config->service_identifier)) {
$classname = $config->service_identifier->classname;
$instance = new $classname($config);
$container->set($config->service_identifier, $instance);
$container->setAlias('application.dispatcher', $config->service_identifier);
}
return $container->get($config->service_identifier);
}
示例2: getInstance
/**
* Force creation of a singleton
*
* @param object An optional KConfig object with configuration options
* @param object A KServiceInterface object
* @return KDispatcherDefault
*/
public static function getInstance(KConfigInterface $config, KServiceInterface $container)
{
// Check if an instance with this identifier already exists or not
if (!$container->has($config->service_identifier)) {
//Create the singleton
$classname = $config->service_identifier->classname;
$instance = new $classname($config);
$container->set($config->service_identifier, $instance);
//Add the factory map to allow easy access to the singleton
$container->setAlias('dispatcher', $config->service_identifier);
}
return $container->get($config->service_identifier);
}