Пример #1
0
 /**
  * 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);
 }
 /**
  * @outputBuffering disabled
  */
 public function testCanRenderFieldsets()
 {
     $this->expectOutputRegex('/<form(.*)<fieldset(.*)<\\/fieldset>(.*)<fieldset(.*)<\\/fieldset>(.*)<\\/form>/');
     $form = new NetsensiaForm();
     $form->addHidden('test1', 'testvalue');
     $hidden = new Element\Hidden('asdasd');
     $hidden->setValue('123');
     $form->add($hidden);
     $element1 = new Text('testelement1');
     $element1->setLabel('Test Element');
     $element1->setAttribute('icon', 'pencil');
     $element2 = new Text('testelement2');
     $element2->setLabel('Test Element 2');
     $element2->setAttribute('icon', 'pencil');
     $fieldset1 = new Fieldset('testfieldset1');
     $fieldset1->add($element1);
     $fieldset2 = new Fieldset('testfieldset2');
     $fieldset2->add($element2);
     $form->add($fieldset1);
     $form->add($fieldset2);
     $helpers = new HelperPluginManager();
     $helpers->setService('formElement', new FormElement());
     $view = new PhpRenderer();
     $view->setHelperPluginManager($helpers);
     $viewHelper = new BootstrapForm();
     $viewHelper->setView($view);
     $viewHelper($form, 'testform', '/');
 }
 /**
  * @param HelperPluginManager $pluginManager
  *
  * @return SymfonyAssetViewHelper
  * @throws \Exception
  */
 public function __invoke(HelperPluginManager $pluginManager)
 {
     $serviceLocator = $pluginManager->getServiceLocator();
     $config = $serviceLocator->get('Config');
     if (false === isset($config['fadoe_symfony_asset_module'])) {
         throw new \Exception('Config not found');
     }
     $config = $config['fadoe_symfony_asset_module'];
     $packagesService = $serviceLocator->get('FaDoe\\SymfonyAssetModule\\PackagesService');
     $version = $config['version'];
     $versionFormat = $config['version_format'];
     $basePath = $config['base_path'];
     $baseUrls = $config['base_urls'];
     $defaultPackage = $packagesService->createService($version, $versionFormat, $basePath, $baseUrls);
     $namedPackages = [];
     foreach ($config['packages'] as $key => $value) {
         $version = $value['version'];
         $versionFormat = $value['version_format'];
         $basePath = $value['base_path'];
         $baseUrls = $value['base_urls'];
         $namedPackages[$key] = $packagesService->createService($version, $versionFormat, $basePath, $baseUrls);
     }
     $packages = new Packages($defaultPackage, $namedPackages);
     return new SymfonyAssetViewHelper($packages);
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 public function testOnDispatch()
 {
     // Create MvcEvent
     $e = new MvcEvent();
     $e->setViewModel(new ViewModel());
     $rm = new RouteMatch([]);
     $rm->setParam('controller', 'Application\\Controller\\Download');
     $e->setRouteMatch($rm);
     $e->setTarget(new DownloadController([]));
     // Create EntityManager and EntityRepository
     $moduleDetail = new ModuleList();
     $moduleDetail->setModuleDesc('Pretty description');
     $repo = $this->prophesize('Doctrine\\ORM\\EntityRepository');
     $repo->findOneBy(['moduleName' => 'Application'])->willReturn($moduleDetail);
     $em = $this->prophesize('Doctrine\\ORM\\EntityManager');
     $em->getRepository('Application\\Entity\\ModuleList')->willReturn($repo);
     $this->sm->setService('Doctrine\\ORM\\EntityManager', $em->reveal());
     // Create ViewHelperManager
     $headTitle = new HeadTitle();
     $vhm = new HelperPluginManager();
     $vhm->setService('headTitle', $headTitle);
     $this->sm->setService('ViewHelperManager', $vhm);
     $this->module->onDispatch($e);
     $fbMeta = $e->getViewModel()->getVariable('fbMeta');
     $this->assertEquals(sprintf('%s-Real Live Learn ZF2', $moduleDetail->getModuleDesc()), $fbMeta['title']);
     $this->assertEquals(sprintf('%s-', $moduleDetail->getModuleDesc()), $fbMeta['description']);
 }
Пример #6
0
 /**
  * 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);
 }
 public function testCreateService()
 {
     $helperPluginManager = new HelperPluginManager();
     $helperPluginManager->setServiceLocator(Bootstrap::getServiceManager());
     $result = $this->testedObj->createService($helperPluginManager);
     $this->assertInstanceOf(FlashMessages::class, $result);
 }
    public function setupHelpers()
    {
        if (!$this->router) {
            $this->setupRouter();
        }

        $urlHelper = new UrlHelper();
        $urlHelper->setRouter($this->router);

        $serverUrlHelper = new ServerUrlHelper();
        $serverUrlHelper->setScheme('http');
        $serverUrlHelper->setHost('localhost.localdomain');

        $linksHelper = new HalHelper();
        $linksHelper->setUrlHelper($urlHelper);
        $linksHelper->setServerUrlHelper($serverUrlHelper);

        $this->helpers = $helpers = new HelperPluginManager();
        $helpers->setService('url', $urlHelper);
        $helpers->setService('serverUrl', $serverUrlHelper);
        $helpers->setService('hal', $linksHelper);

        $this->plugins = $plugins = new ControllerPluginManager();
        $plugins->setService('hal', $linksHelper);
    }
 /**
  * @return Identity
  */
 protected function getIdentityHelper()
 {
     if (!$this->identityHelper instanceof Identity) {
         $identity = $this->serviceLocator->get('identity');
         $this->identityHelper = $identity;
     }
     return $this->identityHelper;
 }
Пример #10
0
 public function setHelperPluginManager(HelperPluginManager $hpm)
 {
     $hpm->setView($this);
     if ($this->getEnvironment()) {
         $this->getEnvironment()->setHelperPluginManager($hpm);
     }
     return $this;
 }
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     $config = isset($config['view_helpers']) ? $config['view_helpers'] : [];
     $manager = new HelperPluginManager(new Config($config));
     $manager->setServiceLocator($container);
     return $manager;
 }
