Exemple #1
0
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $zendResponse->setStatusCode(200);
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = strtoupper($request->getMethod());
     $zendRequest->setCookies(new Parameters($request->getCookies()));
     if ($queryString) {
         parse_str($queryString, $query);
         $zendRequest->setQuery(new Parameters($query));
     }
     if ($request->getContent() !== null) {
         $zendRequest->setContent($request->getContent());
     } elseif ($method != HttpRequest::METHOD_GET) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $zendRequest->setRequestUri(str_replace('http://localhost', '', $request->getUri()));
     $zendRequest->setHeaders($this->extractHeaders($request));
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
 /**
  * @return ServiceLocatorInterface
  */
 public function getServiceManager()
 {
     if ($this->serviceManager == null) {
         $this->serviceManager = $this->application->getServiceManager();
     }
     return $this->serviceManager;
 }
Exemple #3
0
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = $request->getMethod();
     if ($queryString) {
         parse_str($queryString, $query);
     }
     if ($method == HttpRequest::METHOD_POST) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     } elseif ($method == HttpRequest::METHOD_GET) {
         $query = $request->getParameters();
         $zendRequest->setQuery(new Parameters($query));
     } elseif ($method == HttpRequest::METHOD_PUT) {
         $zendRequest->setContent($request->getContent());
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
Exemple #4
0
 public function _before(\Codeception\TestCase $test)
 {
     $this->application = Application::init($this->applicationConfig);
     $events = $this->application->getEventManager();
     $events->detach($this->application->getServiceManager()->get('SendResponseListener'));
     $this->client->setApplication($this->application);
     $_SERVER['REQUEST_URI'] = '';
 }
Exemple #5
0
 /**
  * @param MvcEvent $event
  */
 public function __construct(MvcEvent $event)
 {
     $this->application = $event->getApplication();
     $this->serviceManager = $this->application->getServiceManager();
     $this->config = $this->serviceManager->get('VuFind\\Config')->get('config');
     $this->event = $event;
     $this->events = $this->application->getEventManager();
 }
 /**
  * @param ApplicationInterface $application
  * @return RouteMatch
  */
 public function getRouteMatch(ApplicationInterface $application)
 {
     if (!is_object($this->routeMatch)) {
         if (is_object($application->getMvcEvent()->getRouteMatch())) {
             $this->setRouteMatch($application->getMvcEvent()->getRouteMatch());
         } else {
             $this->setRouteMatch(new RouteMatch([]));
         }
     }
     return $this->routeMatch;
 }
Exemple #7
0
 public function _before(\Codeception\TestCase $test)
 {
     $applicationConfig = (require \Codeception\Configuration::projectDir() . $this->config['config']);
     if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) {
         $applicationConfig['module_listener_options']['config_cache_enabled'] = false;
     }
     Console::overrideIsConsole(false);
     $this->application = Application::init($applicationConfig);
     $events = $this->application->getEventManager();
     $events->detach($this->application->getServiceManager()->get('SendResponseListener'));
     $this->client->setApplication($this->application);
 }
Exemple #8
0
 /**
  * @return String
  */
 protected function getActiveTab()
 {
     if (strpos($this->application->getRequest()->getRequestUri(), '/Summon/') !== false) {
         return 'Summon';
     } else {
         return 'Solr';
     }
 }
Exemple #9
0
 public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app)
 {
     $this->application = $app;
     $locator = $app->getServiceManager();
     if ($this->getOption('enable_guards.route', true)) {
         $routeProtector = $locator->get('ZfcAcl\\Guard\\Route');
         $app->events()->attach('route', array($routeProtector, 'onRoute'), -1000);
     }
     if ($this->getOption('enable_guards.event', true)) {
         $guard = $locator->get('ZfcAcl\\Guard\\Event');
         $guard->bootstrap();
     }
     if ($this->getOption('enable_guards.dispatch', true)) {
         $guard = $locator->get('ZfcAcl\\Guard\\Dispatch');
         $app->events()->attach('dispatch', array($guard, 'dispatch'), 1000);
     }
 }
 /**
  * @param ModuleManager $moduleManager
  * @param ApplicationInterface $app
  */
 public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app)
 {
     /* @var SharedEventManager $em */
     $em = $app->getEventManager()->getSharedManager();
     $sm = $app->getServiceManager();
     /* @var GitHub\LoginListener $loginListener */
     $loginListener = $sm->get(GitHub\LoginListener::class);
     $em->attachAggregate($loginListener);
     $em->attach('EdpGithub\\Client', 'api', function ($e) use($sm) {
         $hybridAuth = $sm->get('HybridAuth');
         $adapter = $hybridAuth->getAdapter('github');
         if ($adapter->isUserConnected()) {
             $token = $adapter->getAccessToken();
             $client = $e->getTarget();
             $client->authenticate('url_token', $token['access_token']);
         }
     });
 }
