Registers a number of default plugins, and contains an initializer for injecting plugins with the current controller.
Наследование: extends Zend\ServiceManager\AbstractPluginManager
Пример #1
0
    public function setUp()
    {
        $plugins  = new ControllerPluginManager();
        $selector = $plugins->get('AcceptableViewModelSelector');

        $this->listener   = new AcceptListener($selector, array(
            'controllers' => array(
                'ZFTest\ContentNegotiation\TestAsset\ContentTypeController' => 'Json',
            ),
            'selectors' => array(
                'Json' => array(
                    'Zend\View\Model\JsonModel' => array(
                        'application/json',
                        'application/*+json',
                    ),
                ),
            ),
        ));
        $this->event      = new MvcEvent();
        $this->controller = new TestAsset\ContentTypeController();
        $this->event->setTarget($this->controller);
        $this->event->setRequest(new Request);
        $this->event->setRouteMatch(new RouteMatch(array(
            'controller' => __NAMESPACE__ . '\TestAsset\ContentTypeController',
        )));

        $this->controller->setEvent($this->event);
        $this->controller->setRequest($this->event->getRequest());
        $this->controller->setPluginManager($plugins);
    }
Пример #2
0
 public function testGetWithConstrutorAndOptions()
 {
     $pluginManager = new PluginManager();
     $pluginManager->setInvokableClass('samplePlugin', 'ZendTest\\Mvc\\Controller\\Plugin\\TestAsset\\SamplePluginWithConstructor');
     $plugin = $pluginManager->get('samplePlugin', 'foo');
     $this->assertEquals($plugin->getBar(), 'foo');
 }
Пример #3
0
 /**
  * {@inheritdoc}
  *
  * @param PluginManager $pluginManager
  *
  * @return InitMetaTags
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /* @var \Zend\ServiceManager\ServiceManager */
     $viewHelper = $pluginManager->getController()->getServiceLocator()->get('ViewHelperManager');
     /*
      * @var \Zend\View\Helper\Placeholder\Container
      */
     $placeholderContainer = $viewHelper->get('placeholder')->getContainer('customHead');
     /*
      * @var \Zend\View\Helper\HeadMeta
      */
     $headMeta = $viewHelper->get('HeadMeta');
     /*
      * @var \Zend\Http\PhpEnvironment\Request
      */
     $request = $pluginManager->getController()->getRequest();
     /*
      * @var \SD\Application\Controller\Plugin\SystemSettings
      */
     $systemSettings = $pluginManager->get('systemsettings');
     /*
      * @var InitMetaTags
      */
     $plugin = new InitMetaTags($placeholderContainer, $headMeta, $request, $systemSettings);
     return $plugin;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  *
  * @param PluginManager $pluginManager
  *
  * @return Translate
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /* @var \Zend\ServiceManager\ServiceManager */
     $translator = $pluginManager->getController()->getServiceLocator()->get('translator')->getTranslator();
     $plugin = new Translate($translator);
     return $plugin;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /* @var Zend\ServiceManager\ServiceManager */
     $serviceLocator = $pluginManager->getController()->getServiceLocator();
     $plugin = new GetTableModel($serviceLocator);
     return $plugin;
 }
 /**
  * Retourne le plugin url.
  *
  * @var \Zend\Mvc\Controller\PluginManager
  */
 public function url()
 {
     if (!$this->_url) {
         $this->_url = $this->_pluginManager->get('url');
     }
     return $this->_url;
 }