Пример #12
0
 public function __call($method, $argv)
 {
     $helper = $this->pluginManager->get($method);
     if (is_callable($helper)) {
         return call_user_func_array($helper, $argv);
     }
     return helper;
 }
 /**
  * @test
  * @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelperFactory::__invoke()
  */
 public function createService()
 {
     $sm = new ServiceManager();
     $sm->setService('Cocur\\Slugify\\Slugify', new Slugify());
     $vhm = new HelperPluginManager();
     $vhm->setServiceLocator($sm);
     $viewHelper = call_user_func($this->factory, $vhm);
     $this->assertInstanceOf('Cocur\\Slugify\\Bridge\\ZF2\\SlugifyViewHelper', $viewHelper);
 }
Пример #14
0
 protected function setUp()
 {
     $this->request = new Request();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('request', $this->request);
     $pluginManager = new HelperPluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $this->pluginManager = $pluginManager;
 }
 public function testCompatibilityWithZF2View()
 {
     $renderer = new PhpRenderer();
     $helpers = new HelperPluginManager();
     $name = $this->jobleadsHelper->getName();
     $helpers->setInvokableClass($name, get_class($this->jobleadsHelper));
     $renderer->setHelperPluginManager($helpers);
     $this->assertEquals(self::EXPECTED_RETURN, $renderer->{$name}());
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $pluginManager = new HelperPluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $this->getMock('ZfcRbac\\Service\\AuthorizationServiceInterface'));
     $factory = new IsGrantedViewHelperFactory();
     $isGranted = $factory->createService($pluginManager);
     $this->assertInstanceOf('ZfcRbac\\View\\Helper\\IsGranted', $isGranted);
 }
 /**
  * @param ContainerInterface $container
  * @throws \RuntimeException
  * @return HelperPluginManager
  */
 public function __invoke(ContainerInterface $container)
 {
     $helperPluginManager = new HelperPluginManager();
     $helperPluginManager->setRetrieveFromPeeringManagerFirst();
     if (!$container instanceof ServiceManager) {
         throw new \RuntimeException(__CLASS__ . ' can only be used when Zend\\ServiceManager\\ServiceManager is used as container');
     }
     $helperPluginManager->addPeeringServiceManager($container);
     return $helperPluginManager;
 }