Exemple #11
0
 protected function getInternalDomains()
 {
     /**
      * @var Zend\Mvc\Router\Http\TreeRouteStack
      */
     $router = $this->application->getServiceManager()->get('router');
     $this->domainCollector = [];
     $this->addInternalDomainsFromRoutes($router->getRoutes());
     return array_unique($this->domainCollector);
 }
Exemple #12
0
 private function createApplication()
 {
     $this->application = Application::init($this->applicationConfig);
     $serviceManager = $this->application->getServiceManager();
     if (isset($this->doctrineServiceManager)) {
         $serviceManager->addPeeringServiceManager($this->doctrineServiceManager);
         $serviceManager->setRetrieveFromPeeringManagerFirst(true);
     }
     $events = $this->application->getEventManager();
     $events->detach($serviceManager->get('SendResponseListener'));
 }
 /**
  * Get the application object
  * @return \Zend\Mvc\ApplicationInterface
  */
 public function getApplication()
 {
     if ($this->application) {
         return $this->application;
     }
     $appConfig = $this->applicationConfig;
     Console::overrideIsConsole($this->getUseConsoleRequest());
     $this->application = Application::init($appConfig);
     $events = $this->application->getEventManager();
     $events->detach($this->application->getServiceManager()->get('SendResponseListener'));
     return $this->application;
 }
 public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app)
 {
     $em = $app->getEventManager()->getSharedManager();
     $sm = $app->getServiceManager();
     $em->attach('ScnSocialAuth\\Authentication\\Adapter\\HybridAuth', 'githubToLocalUser', function ($e) {
         $localUser = $e->getTarget();
         $userProfile = $e->getParam('userProfile');
         $nickname = substr($userProfile->profileURL, strrpos($userProfile->profileURL, "/") + 1);
         $localUser->setUsername($nickname);
         $localUser->setPhotoUrl($userProfile->photoURL);
     });
     $em->attach('EdpGithub\\Client', 'api', function ($e) use($sm) {
         $hybridAuth = $sm->get('HybridAuth');
         $adapter = $hybridAuth->getAdapter('github');
         if ($adapter->isUserConnected()) {
             $token = $adapter->getAccessToken();
             $client = $e->getTarget();
             $client->authenticate('url_token', $token['access_token']);
         }
     });
 }