Пример #7
0
 public function setUp()
 {
     $this->controller = $controller = new RestController();
     $this->router = $router = new SimpleRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $event->setRouteMatch(new RouteMatch(array()));
     $controller->setEvent($event);
     $controller->setRoute('resource');
     $pluginManager = new PluginManager();
     $pluginManager->setService('bodyParams', new BodyParams());
     $controller->setPluginManager($pluginManager);
     $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);
     $pluginManager->setService('Hal', $linksHelper);
     $linksHelper->setController($controller);
     $this->resource = $resource = new Resource();
     $controller->setResource($resource);
 }
    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);
    }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(PluginManager $pluginManager)
 {
     $controller = $pluginManager->getController();
     $layout = $controller->layout();
     $response = $controller->getResponse();
     $plugin = new ErrorCodes($layout, $response);
     return $plugin;
 }
 public function testCreateService()
 {
     $pm = new ControllerPluginManager();
     $sm = new ServiceManager();
     $sm->setService('AcMailer\\Service\\MailService', new MailServiceMock());
     $pm->setServiceLocator($sm);
     $this->assertInstanceOf('AcMailer\\Controller\\Plugin\\SendMailPlugin', $this->factory->createService($pm));
 }
 public function testLoginProxiesToZfcUserAndReturnsNonModelInterface()
 {
     /** @var $forwardPlugin \Mockery\MockInterface */
     $forwardPlugin = $this->pm->get('forward');
     $forwardPlugin->shouldReceive('dispatch')->with('zfcuser', array('action' => 'login'))->andReturn('zfc-user-login');
     $result = $this->dispatch('login');
     $this->assertEquals('zfc-user-login', $result);
 }
Пример #12
0
 public function testCanCreateByFactoryWithConstrutor()
 {
     $pluginManager = new PluginManager();
     $pluginManager->setFactory('samplePlugin', 'ZendTest\\Mvc\\Controller\\Plugin\\TestAsset\\SamplePluginWithConstructorFactory');
     $plugin = $pluginManager->get('samplePlugin', 'foo');
     $this->assertInstanceOf('\\ZendTest\\Mvc\\Controller\\Plugin\\TestAsset\\SamplePluginWithConstructor', $plugin);
     $this->assertEquals($plugin->getBar(), 'foo');
 }
 protected function createControllerManager($config = [])
 {
     $pm = new ControllerPluginManager();
     $sm = new ServiceManager();
     $sm->setService('Config', $config);
     $pm->setServiceLocator($sm);
     return $pm;
 }
Пример #14
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->serviceManager = Bootstrap::getServiceManager();
     $this->entityManager = $this->serviceManager->get('doctrine.entitymanager.orm_default');
     $this->createMergedDocument = new CreateMergedDocument();
     $pluginManager = new PluginManager();
     $pluginManager->setServiceLocator($this->serviceManager);
     $this->createMergedDocument->setServiceLocator($pluginManager);
 }
 private function setupMockFlashMessenger($messageType)
 {
     $flashMessenger = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\FlashMessenger');
     $flashMessenger->expects($this->any())->method('has' . $messageType . 'Messages')->will($this->returnValue(true));
     $flashMessenger->expects($this->any())->method('get' . $messageType . 'Messages')->will($this->returnValue($this->testMessages));
     $plugins = new PluginManager();
     $plugins->setService('FlashMessenger', $flashMessenger);
     $this->controller->setPluginManager($plugins);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  *
  * @param PluginManager $pluginManager
  *
  * @return GetUrlParams
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /*
      * @var \Zend\Mvc\Controller\Plugin\Params
      */
     $params = $pluginManager->get('params');
     $plugin = new GetUrlParams($params);
     return $plugin;
 }
Пример #17
0
 /**
  * {@inheritdoc}
  *
  * @param PluginManager $pluginManager
  *
  * @return Mailing
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /* @var \Zend\Mvc\Controller\Plugin\FlashMessenger */
     $flashmessenger = $pluginManager->get('flashmessenger');
     /* @var \SD\Application\Controller\Plugin\SystemSettings */
     $systemsettings = $pluginManager->get('systemsettings');
     $plugin = new Mailing($flashmessenger, $systemsettings);
     return $plugin;
 }
Пример #18
0
 public function testPlugin()
 {
     $config = (include __DIR__ . '/../../../../config/module.config.php');
     $plugins = new PluginManager(new Config($config['controller_plugins']));
     $plugin = $plugins->get('CsvExport');
     $this->assertInstanceOf('RdnCsv\\Controller\\Plugin\\CsvExport', $plugin);
     $anotherPlugin = $plugins->get('CsvExport');
     $this->assertFalse($plugin === $anotherPlugin);
 }