Пример #18
0
 public function __construct(HelperPluginManager $pluginManager)
 {
     $this->pluginManager = $pluginManager;
     $this->serviceManager = $pluginManager->getServiceLocator();
     $this->app = $pluginManager->getServiceLocator()->get('Application');
     $this->request = $this->app->getRequest();
     $this->event = $this->app->getMvcEvent();
     $this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
     $this->translator = $this->serviceManager->get('translator');
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $pluginManager = new HelperPluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $serviceManager->setService('ZfjRbac\\Service\\RoleService', $this->getMock('ZfjRbac\\Service\\RoleService', [], [], '', false));
     $factory = new HasRoleViewHelperFactory();
     $viewHelper = $factory->createService($pluginManager);
     $this->assertInstanceOf('ZfjRbac\\View\\Helper\\HasRole', $viewHelper);
 }
Пример #20
0
 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);
 }
Пример #21
0
 /**
  * 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}"));
 }
Пример #22
0
 public function testFactory()
 {
     $sm = new ServiceManager();
     $sm->setService(BlockPoolInterface::class, $this->blockPool);
     $helperManager = new HelperPluginManager();
     $helperManager->setServiceLocator($sm);
     $factory = new BlockFactory();
     $helper = $factory->createService($helperManager);
     $this->assertInstanceOf(Block::class, $helper);
     $this->assertInstanceOf(AbstractHelper::class, $helper);
 }
Пример #23
0
 /**
  * @param ContentType|null $contentType
  * @param string|null $contentTypeName
  *
  * @return string
  */
 public function __invoke(ContentType $contentType = null, $contentTypeName = null)
 {
     if (!is_null($contentTypeName)) {
         /** @var GeneralService $generalService */
         $generalService = $this->serviceLocator->getServiceLocator()->get(GeneralService::class);
         $contentType = $generalService->findContentTypeByContentTypeName($contentTypeName);
     }
     if (is_null($contentType)) {
         return null;
     }
     switch (trim($contentType->getContentType())) {
         case 'image/jpeg':
         case 'image/tiff':
         case 'image/png':
             $class = " fa-file-image-o";
             break;
         case 'application/pdf':
         case 'application/postscript':
             $class = "fa-file-pdf-o";
             break;
         case 'application/zip':
         case 'application/x-zip-compressed':
             $class = "fa-file-archive-o";
             break;
         case 'application/vnd.ms-excel':
         case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
         case 'application/vnd.ms-excel.sheet.macroEnabled.12':
             $class = "fa-file-excel-o";
             break;
         case 'application/mspowerpoint':
         case 'application/vnd.ms-powerpoint':
         case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
         case 'application/vnd.openxmlformats-officedocument.presentationml.template':
         case 'application/vnd.openxmlformats-officedocument.presentationml.slideshow':
             $class = 'fa-file-powerpoint-o';
             break;
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
         case 'application/msword':
             $class = "fa-file-word-o";
             break;
         case 'application/octet-stream':
         case 'application/csv':
         case 'text/xml':
             $class = "fa-file-o";
             break;
         case 'video/mp4':
             $class = "fa-file-video-o";
             break;
         default:
             return sprintf('%s not found', $contentType->getContentType());
     }
     return sprintf('<i class="fa %s" title="%s"></i> ', $class, $contentType->getDescription());
 }
