本文整理匯總了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');
}