Пример #19
0
 /**
  *
  * @return ViewController
  */
 private function getTestTarget()
 {
     $target = $this->getSimpleTarget();
     $params = $this->getMockBuilder(Params::class)->disableOriginalConstructor()->setMethods(['__invoke'])->getMock();
     $params->expects($this->once())->method('__invoke')->with('id')->willReturn(1234);
     $plugins = new PluginManager();
     $plugins->setService('params', $params);
     $target->setPluginManager($plugins);
     return $target;
 }
Пример #20
0
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $pluginManager = new PluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $serviceManager->setService('ZfjRbac\\Service\\AuthorizationService', $this->getMock('ZfjRbac\\Service\\AuthorizationServiceInterface'));
     $factory = new IsGrantedPluginFactory();
     $isGranted = $factory->createService($pluginManager);
     $this->assertInstanceOf('ZfjRbac\\Mvc\\Controller\\Plugin\\IsGranted', $isGranted);
 }
 /**
  * __invoke
  *
  * Create the identity controller plugin.
  *
  * @param PluginManager  $controllerPluginManager  The controller plugin manager.
  * @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(PluginManager $controllerPluginManager, $name, $requestedName)
 {
     /** @var ServiceManager $serviceManager */
     $serviceManager = $controllerPluginManager->getServiceLocator();
     $options = $this->getOptions($serviceManager, $requestedName);
     if (empty($options['auth_service'])) {
         throw new ServiceNotCreatedException(sprintf('The required \'auth_service\' configuration option for service \'%s\' could not be found in \'%s\'.', $requestedName, __METHOD__));
     }
     /** @var AuthenticationServiceInterface $authenticationService */
     $authenticationService = $serviceManager->get($options['auth_service']);
     return new Identity($authenticationService);
 }
Пример #22
0
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('ConLayout\\Layout\\LayoutInterface', $this->layout);
     $serviceManager->setService('ConLayout\\Updater\\LayoutUpdaterInterface', $this->updater);
     $serviceManager->setService('ConLayout\\View\\Renderer\\BlockRenderer', $this->renderer);
     $controllerPluginManager = new PluginManager();
     $controllerPluginManager->setServiceLocator($serviceManager);
     $factory = new LayoutManagerFactory();
     $instance = $factory->createService($controllerPluginManager);
     $this->assertInstanceOf('ConLayout\\Controller\\Plugin\\LayoutManager', $instance);
 }
Пример #23
0
 /**
  * {@inheritdoc}
  *
  * @param PluginManager $pluginManager
  *
  * @return SystemSettings
  */
 public function __invoke(PluginManager $pluginManager)
 {
     /* @var \Zend\ServiceManager\ServiceLocatorInterface */
     $serviceLocator = $pluginManager->getController()->getServiceLocator();
     $config = $serviceLocator->get('Config');
     /*
      * No need to pass a second argument, just for the theme name. Instead,merge it into the already system config array
      */
     $config['system_config']['theme']['name'] = $config['theme']['name'];
     $plugin = new SystemSettings($config['system_config']);
     return $plugin;
 }
 /**
  * @covers \DoctrineORMModule\Yuml\YumlController::indexAction
  */
 public function testIndexActionWillRedirectToYuml()
 {
     $response = $this->getMock('Zend\\Http\\Response');
     $controllerResponse = $this->getMock('Zend\\Http\\Response');
     $redirect = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Redirect');
     $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response));
     $response->expects($this->any())->method('isSuccess')->will($this->returnValue(true));
     $response->expects($this->any())->method('getBody')->will($this->returnValue('short-url'));
     $this->pluginManager->expects($this->any())->method('get')->with('redirect')->will($this->returnValue($redirect));
     $redirect->expects($this->any())->method('toUrl')->with('http://yuml.me/short-url')->will($this->returnValue($controllerResponse));
     $this->assertSame($controllerResponse, $this->controller->indexAction());
 }