Пример #24
0
 public function testFactoryReturnsProperConfiguredInstanceOfAuthViewHelperAuth()
 {
     $f = new AuthFactory();
     $sm = new ServiceManager();
     $auth = $this->getMockBuilder('\\Zend\\Authentication\\AuthenticationService')->getMock();
     $sm->setService('AuthenticationService', $auth);
     $hm = new HelperPluginManager();
     $hm->setServicelocator($sm);
     $helper = $f->createService($hm);
     $this->assertInstanceOf('\\Auth\\View\\Helper\\Auth', $helper);
     $this->assertSame($auth, $helper->getService());
 }
 /**
  * createService
  *
  * Create the identity view helper.
  *
  * @param HelperPluginManager  $viewHelperManager  The service manager instance.
  * @param string               $name            The name of the service being created.
  * @param string               $requestedName   The requested name of the service being created.
  *
  * @return Identity
  */
 public function __invoke(HelperPluginManager $viewHelperManager, $name, $requestedName)
 {
     /** @var ServiceManager $serviceManager */
     $serviceManager = $viewHelperManager->getServiceLocator();
     $options = $this->getOptions($serviceManager, $requestedName);
     if (!isset($options['auth_service'])) {
         throw new ServiceNotCreatedException(sprintf('The \'auth_service\' configuration option is missing for view helper \'%s\'.', $requestedName));
     }
     /** @var AuthenticationServiceInterface $authenticationService */
     $authenticationService = $serviceManager->get($options['auth_service']);
     return new Identity($authenticationService);
 }
Пример #26
0
 public function testCanCreateServiceWithName()
 {
     $moduleOptions = new ModuleOptions(['view_helpers' => ['headLink' => ['proxy' => TestProxy::class]]]);
     $sm = new ServiceManager();
     $sm->setService(ModuleOptions::class, $moduleOptions);
     $viewHelperManager = new HelperPluginManager();
     $viewHelperManager->setServiceLocator($sm);
     $viewHelperManager->setInvokableClass(TestProxy::class, TestProxy::class);
     $factory = new ViewHelperProxyAbstractFactory();
     $this->assertTrue($factory->canCreateServiceWithName($viewHelperManager, TestProxy::class, TestProxy::class));
     $this->assertFalse($factory->canCreateServiceWithName($viewHelperManager, 'not-exist', 'not-exist'));
 }
Пример #27
0
 protected function setUp()
 {
     $router = new Router();
     $router->addRoute('home', array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/')));
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller[/:action]')));
     $this->request = new Request();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('router', $router);
     $serviceManager->setService('request', $this->request);
     $pluginManager = new HelperPluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $this->pluginManager = $pluginManager;
 }
Пример #28
0
 public function testFactory()
 {
     $factory = new BasePathFilterFactory();
     $viewHelperManager = new HelperPluginManager();
     $viewHelperManager->setService('basePath', new BasePath());
     $serviceManager = new ServiceManager();
     $serviceManager->setService('viewHelperManager', $viewHelperManager);
     $filterManager = new FilterPluginManager();
     $filterManager->setServiceLocator($serviceManager);
     $instance = $factory->createService($filterManager);
     $this->assertInstanceOf(BasePathFilter2::class, $instance);
     $this->assertInstanceOf(FilterInterface::class, $instance);
 }
 /**
  * @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;
 }
 public function testFactoryReturnsInstanceOfParamsHelper()
 {
     $factory = new Factory();
     $sm = new ServiceManager();
     $event = new MvcEvent();
     $application = $this->getMockBuilder('\\Zend\\Mvc\\Application')->disableOriginalConstructor()->setMethods(array('getMvcEvent'))->getMock();
     $application->expects($this->once())->method('getMvcEvent')->will($this->returnValue($event));
     $sm->setService('Application', $application);
     $hm = new HelperPluginManager();
     $hm->setServiceLocator($sm);
     $helper = $factory->createService($hm);
     $this->assertInstanceOf('\\Core\\View\\Helper\\Params', $helper);
 }