/** * Setup request and shibboleth objects, run getPermissions and check the result * * @param array $headers Request headers * @param mixed $options options as from configuration * @param array $expectedResult expected result returned by getPermissions * * @return void */ protected function checkShibboleth($headers, $options, $expectedResult) { $request = new \Zend\Http\PhpEnvironment\Request(); $request->setServer(new \Zend\Stdlib\Parameters($headers)); $shibboleth = new Shibboleth($request); $result = $shibboleth->getPermissions($options); $this->assertEquals($result, $expectedResult); }
/** * * @return \Zend\Http\PhpEnvironment\Request */ function createRefererRequest($expectedUrl) { $headers = new \Zend\Http\Headers(); $headers->addHeaderLine('Referer', $expectedUrl); $request = new \Zend\Http\PhpEnvironment\Request(); $request->setHeaders($headers); return $request; }
function dispatch($uri) { $this->request->setUri($uri); $event = new \Zend\Mvc\MvcEvent(); $event->setRouter($this->router); $event->setRequest($this->request); $this->events->trigger('route', $event); $this->routeMatch = $event->getRouteMatch(); }
/** * @see \Zend\ServiceManager\FactoryInterface::createService() * @param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator * @throws \UnexpectedValueException * @return \AssetsBundle\Service\ServiceOptions */ public function createService(\Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator) { $aConfiguration = $oServiceLocator->get('Config'); if (!isset($aConfiguration['assets_bundle'])) { throw new \UnexpectedValueException('AssetsBundle configuration is undefined'); } $aOptions = $aConfiguration['assets_bundle']; if ($aOptions instanceof \Traversable) { $aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions); } elseif (!is_array($aOptions)) { throw new \InvalidArgumentException('"assets_bundle" configuration expects an array or Traversable object; received "' . (is_object($aOptions) ? get_class($aOptions) : gettype($aOptions)) . '"'); } //Define base URL of the application if (!isset($aOptions['baseUrl'])) { if (($oRequest = $oServiceLocator->get('request')) instanceof \Zend\Http\PhpEnvironment\Request) { $aOptions['baseUrl'] = $oRequest->getBaseUrl(); } else { $oRequest = new \Zend\Http\PhpEnvironment\Request(); $aOptions['baseUrl'] = $oRequest->getBaseUrl(); } } //Retrieve filters if (isset($aOptions['view_helper_plugins'])) { $aViewHelperPlugins = $aOptions['view_helper_plugins']; if ($aViewHelperPlugins instanceof \Traversable) { $aViewHelperPlugins = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions); } elseif (!is_array($aViewHelperPlugins)) { throw new \InvalidArgumentException('Assets bundle "filters" option expects an array or Traversable object; received "' . (is_object($aViewHelperPlugins) ? get_class($aViewHelperPlugins) : gettype($aViewHelperPlugins)) . '"'); } $oViewHelperPluginManager = $oServiceLocator->get('ViewHelperManager'); foreach ($aViewHelperPlugins as $sAssetFileType => $oViewHelperPlugin) { if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetFileType)) { throw new \LogicException('Asset file type "' . $sAssetFileType . '" is not valid'); } if (is_string($oViewHelperPlugin)) { if ($oViewHelperPluginManager->has($oViewHelperPlugin)) { $oViewHelperPlugin = $oViewHelperPluginManager->get($oViewHelperPlugin); } elseif (class_exists($oViewHelperPlugin)) { $oViewHelperPlugin = new $oViewHelperPlugin(); } else { throw new \LogicException('View helper plugin "' . $oViewHelperPlugin . '" is not a registered service or an existing class'); } if ($oViewHelperPlugin instanceof \Zend\View\Helper\HelperInterface) { $aViewHelperPlugins[$sAssetFileType] = $oViewHelperPlugin; } else { throw new \LogicException('View helper plugin expects an instance of "\\Zend\\View\\Helper\\HelperInterface", "' . get_class($oViewHelperPlugin) . '" given'); } } } $aOptions['view_helper_plugins'] = $aViewHelperPlugins; } //Unset filters unset($aOptions['filters']); return new \AssetsBundle\Service\ServiceOptions($aOptions); }
public function testInheritRequestParams() { $requestParams = array('param1' => 'requestValue1'); $request = new \Zend\Http\PhpEnvironment\Request(); $request->setQuery(new \Zend\Stdlib\Parameters($requestParams)); $helper = new \Console\View\Helper\ConsoleUrl($request, $this->_getHelper('Url')); $params = array(); $this->assertEquals('/console/controller/action/?param1=requestValue1', $helper('controller', 'action', $params, true)); $params['param2'] = 'value2'; $this->assertEquals('/console/controller/action/?param1=requestValue1¶m2=value2', $helper('controller', 'action', $params, true)); $params['param1'] = 'value1'; $this->assertEquals('/console/controller/action/?param1=value1¶m2=value2', $helper('controller', 'action', $params, true)); }
public function indexAction() { if ($this->getRequest()->isPost()) { $request = new Zend\Http\PhpEnvironment\Request(); $formData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $this->formRegistration->setData($formData); if ($this->formRegistration->isValid($formData)) { $users = $this->model; $users->setRenderer($this->view); $users->userAdd($this->formRegistration); $this->_helper->FlashMessenger('Registration complete'); $this->getHelper('Redirector')->gotoRouteAndExit(array('module' => 'user', 'controller' => 'auth', 'action' => 'index'), 'userLogin'); } } $this->view->title = "User registration Page"; $this->view->registrationLink = " active"; $this->view->form = $this->formRegistration; $this->view->status = $this->_helper->flashMessenger->getMessages(); }
/** * Get the custom URL of the Tracking Code * * @return string URL */ protected function getCustomUrl() { $path = $this->request->getUri()->getPath(); $routeMatch = $this->router->match($this->request); if ($routeMatch && $routeMatch->getMatchedRouteName() == 'vufindrecord-ajaxtab') { // Replace 'AjaxTab' with tab name in record page URLs $replace = 'AjaxTab'; $tab = $this->request->getPost('tab'); if (null !== ($pos = strrpos($path, $replace))) { $path = substr_replace($path, $tab, $pos, $pos + strlen($replace)); } } return $path; }
public function testGetTokenMocked() { $this->client->getUrl(); $httpClientMock = $this->getMock('\\ReverseOAuth2\\OAuth2HttpClient', array('send'), array(null, array('timeout' => 30, 'adapter' => '\\Zend\\Http\\Client\\Adapter\\Curl'))); $httpClientMock->expects($this->exactly(1))->method('send')->will($this->returnCallback(array($this, 'getMockedTokenResponse'))); $this->client->setHttpClient($httpClientMock); $request = new \Zend\Http\PhpEnvironment\Request(); $request->setQuery(new \Zend\Stdlib\Parameters(array('code' => 'some code', 'state' => $this->client->getState()))); $this->assertTrue($this->client->getToken($request)); $this->client->getToken($request); $this->assertTrue($this->client->getToken($request)); // from session $this->assertTrue(strlen($this->client->getSessionToken()->access_token) > 0); }
/** * Support method -- get parameters to log into an account (but allow override of * individual parameters so we can test different scenarios). * * @param array $overrides Associative array of parameters to override. * * @return \Zend\Http\Request */ protected function getLoginRequest($overrides = array()) { $server = $overrides + array('username' => 'testuser', 'email' => '*****@*****.**', 'password' => 'testpass'); $request = new \Zend\Http\PhpEnvironment\Request(); $request->setServer(new \Zend\Stdlib\Parameters($server)); return $request; }
public function singleRecordAction() { $retour = array(); $iso = $this->params('iso3166'); $request = new \Zend\Http\PhpEnvironment\Request(); $methode = $request->getServer('REQUEST_METHOD'); if (isset($iso)) { $retour["search"] = $iso; $sm = $this->getServiceLocator(); $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter'); $resultSetPrototype = new \Zend\Db\ResultSet\ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Country()); $tableGateWay = new TableGateway('country', $dbAdapter, null, $resultSetPrototype); $countryTable = new CountryTable($tableGateWay); switch ($methode) { case "GET": $country = $countryTable->getCountryWithSearch($iso); if (isset($country)) { $retour[] = $country->toArray(); } else { $retour["error"] = "Pas de resultat"; } break; case "PATCH": $country = $countryTable->getCountryWithSearch($iso); if (isset($country)) { $postContent = $request->getContent(); if (trim($postContent)) { //$retour["content"] = json_decode($postContent); $formReceivedData = new Form\Register(); $formReceivedData->setData(json_decode($postContent, true)); //$retour["insert"] = json_decode($postContent,true); if ($formReceivedData->isValid()) { $newCountry = new Country(); $newCountry->exchangeArray(json_decode($postContent, true)); $countryTable->saveCountry($newCountry); $retour["success"] = "Donnees valides"; } else { $retour["error"] = "Donnees recues non valides"; } } else { $retour["error"] = "Pas de donnees recues"; } } else { $retour["error"] = "Pays non trouve"; } break; case "DELETE": $country = $countryTable->getCountryWithSearch($iso); if (isset($country)) { $countryTable->deleteCountryWithSearch($iso); $retour["success"] = "Suppression reussie"; } else { $retour["error"] = "Pays non trouve"; } break; default: $retour["error"] = "405 : Forbidden method"; break; } } else { $retour["error"] = "Pas d'iso3166 specifie"; } return new JsonModel($retour); }
/** * Retorna o adaptador de sessao * @param string $name * @return SessionContainer */ public function getSessionAdapter($name = 'Default') { if (!isset($_SESSION[$name])) { $sessionConfig = new SessionConfig(); $sessionConfig->setOptions($this->globalConfig['session']); $sessionStorage = new \Zend\Session\Storage\SessionArrayStorage(); $sessionManager = new SessionManager(); $sessionManager->rememberMe($this->globalConfig['session']['remember_me_seconds']); $sessionManager->forgetMe(); $sessionManager->setConfig($sessionConfig); $sessionManager->setStorage($sessionStorage); $sessionNamespace = new SessionContainer($name, $sessionManager); $sessionNamespace->setExpirationSeconds(3600); if (!isset($sessionNamespace->init)) { $request = new \Zend\Http\PhpEnvironment\Request(); $sessionNamespace->init = 1; $sessionNamespace->remoteAddr = $request->getServer('REMOTE_ADDR'); $sessionNamespace->httpUserAgent = $request->getServer('HTTP_USER_AGENT'); /* $chain = $sessionManager->getValidatorChain(); $validatorUserAgent = new \Zend\Session\Validator\HttpUserAgent($sessionNamespace->httpUserAgent); $chain->attach('session.validate', array($validatorUserAgent, 'isValid')); $validatorAddr = new \Zend\Session\Validator\RemoteAddr($sessionNamespace->remoteAddr); $chain->attach('session.validate', array($validatorAddr, 'isValid')); $sessionManager->setValidatorChain($chain); * */ } $sessionNamespace->setDefaultManager($sessionManager); } else { $sessionNamespace = new SessionContainer($name); $sessionNamespace->setExpirationSeconds(3600); } $this->sessionAdapter = $sessionNamespace; return $sessionNamespace; }
public function ccCheckAction() { $response = $this->getResponse(); $response->setStatusCode(200); $response->setContent("Thank you"); $config = $this->getServiceLocator()->get('Config'); $sec_key = $config['ERS\\iPayment']['sec_key']; $allowed_ips = array('212.227.34.218', '212.227.34.219', '212.227.34.220'); $logger = $this->getServiceLocator()->get('Logger'); $request = new \Zend\Http\PhpEnvironment\Request(); $ipmatch = false; if (in_array($request->getServer('REMOTE_ADDR'), $allowed_ips)) { $ipmatch = true; } else { $logger->info('unauthorized hidden trigger from: ' . $request->getServer('REMOTE_ADDR')); return $response; } $post_param = $this->params()->fromPost(); $logger->info('$_POST:'); $logger->info($post_param); $return_checksum = array(); if (isset($post_param["trxuser_id"])) { $return_checksum[] = $post_param["trxuser_id"]; } if (isset($post_param["trx_amount"])) { $return_checksum[] = $post_param["trx_amount"]; } if (isset($post_param["trx_currency"])) { $return_checksum[] = $post_param["trx_currency"]; } if (isset($post_param["ret_authcode"])) { $return_checksum[] = $post_param["ret_authcode"]; } if (isset($post_param["ret_trx_number"])) { $return_checksum[] = $post_param["ret_trx_number"]; } $return_checksum[] = $sec_key; $logger->info($return_checksum); $logger->info('ret_param: ' . $post_param["ret_param_checksum"]); $logger->info('hash : ' . md5(implode($return_checksum))); if ($post_param["ret_param_checksum"] != md5(implode($return_checksum))) { // Error because hash do not match! $logger->emerg('Unable to finish payment, checksums do not match.'); return $response; #exit; } $hashkey = $this->params()->fromRoute('hashkey', ''); if ($hashkey == '') { $logger->warn('no hashkey given in route'); return $response; } $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('hashkey' => $hashkey)); if ($order == null) { $logger->warn('unable to find order with hashkey: ' . $hashkey); return $response; } $order->setPaymentStatus('paid'); foreach ($order->getItems() as $item) { $item->setStatus('paid'); $em->persist($item); } $orderStatus = new Entity\OrderStatus(); $orderStatus->setOrder($order); $orderStatus->setValue('paid'); $order->addOrderStatus($orderStatus); $em->persist($order); $em->persist($orderStatus); $em->flush(); return $response; }
<?php require_once './autoloader.php'; $_SERVER['REQUEST_URI'] = '/html/index.php?url=http://test.example.com/path/&foo=bar'; $request = new \Zend\Http\PhpEnvironment\Request(); //$request->setRequestUri($url); echo $request->getRequestUri();