Пример #25
0
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService(LayoutInterface::class, $this->layout);
     $serviceManager->setService(LayoutUpdaterInterface::class, $this->layoutUpdater);
     $serviceManager->setService(BlockPoolInterface::class, $this->blockPool);
     $controllerPluginManager = new PluginManager();
     $controllerPluginManager->setServiceLocator($serviceManager);
     $factory = new LayoutManagerFactory();
     $instance = $factory->createService($controllerPluginManager);
     $this->assertInstanceOf(LayoutManager::class, $instance);
 }
Пример #26
0
 public function testGetMethod()
 {
     $expected = array('test1' => 'Testing Var 1', 'test2' => 'Testing Var 2');
     $this->rcmIsSiteAdminPlugin->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $parmsMock = $this->getMockBuilder('\\Zend\\Mvc\\Controller\\Plugin\\Params')->disableOriginalConstructor()->getMock();
     $parmsMock->expects($this->any())->method('__invoke')->will($this->returnValue('someUserName'));
     $this->pluginManager->setService('params', $parmsMock);
     $this->mockApi->expects($this->once())->method('getEmbed')->with($this->equalTo('someUserName'), $this->equalTo(22))->will($this->returnValue($expected));
     $result = $this->controller->get(22);
     $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $result);
     $jsonResult = $result->serialize();
     $this->assertEquals(json_encode($expected), $jsonResult);
 }
 public function setUp()
 {
     $plugins = new ControllerPluginManager(new ServiceManager());
     $selector = $plugins->get('AcceptableViewModelSelector');
     $this->listener = new AcceptListener($selector, ['controllers' => ['ZFTest\\ContentNegotiation\\TestAsset\\ContentTypeController' => 'Json'], 'selectors' => ['Json' => ['Zend\\View\\Model\\JsonModel' => ['application/json', 'application/*+json']]]]);
     $this->event = new MvcEvent();
     $this->controller = new TestAsset\ContentTypeController();
     $this->event->setTarget($this->controller);
     $this->event->setRequest(new Request());
     $this->event->setRouteMatch($this->createRouteMatch(['controller' => __NAMESPACE__ . '\\TestAsset\\ContentTypeController']));
     $this->controller->setEvent($this->event);
     $this->controller->setRequest($this->event->getRequest());
     $this->controller->setPluginManager($plugins);
 }
Пример #28
0
 /**
  * @covers \OcraServiceManager\Controller\YumlController::indexAction
  */
 public function testIndexActionWillRedirectToYuml()
 {
     $this->serviceLocator->expects($this->any())->method('get')->with('Config')->will($this->returnValue(array('ocra_service_manager' => array('logged_service_manager' => true), 'zenddevelopertools' => array('toolbar' => array('enabled' => true)))));
     $client = $this->getMock('Zend\\Http\\Client');
     $response = $this->getMock('Zend\\Http\\Response');
     $controllerResponse = $this->getMock('Zend\\Http\\Response');
     $redirect = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Redirect');
     $client->expects($this->any())->method('send')->will($this->returnValue($response));
     $response->expects($this->any())->method('isSuccess')->will($this->returnValue(true));
     $response->expects($this->any())->method('getBody')->will($this->returnValue('short-url'));
     $this->pluginManager->expects($this->any())->method('get')->with('redirect')->will($this->returnValue($redirect));
     $redirect->expects($this->any())->method('toUrl')->with('http://yuml.me/short-url')->will($this->returnValue($controllerResponse));
     $this->controller->setHttpClient($client);
     $this->assertSame($controllerResponse, $this->controller->indexAction());
 }
    /**
     * Set plugin manager
     *
     * @param  PluginManager $plugins
     * @return AbstractController
     */
    public function setPluginManager(PluginManager $plugins)
    {
        $this->plugins = $plugins;
        $this->plugins->setController($this);

        return $this;
    }
Пример #30
0
 /**
  * Set plugin manager
  *
  * @param  string|PluginManager $plugins
  * @return AbstractController
  * @throws Exception\InvalidArgumentException
  */
 public function setPluginManager(PluginManager $plugins)
 {
     $this->plugins = $plugins;
     if (method_exists($plugins, 'setController')) {
         $this->plugins->setController($this);
     }
     return $this;
 }