Exemple #15
0
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $zendHeaders = $zendRequest->getHeaders();
     if (!$zendHeaders->has('Content-Type')) {
         $server = $request->getServer();
         if (isset($server['CONTENT_TYPE'])) {
             $zendHeaders->addHeaderLine('Content-Type', $server['CONTENT_TYPE']);
         }
     }
     $zendResponse->setStatusCode(200);
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = strtoupper($request->getMethod());
     $zendRequest->setCookies(new Parameters($request->getCookies()));
     if ($queryString) {
         parse_str($queryString, $query);
         $zendRequest->setQuery(new Parameters($query));
     }
     if ($method == HttpRequest::METHOD_POST) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     } elseif ($method == HttpRequest::METHOD_PUT) {
         $zendRequest->setContent($request->getContent());
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
 public function setUp()
 {
     $this->listener = new Listener();
     $this->user = $this->getMockBuilder(User::class)->setMethods(['isActive'])->getMock();
     $this->auth = $this->getMockBuilder(AuthenticationService::class)->setMethods(['authenticate', 'hasIdentity', 'getIdentity', 'clearIdentity', 'getUser'])->getMock();
     $this->auth->expects($this->any())->method('getUser')->willReturn($this->user);
     $this->serviceManager = $this->getMockBuilder(ServiceManager::class)->setMethods(['get', 'has'])->getMock();
     $this->serviceManager->expects($this->any())->method('get')->will($this->returnCallback(function ($name) {
         switch ($name) {
             case 'AuthenticationService':
                 return $this->auth;
                 break;
             default:
                 throw new \InvalidArgumentException();
                 break;
         }
     }));
     $this->application = $this->getMockBuilder(Application::class)->setMethods(['getServiceManager', 'getRequest', 'getResponse', 'run', 'getEventManager'])->getMock();
     $this->application->expects($this->any())->method('getServiceManager')->willReturn($this->serviceManager);
     $this->routeMatch = new RouteMatch([]);
     $this->event = $this->getMockBuilder(MvcEvent::class)->getMock();
     $this->event->expects($this->any())->method('getApplication')->willReturn($this->application);
     $this->event->expects($this->any())->method('getRouteMatch')->willReturn($this->routeMatch);
 }
Exemple #17
0
 private function createApplication()
 {
     $this->application = Application::init($this->applicationConfig);
     $serviceManager = $this->application->getServiceManager();
     if (isset($this->persistentServiceManager)) {
         $serviceManager->addPeeringServiceManager($this->persistentServiceManager);
         $serviceManager->setRetrieveFromPeeringManagerFirst(true);
     }
     $sendResponseListener = $serviceManager->get('SendResponseListener');
     $events = $this->application->getEventManager();
     if (class_exists('Zend\\EventManager\\StaticEventManager')) {
         $events->detach($sendResponseListener);
         //ZF2
     } else {
         $events->detach([$sendResponseListener, 'sendResponse']);
         //ZF3
     }
 }
 /**
  * Get the application object
  * @return \Zend\Mvc\ApplicationInterface
  */
 public function getApplication()
 {
     if ($this->application) {
         return $this->application;
     }
     $appConfig = $this->applicationConfig;
     if (!$this->useConsoleRequest) {
         $consoleServiceConfig = array('service_manager' => array('factories' => array('ServiceListener' => 'Zend\\Test\\PHPUnit\\Mvc\\Service\\ServiceListenerFactory')));
         $appConfig = array_replace_recursive($appConfig, $consoleServiceConfig);
     }
     $this->application = Application::init($appConfig);
     $events = $this->application->getEventManager();
     foreach ($events->getListeners(MvcEvent::EVENT_FINISH) as $listener) {
         $callback = $listener->getCallback();
         if (is_array($callback) && $callback[0] instanceof SendResponseListener) {
             $events->detach($listener);
         }
     }
     return $this->application;
 }
Exemple #19
0
 /**
  * Trigger the "bootstrap" event
  *
  * Triggers with the keys "application" and "config", the latter pointing
  * to the Module ManagerInterface attached to the bootstrap.
  *
  * @param  ApplicationInterface $application
  * @return void
  */
 protected function setupEvents(ApplicationInterface $application)
 {
     $application->events()->setSharedManager($this->events()->getSharedManager());
     $params = array('application' => $application, 'config' => $this->config);
     $this->events()->trigger(MvcEvent::EVENT_BOOTSTRAP, $this, $params);
 }
Exemple #20
0
 public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app)
 {
     $em = $app->getEventManager()->getSharedManager();
     $sm = $app->getServiceManager();
 }
Exemple #21
0
 /**
  * Checks that current url matches route.
  *
  * ``` php
  * <?php
  * $I->seeCurrentRouteIs('posts.index');
  * $I->seeCurrentRouteIs('posts.show', ['id' => 8]));
  * ?>
  * ```
  *
  * @param $routeName
  * @param array $params
  */
 public function seeCurrentRouteIs($routeName, array $params = [])
 {
     $router = $this->application->getServiceManager()->get('router');
     $url = $router->assemble($params, ['name' => $routeName]);
     $this->seeCurrentUrlEquals($url);
 }