public function onRequest() { $http = self::$serverInstance; $kernel = $this->kernel; $http->onMessage = function ($connection, $data) use($kernel) { // $http->on('request', function ($request, $response) use($kernel) { // if ($request->server['request_uri'] !== '/favicon.ico') { $l_request = new Symfony\Component\HttpFoundation\Request($data['get'], $data['post'], [], $data['cookie'], $data['files'], $data['server']); if (0 === strpos($l_request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($l_request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) { parse_str($l_request->getContent(), $data); $l_request->request = new Symfony\Component\HttpFoundation\ParameterBag($data); } Illuminate\Http\Request::enableHttpMethodParameterOverride(); $l_request = Illuminate\Http\Request::createFromBase($l_request); $l_response = $kernel->handle($l_request); $result = $l_response->getContent(); foreach ($l_response->headers->allPreserveCase() as $name => $values) { Http::header($name . ':' . implode(';', $values)); } // $l_response->send(); foreach ($l_response->headers->getCookies() as $cookie) { Http::setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } $kernel->terminate($l_request, $l_response); $connection->send($result); // } }; }
private function autoPopulateSuperGlobals() { if (is_null($this->brServerGlobals)) { $rqst = new \Symfony\Component\HttpFoundation\Request(); $this->brServerGlobals = $rqst->createFromGlobals(); } }
public function __construct() { $this->informatorInternalArray['composerLockFile'] = 'composer.lock'; $this->informatorInternalArray['knownLabels'] = $this->knownLabelsGlobal(['composerLockFile' => $this->informatorInternalArray['composerLockFile'], 'informatorFile' => __FILE__]); ksort($this->informatorInternalArray['knownLabels']); $rqst = new \Symfony\Component\HttpFoundation\Request(); $this->informatorInternalArray['superGlobals'] = $rqst->createFromGlobals(); echo $this->setInterface(); }
public function controllersProvider() { $parameters = ['string' => 'Test', 'int' => 1]; $getRequest = new \Symfony\Component\HttpFoundation\Request($parameters); $getRequest->setMethod('GET'); $postRequest = new \Symfony\Component\HttpFoundation\Request([], $parameters); $postRequest->setMethod('POST'); return [[new SymfonyController($getRequest)], [new SymfonyController($postRequest)]]; }
/** * @param Symfony\Component\HttpFoundation\Request $request * @param Symfony\Component\Debug\Exception\FlattenException $exception */ function it_renders_default_exception_response_when_templates_is_missing($request, $exception, $twig) { $twig->resolveTemplate(Argument::any())->willThrow(new \Twig_Error_Loader('')); $exception->getStatusCode()->willReturn(500); $exception->getHeaders()->willReturn([]); $request->setRequestFormat('html')->shouldBeCalled(); $response = $this($request, $exception, 'json'); $response->getStatusCode()->shouldReturn(500); }
public function __construct() { $this->getConfiguration(); echo $this->setHeaderHtml(); $rqst = new \Symfony\Component\HttpFoundation\Request(); $superGlobals = $rqst->createFromGlobals(); $this->prepareForOutputForm(['SuperGlobals' => $superGlobals]); if (!is_null($superGlobals->get('Label'))) { $this->processInfos(['sGlobals' => $superGlobals]); echo $this->setFormCurlInfos(['SuperGlobals' => $superGlobals]); echo $this->setFormInfos(['SuperGlobals' => $superGlobals]); } echo $this->setFooterHtml(); }
/** * Passes valuta-model conversion amount to response * @return String|Json */ public function convertValutaAction() { $result = ["ConversionAmountResult" => 0]; $dateTime = new DateTime(); $parameters = ['CurrencyFrom' => $this->request->get("CurrencyFrom"), 'CurrencyTo' => $this->request->get("CurrencyTo"), 'RateDate' => $dateTime->format("Y-m-d"), 'Amount' => $this->request->get("Amount")]; try { $soapClientService = new App\SoapClientService(); $soapClientService->addProvider(new Kowabunga()); $soapClientService->addProvider(new Webservicex()); $result["ConversionAmountResult"] = $soapClientService->getConversionAmount($parameters); $response = new JsonResponse($result); } catch (Exception $e) { $response = new JsonResponse(["error" => $e->getMessage()]); } return $response->send(); }
public function testSignSymfonyRequest() { $request = Symfony\Component\HttpFoundation\Request::create('http://somesite.com/sample/url', 'GET', ['foo' => 'bar']); $generator = new Generator(); $request = $generator->addSignatureToSymfonyRequest($request, 'myapi123', 'mysecret456'); $nonce = $request->headers->get('X-TOKENLY-AUTH-NONCE'); PHPUnit::assertGreaterThanOrEqual(time(), $nonce); PHPUnit::assertEquals('myapi123', $request->headers->get('X-TOKENLY-AUTH-API-TOKEN')); $expected_signature = $this->expectedSignature($nonce); PHPUnit::assertEquals($expected_signature, $request->headers->get('X-TOKENLY-AUTH-SIGNATURE')); }
public function onRequest() { $http = self::$serverInstance; $kernel = $this->kernel; $http->on('request', function ($request, $response) use($kernel) { $_SERVER = array_change_key_case($request->server); $l_request = new Symfony\Component\HttpFoundation\Request(isset($request->get) ? $request->get : [], isset($request->post) ? $request->post : [], [], isset($request->cookie) ? $request->cookie : [], isset($request->files) ? $request->files : [], $_SERVER, $request->rawContent()); if (0 === strpos($l_request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($l_request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) { parse_str($l_request->getContent(), $data); $l_request->request = new Symfony\Component\HttpFoundation\ParameterBag($data); } Illuminate\Http\Request::enableHttpMethodParameterOverride(); $l_request = Illuminate\Http\Request::createFromBase($l_request); $l_response = $kernel->handle($l_request); ob_start(); $l_response->send(); $kernel->terminate($l_request, $l_response); $result = ob_get_clean(); $response->end($result); }); }
/** * test case for api call if post values are not there * * @covers AppBundle\Controller\DemoController::indexAction */ public function testindexActionPostFails() { $defaultData = array('message' => 'Enter City Name Or Country Name For Weather'); $this->mockController->expects($this->once())->method('createFormBuilder')->with($this->equalTo($defaultData))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(0))->method('add')->with($this->equalTo('countryname'), $this->equalTo('text'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(1))->method('add')->with($this->equalTo('cityname'), $this->equalTo('text'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(2))->method('add')->with($this->equalTo('search'), $this->equalTo('submit'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->once())->method('getForm')->will($this->returnValue($this->mockForm)); $this->mockRequest->expects($this->once())->method('isMethod')->with($this->equalTo('POST'))->will($this->returnValue(false)); $this->mockController->expects($this->once())->method('render')->with($this->equalTo('AppBundle:Demo:show.html.twig'), $this->equalTo(array('form' => ''))); $this->mockController->indexAction($this->mockRequest); }
/** * Get the root URL for the request. * * @return string */ public function getCurrentUrl() { return $this->baseUrl ?: $this->request->url(); }
/** * Sets the URL values * * @param Symfony\Component\HttpFoundation\Request $request */ private function setURLFromSymfony($request) { $this->setQueryVar('acid', null); $this->m_publication = $this->_getPublication(); $language = $request->get('language', 'en'); $this->m_language = $this->_getLanguage($language, $this->m_publication); $this->m_issue = $this->_getIssue($request->get('issue'), $this->m_language, $this->m_publication); $this->m_section = $this->_getSection($request->get('section'), $this->m_issue, $this->m_language, $this->m_publication); $this->m_article = $this->_getArticle($request->get('articleNo'), $this->m_language); $this->m_template = $this->_getTemplate(); }
/** * Generates an URL based on the current URL. * * @see Controller::getPathFor() * @param array $parameters * @return string */ public function getUrlFor($routingData = array(), $parameters = array()) { $port = $this->request->getPort(); $portStr = $port != '80' ? ':' . $port : ''; return $this->request->getScheme() . '://' . $this->request->getHost() . $portStr . $this->getPathFor($routingData, $parameters); }
/** * Create URL based on passed $controller and $arguments * * @see functionPath */ public function functionUrl($controllerAction, $arguments = array(), $ajax = false) { $port = $this->request->getPort(); $portStr = $port != '80' ? ':' . $port : ''; return $this->request->getScheme() . '://' . $this->request->getHost() . $portStr . $this->functionPath($controllerAction, $arguments, $ajax); }
/** * Controller action which is used to upload a theme zip file * and extract it into the engine\Shopware\Themes folder. * * @throws Exception */ public function uploadAction() { /**@var $file UploadedFile */ $file = Symfony\Component\HttpFoundation\Request::createFromGlobals()->files->get('fileId'); $system = new Filesystem(); if (strtolower($file->getClientOriginalExtension()) !== 'zip') { $name = $file->getClientOriginalName(); $system->remove($file->getPathname()); throw new Exception(sprintf('Uploaded file %s is no zip file', $name)); } $targetDirectory = $this->container->get('theme_path_resolver')->getFrontendThemeDirectory(); if (!is_writable($targetDirectory)) { return $this->View()->assign(array('success' => false, 'error' => sprintf("Target Directory %s isn't writable", $targetDirectory))); } $this->unzip($file, $targetDirectory); $system->remove($file->getPathname()); $this->View()->assign('success', true); }
function request() { return Symfony\Component\HttpFoundation\Request::createFromGlobals(); }
public function isXmlHttpRequest() { return $this->request->isXmlHttpRequest(); }
<?php /** * Created by PhpStorm. * User: Kessiler * Date: 14/12/2014 * Time: 14:58 */ $app = new Silex\Application(); /** SERVICES */ $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\SessionServiceProvider()); $app->register(new Core\Service\ConfigServiceProvider(realpath(__DIR__) . "/../app/config/settings.json")); $app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $app['config']['database'])); $app['debug'] = $app['config']['debugger']; $app->boot(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => realpath(__DIR__) . '/../templates/' . $app['config']['template'], 'twig.options' => array('cache' => $app['config']['cache'] ? realpath(__DIR__) . "/../app/cache" : false, 'strict_variables' => true))); /** ROUTING */ Symfony\Component\HttpFoundation\Request::enableHttpMethodParameterOverride(); require_once realpath(__DIR__) . "/routes.php"; return $app;
/** * Check the request against $action_checks defined for * the controller action * * @param Symfony\Component\HttpFoundation\Request $request * @param string $action * Controller action name */ public function checkRequest($request, $action) { $request_method = strtolower($request->getMethod()); if (!empty($this->action_checks) && isset($this->action_checks[$action])) { $allowed_methods = $this->action_checks[$action]['methods']; $xhr_required = $this->action_checks[$action]['xhr']; // test http method if (isset($allowed_methods) && !in_array($request_method, $allowed_methods)) { header('HTTP/1.0 400 Bad Request'); exit('Wrong HTTP request method'); } // test for XHR header if (isset($xhr_required) && $xhr_required === TRUE && $request->headers->get('x-requested-with') != 'XMLHttpRequest') { header('HTTP/1.0 400 Bad Request'); exit('Required HTTP request header missing'); } } return $this; }
<?php require_once __DIR__ . '/../auth.php'; $request = Symfony\Component\HttpFoundation\Request::createFromGlobals(); if ($request->isXmlHttpRequest() === false) { redirige("../accueil.php"); } if (!est_autorise("acces_contenu")) { exit; } switch ($request->query->get('action')) { case 'changeDisplay': FolderAdmin::getInstance($request->query->get('folder_id'))->display($request->query->get('display')); break; }
/** * @param \React\Http\Request $request * * @return \Symfony\Component\HttpFoundation\Request */ private function convertRequest($request) { // Convert the React Request to a Symfony Request $symReq = new \Symfony\Component\HttpFoundation\Request(); // Set Method $symReq->setMethod($request->getMethod()); // Add path $symReq->server->set('REQUEST_URI', $request->getPath()); // TODO: consider appending http_build_query($request->getQuery()) // Add GET variables $symReq->query->add($request->getQuery()); // Add POST variables $symReq->request->add($request->getPost()); // Add headers $symReq->headers->add($request->getHeaders()); return $symReq; }
/** * @return Enlight_View|Enlight_View_Default */ public function importProfileAction() { /**@var $file UploadedFile */ $file = Symfony\Component\HttpFoundation\Request::createFromGlobals()->files->get('profilefile'); /** @var ProfileService $service */ $service = $this->get('swag_import_export.profile_service'); try { $service->importProfile($file); } catch (\Exception $e) { return $this->View()->assign(['success' => false, 'message' => $e->getMessage()]); } return $this->View()->assign(['success' => true]); }
return new Kodazzi\Console\Commands\ModelCommand(); }); Service::factory('command.form', function () { return new Kodazzi\Console\Commands\FormsCommand(); }); Service::factory('command.bundle', function () { return new Kodazzi\Console\Commands\BundleCommand(); }); Service::factory('command.routes', function () { return new Kodazzi\Console\Commands\RoutesCommand(); }); Service::set('shell', function () { return new Kodazzi\Console\Shell(); }); Service::factory('new.request', function () { return new Symfony\Component\HttpFoundation\Request(); }); // Captura la peticion Service::instance('kernel.request', Symfony\Component\HttpFoundation\Request::createFromGlobals()); // Agrega al contenedor la instancia de Request y loader. Service::instance('kernel.loader', $loader); // Suscribe los escuchas $dispatcher = Service::get('event'); $dispatcher->addSubscriber(Service::get('listener.router')); $dispatcher->addSubscriber(Service::get('listener.firewall')); $dispatcher->addSubscriber(Service::get('listener.controller')); $dispatcher->addSubscriber(Service::get('listener.locale')); $dispatcher->addSubscriber(Service::get('listener.response')); $dispatcher->addSubscriber(Service::get('listener.subrequest')); $dispatcher->addSubscriber(Service::get('listener.postaction')); $dispatcher->addSubscriber(Service::get('listener.exception'));
/** * Initializes HTTP request formats. */ protected static function initializeFormats() { return Symfony\Component\HttpFoundation\Request::initializeFormats(); }
/** * This is the same as invoke(), but it does *not* include exception * handling. * * @param array $args * The parts of the URL which identify the intended CiviCRM page * (e.g. array('civicrm', 'event', 'register')). * @return string * HTML. For non-HTML content, invoke() may call print() and exit(). */ public static function _invoke($args) { if ($args[0] !== 'civicrm') { return NULL; } // CRM-15901: Turn off PHP errors display for all ajax calls if (CRM_Utils_Array::value(1, $args) == 'ajax' || CRM_Utils_Array::value('snippet', $_REQUEST)) { ini_set('display_errors', 0); } if (!defined('CIVICRM_SYMFONY_PATH')) { // Traditional Civi invocation path self::hackMenuRebuild($args); // may exit self::init($args); self::hackStandalone($args); $item = self::getItem($args); return self::runItem($item); } else { // Symfony-based invocation path require_once CIVICRM_SYMFONY_PATH . '/app/bootstrap.php.cache'; require_once CIVICRM_SYMFONY_PATH . '/app/AppKernel.php'; $kernel = new AppKernel('dev', TRUE); $kernel->loadClassCache(); $response = $kernel->handle(Symfony\Component\HttpFoundation\Request::createFromGlobals()); if (preg_match(':^text/html:', $response->headers->get('Content-Type'))) { // let the CMS handle the trappings return $response->getContent(); } else { $response->send(); exit; } } }
public function __construct() { $rqst = new \Symfony\Component\HttpFoundation\Request(); echo $this->setApplicationHeader() . $this->buildApplicationInterface($rqst->createFromGlobals()) . $this->setApplicationFooter(); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; $app = new Silex\Application(); require __DIR__ . '/../app/config/dev.php'; require __DIR__ . '/../app/app.php'; require __DIR__ . '/../app/routes.php'; list($_, $method, $path) = $argv; $request = Symfony\Component\HttpFoundation\Request::create($path, $method); $app->run($request);
define('ROLE_ADMIN', 'ROLE_ADMIN'); $app['security.role_hierarchy'] = array('ROLE_ANONYMOUS' => array(), 'ROLE_GUEST' => array('ROLE_ANONYMOUS'), 'ROLE_USER' => array('ROLE_GUEST', 'ROLE_ANONYMOUS'), 'ROLE_MODERATOR' => array('ROLE_USER', 'ROLE_GUEST', 'ROLE_ANONYMOUS'), 'ROLE_ADMIN' => array('ROLE_USER', 'ROLE_MODERATOR', 'ROLE_GUEST', 'ROLE_ANONYMOUS')); $app['security.access_rules'] = array(array('^/admin', 'ROLE_ADMIN'), array('^/install', 'ROLE_ADMIN'), array('^/upgrade', 'ROLE_ADMIN'), array('^/moderator', 'ROLE_MODERATOR'), array('^/profile', 'ROLE_USER'), array('^/ajax', 'ROLE_GUEST'), array('^/', $config->get('is_chat_open') ? ROLE_ANONYMOUS : ROLE_ADMIN)); $app['security.provider'] = $app->share(function () use($app) { return new ElfChat\Security\Authentication\Provider($app['security.role_hierarchy'], $app['security.access_rules']); }); $app['security.middleware'] = $app->share(function () use($app) { return new ElfChat\Security\Authentication\SecurityMiddleware($app['security.provider'], $app['em'], $app['security.remember']); }); $app['security.remember'] = $app->share(function () use($app) { return new ElfChat\Security\Authentication\Remember($app->config()->get('remember_me.token')); }); /** * IP Trusted proxy */ Symfony\Component\HttpFoundation\Request::setTrustedProxies(array($config->get('trusted_proxy', '127.0.0.1'))); /** * Plugins */ $app['plugin_manager'] = $app->share(function () use($app) { return new ElfChat\Plugin\PluginManager($app->getPluginDir(), $app->getOpenDir() . '/plugins.php', $app['plugin_view_dir'], isset($app['installed_plugins']) ? $app['installed_plugins'] : array()); }); // Things to do not use then directory "open" does not writeable. if ($app->isOpen()) { // Http Cache $app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => $app->getCacheDir() . '/http/')); // Monolog $app->register(new Silex\Provider\MonologServiceProvider()); $app['monolog.name'] = 'ELFCHAT'; $app['monolog.logfile'] = $app->getLogDir() . '/error_log.txt'; $app['monolog.level'] = function () {
protected static function _invoke($args) { if ($args[0] !== 'civicrm') { return; } // CRM-15901: Turn off PHP errors display for all ajax calls if (CRM_Utils_Array::value(1, $args) == 'ajax' || CRM_Utils_Array::value('snippet', $_REQUEST)) { ini_set('display_errors', 0); } if (!defined('CIVICRM_SYMFONY_PATH')) { try { // Traditional Civi invocation path self::hackMenuRebuild($args); // may exit self::init($args); self::hackStandalone($args); $item = self::getItem($args); return self::runItem($item); } catch (CRM_Core_EXCEPTION $e) { $params = $e->getErrorData(); $message = $e->getMessage(); if (isset($params['legacy_status_bounce'])) { //@todo remove this- see comments on //https://github.com/eileenmcnaughton/civicrm-core/commit/ae686b09e2c987091612bb25ba0a58e520a203e7 CRM_Core_Error::statusBounce($params['message']); } else { $session = CRM_Core_Session::singleton(); $session->setStatus($message, CRM_Utils_Array::value('message_title', $params), CRM_Utils_Array::value('message_type', $params, 'error')); // @todo remove this code - legacy redirect path is an interim measure for moving redirects out of BAO // to somewhere slightly more acceptable. they should not be part of the exception class & should // be managed @ the form level - if you find a form that is triggering this piece of code // you should log a ticket for it to be removed with details about the form you were on. if (!empty($params['legacy_redirect_path'])) { if (CRM_Utils_System::isDevelopment()) { // here we could set a message telling devs to log it per above } CRM_Utils_System::redirect($params['legacy_redirect_path'], $params['legacy_redirect_query']); } } } catch (Exception $e) { // Recall: CRM_Core_Config is initialized before calling CRM_Core_Invoke $config = CRM_Core_Config::singleton(); return CRM_Core_Error::handleUnhandledException($e); /* if ($config->backtrace) { return CRM_Core_Error::formatHtmlException($e); } else { // TODO }*/ } } else { // Symfony-based invocation path require_once CIVICRM_SYMFONY_PATH . '/app/bootstrap.php.cache'; require_once CIVICRM_SYMFONY_PATH . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $response = $kernel->handle(Symfony\Component\HttpFoundation\Request::createFromGlobals()); // $response->send(); return $response->getContent(); } }
/** * handle error pages. * * @return \Symfony\Component\HttpFoundation\Response return response http foundation. */ public function handleErrors() { $this->Silexapp->error(function (\Exception $e, $code) { $request = new \Symfony\Component\HttpFoundation\Request(); switch ($code) { case 404: $subrequest = $request->create('/Error/E404'); $response = $this->Silexapp->handle($subrequest, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, false); $message = $response->getContent(); unset($response, $subrequest); break; case 403: $subrequest = $request->create('/Error/E403'); $response = $this->Silexapp->handle($subrequest, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, false); $message = $response->getContent(); unset($response, $subrequest); break; default: $subrequest = $request->create('/Error/E' . $code); $response = $this->Silexapp->handle($subrequest, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, false); $message = $response->getContent(); unset($response, $subrequest); } unset($request); return new \Symfony\Component\HttpFoundation\Response($message); }); }