本文整理汇总了PHP中Zend\View\HelperPluginManager::setFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP HelperPluginManager::setFactory方法的具体用法?PHP HelperPluginManager::setFactory怎么用?PHP HelperPluginManager::setFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\HelperPluginManager
的用法示例。
在下文中一共展示了HelperPluginManager::setFactory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectOverrideFactories
/**
* @param HelperPluginManager $plugins
* @param ContainerInterface $container
* @return HelperPluginManager
*/
private function injectOverrideFactories(HelperPluginManager $plugins, ContainerInterface $container)
{
$urlFactory = $this->createUrlHelperFactory($container);
$plugins->setFactory(ViewHelper\Url::class, $urlFactory);
$plugins->setFactory('zendviewhelperurl', $urlFactory);
$basePathFactory = $this->createBasePathHelperFactory($container);
$plugins->setFactory(ViewHelper\BasePath::class, $basePathFactory);
$plugins->setFactory('zendviewhelperbasepath', $basePathFactory);
return $plugins;
}
示例2: __invoke
/**
* @param ContainerInterface $container
* @throws \RuntimeException
* @return HelperPluginManager
*/
public function __invoke(ContainerInterface $container)
{
$helperPluginManager = new HelperPluginManager();
$config = $container->has('config') ? $container->get('config') : [];
if (isset($config['templates']['plugins'])) {
foreach ($config['templates']['plugins'] as $pluginName => $serviceName) {
$helperPluginManager->setFactory($pluginName, function () use($container, $serviceName) {
return $container->get($serviceName);
});
}
}
return $helperPluginManager;
}
示例3: injectOverrideFactories
/**
* Inject override factories into the plugin manager.
*
* @param HelperPluginManager $plugins
* @param ContainerInterface $services
* @return HelperPluginManager
*/
private function injectOverrideFactories(HelperPluginManager $plugins, ContainerInterface $services)
{
// Configure URL view helper
$urlFactory = $this->createUrlHelperFactory($services);
$plugins->setFactory(ViewHelper\Url::class, $urlFactory);
$plugins->setFactory('zendviewhelperurl', $urlFactory);
// Configure base path helper
$basePathFactory = $this->createBasePathHelperFactory($services);
$plugins->setFactory(ViewHelper\BasePath::class, $basePathFactory);
$plugins->setFactory('zendviewhelperbasepath', $basePathFactory);
// Configure doctype view helper
$doctypeFactory = $this->createDoctypeHelperFactory($services);
$plugins->setFactory(ViewHelper\Doctype::class, $doctypeFactory);
$plugins->setFactory('zendviewhelperdoctype', $doctypeFactory);
return $plugins;
}
示例4: injectHelpers
/**
* Inject helpers into the PhpRenderer instance.
*
* If a HelperPluginManager instance is present in the container, uses that;
* otherwise, instantiates one.
*
* In each case, injects with the custom url/serverurl implementations.
*
* @param PhpRenderer $renderer
* @param ContainerInterface $container
*/
private function injectHelpers(PhpRenderer $renderer, HelperPluginManager $manager)
{
$manager->setFactory('url', function () use($container) {
if (!$container->has(BaseUrlHelper::class)) {
throw new Exception\MissingHelperException(sprintf('An instance of %s is required in order to create the "url" view helper; not found', BaseUrlHelper::class));
}
return new UrlHelper($container->get(BaseUrlHelper::class));
});
$manager->setFactory('serverurl', function () use($container) {
if (!$container->has(BaseServerUrlHelper::class)) {
throw new Exception\MissingHelperException(sprintf('An instance of %s is required in order to create the "url" view helper; not found', BaseServerUrlHelper::class));
}
return new ServerUrlHelper($container->get(BaseServerUrlHelper::class));
});
$renderer->setHelperPluginManager($manager);
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->viewHelperPluginManager = new HelperPluginManager();
$this->viewHelperPluginManager->setFactory('hangerSnippet', 'HangerSnippet\\Service\\SnippetHelperServiceFactory');
}