本文整理汇总了PHP中Zend\View\HelperPluginManager::get方法的典型用法代码示例。如果您正苦于以下问题:PHP HelperPluginManager::get方法的具体用法?PHP HelperPluginManager::get怎么用?PHP HelperPluginManager::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\HelperPluginManager
的用法示例。
在下文中一共展示了HelperPluginManager::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getViewHelper
/**
* Get a view helper from the manager.
*
* @param string $name
* @return TranslatorInterface
*/
protected function getViewHelper($name)
{
if (!$this->viewHelperManager instanceof HelperPluginManager) {
$this->viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
}
return $this->viewHelperManager->get($name);
}
示例2: applyViewHelpers
/**
* applies view helpers
*
* @todo refactor
* @param MvcEvent $e
* @return LayoutModifierListener
*/
public function applyViewHelpers(EventInterface $e)
{
$viewHelperInstructions = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_VIEW_HELPERS);
if ($viewHelperInstructions instanceof Config) {
$viewHelperInstructions = $viewHelperInstructions->toArray();
}
foreach ($this->helperConfig as $helper => $config) {
if (!isset($viewHelperInstructions[$helper])) {
continue;
}
$defaultMethod = isset($config['default_method']) ? $config['default_method'] : '__invoke';
$viewHelper = $this->viewHelperManager->get($helper);
$viewHelperInstructions[$helper] = (array) $viewHelperInstructions[$helper];
foreach ($viewHelperInstructions[$helper] as $value) {
if (!$value) {
continue;
}
$value = (array) $value;
$method = $this->getHelperMethod($value, $defaultMethod, $viewHelper);
$args = isset($value['args']) ? (array) $value['args'] : array_values($value);
$args[0] = $this->prepareHelperValue($args[0], $helper);
call_user_func_array([$viewHelper, $method], $args);
}
}
return $this;
}
示例3: __call
/**
* Invoke helper manager
*
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call($name, array $arguments = null)
{
if (null === $arguments) {
return $this->helperManager->get($name);
}
return call_user_func_array(array($this->helperManager->get($name), '__invoke'), $arguments);
}
示例4: getIdentityHelper
/**
* @return Identity
*/
protected function getIdentityHelper()
{
if (!$this->identityHelper instanceof Identity) {
$identity = $this->serviceLocator->get('identity');
$this->identityHelper = $identity;
}
return $this->identityHelper;
}
示例5: __call
public function __call($method, $argv)
{
$helper = $this->pluginManager->get($method);
if (is_callable($helper)) {
return call_user_func_array($helper, $argv);
}
return helper;
}
示例6: dateFormat
/**
* Format a date.
*
* If PHP's intl extension is not loaded, this helper will fall back on a
* predefined date and time format.
*
* @param DateTime $date
* @param string $dateType Use local DATE_FORMAT_* constants, not their
* corresponding constants in IntlDateFormatter.
* @param string $timeType Use local DATE_FORMAT_* constants, not their
* corresponding constants in IntlDateFormatter.
* @param string|null $locale Optional locale to use when formatting or
* parsing. Ignored when intl extension is not loaded.
* @param string|null $pattern Optional pattern to use when formatting or
* parsing. Possible patterns are documented at
* {@link http://userguide.icu-project.org/formatparse/datetime}.
* Ignored when intl extension is not loaded.
* @return string
*/
public function dateFormat(DateTime $date = null, $dateType = self::DATE_FORMAT_MEDIUM, $timeType = self::DATE_FORMAT_NONE, $locale = null, $pattern = null)
{
if (!$date) {
return null;
}
if (extension_loaded('intl')) {
// Map local constants to those in IntlDateFormatter.
$constMap = [self::DATE_FORMAT_NONE => \IntlDateFormatter::NONE, self::DATE_FORMAT_FULL => \IntlDateFormatter::FULL, self::DATE_FORMAT_LONG => \IntlDateFormatter::LONG, self::DATE_FORMAT_MEDIUM => \IntlDateFormatter::MEDIUM, self::DATE_FORMAT_SHORT => \IntlDateFormatter::SHORT];
$dateType = array_key_exists($dateType, $constMap) ? $constMap[$dateType] : \IntlDateFormatter::MEDIUM;
$timeType = array_key_exists($timeType, $constMap) ? $constMap[$timeType] : \IntlDateFormatter::NONE;
// Proxy to Zend's dateFormat helper.
$dateFormat = $this->viewHelperManager->get('dateFormat');
return $dateFormat($date, $dateType, $timeType, $locale, $pattern);
}
// Set the date format.
$dateFormat = '';
switch ($dateType) {
case self::DATE_FORMAT_NONE:
break;
case self::DATE_FORMAT_FULL:
$dateFormat .= 'l, F j, Y';
break;
case self::DATE_FORMAT_LONG:
$dateFormat .= 'F j, Y';
break;
case self::DATE_FORMAT_SHORT:
$dateFormat .= 'n/j/y';
break;
case self::DATE_FORMAT_MEDIUM:
default:
$dateFormat .= 'M j, Y';
break;
}
// Set the time format.
$timeFormat = '';
switch ($timeType) {
case self::DATE_FORMAT_FULL:
$timeFormat .= 'g:i:sa T';
break;
case self::DATE_FORMAT_LONG:
$timeFormat .= 'g:i:sa';
break;
case self::DATE_FORMAT_MEDIUM:
$timeFormat .= 'g:ia';
break;
case self::DATE_FORMAT_SHORT:
$timeFormat .= 'g:ia';
break;
case self::DATE_FORMAT_NONE:
default:
break;
}
return $date->format(trim("{$dateFormat} {$timeFormat}"));
}
示例7: perform_do
public function perform_do($args)
{
$name = array_shift($args);
if (is_string($name) == false) {
return null;
}
if ($this->helpers->has($name) == false) {
return null;
}
call_user_func_array($this->helpers->get($name), $args);
}
示例8: testInstance
/**
* A test class of instance
*/
public function testInstance()
{
$moduleConfig = (require __DIR__ . '/../../../config/module.config.php');
$serviceManager = new ServiceManager($moduleConfig['service_manager']);
$helperPluginManager = new HelperPluginManager($serviceManager, $moduleConfig['view_helpers']);
$signInForm = new SignInForm();
$formBuilderHelper1 = $helperPluginManager->get('formBuilder');
$formBuilderHelper1()->setToken('test token 1');
$this->assertInstanceOf(FormBuilder::class, $formBuilderHelper1());
$formBuilderHelper2 = $helperPluginManager->get(FormBuilderHelper::class);
$formBuilderHelper2()->setToken('test token 2');
$this->assertInstanceOf(FormBuilder::class, $formBuilderHelper2($signInForm));
$this->assertNotEquals($formBuilderHelper1(), $formBuilderHelper2());
}
示例9: testHelperService
/**
* Test if the helper is properly registered with the service manager
*/
public function testHelperService()
{
// Uppercase
$this->assertInstanceOf(static::_getHelperClass(), static::$_helperManager->get($this->_getHelperName()));
// Lowercase
$this->assertInstanceOf(static::_getHelperClass(), static::$_helperManager->get(lcfirst($this->_getHelperName())));
}
示例10: get
/**
* Retrieve a service from the manager by name
*
* Allows passing an array of options to use when creating the instance.
* createFromInvokable() will use these and pass them to the instance
* constructor if not null and a non-empty array.
*
* @param string $name
* @param array $options
* @param bool $usePeeringServiceManagers
* @return Helper\HelperInterface
*/
public function get($name, $options = array(), $usePeeringServiceManagers = true)
{
// Canonize invokable class from name
if (!$this->has($name) && !class_exists($name)) {
// Lookup in default invokable list
$cname = strtolower(str_replace(array('-', '_', ' ', '\\', '/'), '', $name));
if (isset($this->invokableList[$cname])) {
$invokableClass = 'Pi\\' . $this->invokableList[$cname];
if (!class_exists($invokableClass)) {
$invokableClass = 'Zend\\' . $this->invokableList[$cname];
}
$name = $invokableClass;
// Lookup in helper locations
} else {
$class = str_replace(' ', '', ucwords(str_replace(array('-', '_', '.', '\\', '/'), ' ', $name)));
foreach ($this->helperLocations as $location) {
$invokableClass = 'Pi\\' . $location . '\\' . $class;
if (class_exists($invokableClass)) {
$name = $invokableClass;
break;
} else {
$invokableClass = 'Zend\\' . $location . '\\' . $class;
if (class_exists($invokableClass)) {
$name = $invokableClass;
break;
}
}
}
}
}
return parent::get($name, $options, $usePeeringServiceManagers);
}
示例11: parseCountryMap
/**
* @return null|string
*/
public function parseCountryMap()
{
$mapOptions = ['clickable' => true, 'colorMin' => $this->getModuleOptions()->getCountryColorFaded(), 'colorMax' => $this->getModuleOptions()->getCountryColor(), 'focusOn' => ['x' => 0.5, 'y' => 0.5, 'scale' => 1.1], 'height' => '340px'];
/**
* @var $countryMap CountryMap
*/
$countryMap = $this->serviceLocator->get('countryMap');
return $countryMap([$this->getCountry()], null, $mapOptions);
}
示例12: __call
/**
* Provides access to view helpers.
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if (!isset($this->_helperCache[$method])) {
$helper = $this->_helperManager->get($method);
$helper->setView($this);
$this->_helperCache[$method] = $helper;
}
return call_user_func_array($this->_helperCache[$method], $args);
}
示例13: createImageUrl
/**
* This function produces the link in the end
*
* @return string
*/
public function createImageUrl()
{
/**
* @var $url Url
*/
$url = $this->serviceLocator->get('url');
/**
* @var $config array
*/
$config = $this->serviceLocator->getServiceLocator()->get('config');
$cdn = null;
if (isset($config['cdn']) && $config['cdn']['enable']) {
$cdn = $config['cdn']['address'];
}
$imageUrl = '<img src="%s%s" id="%s" class="%s" %s>';
$image = sprintf($imageUrl, $cdn, $url($this->router, $this->routerParams), $this->imageId, implode(' ', $this->classes), is_null($this->height) ? null : ' height="' . $this->height . 'px"');
if (!$this->lightBox) {
return $image;
} else {
return '<a href="' . $url($this->router, $this->routerParams) . '" data-lightbox="itea">' . $image . '</a>';
}
}
示例14: __invoke
/**
* createService
*
* Create the form group helper.
*
* @param HelperPluginManager $viewHelperManager The view helper plugin manager.
* @param string $name The name of the service to create.
* @param string $requestedName The requested name of the service to create.
*
* @return FormGroup
*/
public function __invoke(HelperPluginManager $viewHelperManager, $name, $requestedName)
{
/** @var ServiceManager $serviceManager */
$serviceManager = $viewHelperManager->getServiceLocator();
$options = $this->getOptions($serviceManager, $requestedName);
$formRowHelper = $this->defaultRowHelper;
if (!empty($options['form_row_helper'])) {
$formRowHelper = $options['form_row_helper'];
}
/** @var FormRow $formRow */
$formRow = $viewHelperManager->get($formRowHelper);
return new FormGroup($formRow);
}
示例15: testGenerateViewHelpers
public function testGenerateViewHelpers()
{
$config = (new Module())->getConfig();
$helperPluginManager = new HelperPluginManager();
$helperPluginManager->setServiceLocator(new ServiceManager());
$filterManager = new FilterPluginManager();
$basePath = $helperPluginManager->get('basePath');
$basePath->setBasePath('/assets');
$basePathFilter = new BasePathFilter($basePath);
$filterManager->setService('basePath', $basePathFilter);
$cacheBusterFilter = new CacheBusterFilter(__DIR__ . '/_files');
$filterManager->setService('cacheBuster', $cacheBusterFilter);
$generator = new ViewHelperGenerator($filterManager, $helperPluginManager, $config['con-layout']['view_helpers']);
$renderer = new PhpRenderer();
$renderer->setHelperPluginManager($helperPluginManager);
/* @var $headLink HeadLink */
$headLink = $helperPluginManager->get('headLink');
$headLinkProxy = new HeadLinkProxy($headLink);
$helperPluginManager->setService(get_class($headLinkProxy), $headLinkProxy);
/* @var $headScript HeadScript */
$headScript = $helperPluginManager->get('headScript');
$headScriptProxy = new HeadScriptProxy($headScript);
$helperPluginManager->setService(get_class($headScriptProxy), $headScriptProxy);
/* @var $doctype Doctype */
$doctype = $helperPluginManager->get('doctype');
$doctype('HTML5');
/* @var $headTitle HeadTitle */
$headTitle = $helperPluginManager->get('headTitle');
$headTitleProxy = new HeadTitleProxy($headTitle);
$helperPluginManager->setService(get_class($headTitleProxy), $headTitleProxy);
/* @var $headMeta HeadMeta */
$headMeta = $helperPluginManager->get('headMeta');
$headMetaProxy = new HeadMetaProxy($headMeta);
$helperPluginManager->setService(get_class($headMetaProxy), $headMetaProxy);
$headMeta->setView($renderer);
$generator->generate($this->getLayoutStructure());
foreach (['/assets/css/test.css', '/assets/css/main.css'] as $expected) {
$this->assertContains($expected, $headLink->toString());
}
foreach (['jquery.min.js', 'jquery-ui.min.js'] as $expected) {
$this->assertContains($expected, $headScript->toString());
}
$this->assertEquals('<!DOCTYPE html>', (string) $doctype);
$headTitle->setSeparator(' | ');
$expected = 'First | My Title | Another Title';
$this->assertContains($expected, $headTitle->toString());
$contains = ['charset="utf8"', 'name="description" content="My description"', 'name="keywords" content="keyword1, keyword2, keyword3"'];
foreach ($contains as $expected) {
$this->assertContains($expected, $headMeta->toString());
}
}