createFromGlobals() public static method

Creates a new request with values from PHP's super globals.
public static createFromGlobals ( ) : Request
return Request A new request
Example #1
0
 /**
  * @param \Silex\Application $app
  */
 public function __construct(Silex\Application $app)
 {
     $this->app = $app;
     $this->db = $app['db'];
     $prefix = $this->app['config']->get('general/database/prefix', 'bolt_');
     // Hashstrength has a default of '10', don't allow less than '8'.
     $this->hashStrength = max($this->app['config']->get('general/hash_strength'), 8);
     $this->usertable = $prefix . 'users';
     $this->authtokentable = $prefix . 'authtoken';
     $this->users = array();
     $this->session = $app['session'];
     /*
      * Get the IP stored earlier in the request cycle. If it's missing we're on CLI so use localhost
      *
      * @see discussion in https://github.com/bolt/bolt/pull/3031
      */
     $request = Request::createFromGlobals();
     $this->hostName = $request->getHost();
     $this->remoteIP = $request->getClientIp() ?: '127.0.0.1';
     $this->userAgent = $request->server->get('HTTP_USER_AGENT');
     $this->authToken = $request->cookies->get('bolt_authtoken');
     // Set 'validsession', to see if the current session is valid.
     $this->validsession = $this->checkValidSession();
     $this->allowed = array('dashboard' => self::EDITOR, 'settings' => self::ADMIN, 'login' => self::ANONYMOUS, 'logout' => self::EDITOR, 'dbcheck' => self::ADMIN, 'dbupdate' => self::ADMIN, 'clearcache' => self::ADMIN, 'prefill' => self::DEVELOPER, 'users' => self::ADMIN, 'useredit' => self::ADMIN, 'useraction' => self::ADMIN, 'overview' => self::EDITOR, 'editcontent' => self::EDITOR, 'editcontent:own' => self::EDITOR, 'editcontent:all' => self::ADMIN, 'contentaction' => self::EDITOR, 'about' => self::EDITOR, 'extensions' => self::DEVELOPER, 'files' => self::EDITOR, 'files:config' => self::DEVELOPER, 'files:theme' => self::DEVELOPER, 'files:uploads' => self::ADMIN, 'translation' => self::DEVELOPER, 'activitylog' => self::ADMIN, 'fileedit' => self::ADMIN);
 }
Example #2
0
 /**
  * Builds absolute url address.
  *
  * Example of usage: url('/nmkd/input', array($id));.
  *
  * @param string $uri
  * @param array $params
  * @return string
  */
 public static function buildUrl($uri, $params = array())
 {
     $strParams = '';
     if (!empty($params)) {
         if (strpos($uri, '?') == false) {
             $strParams .= '?';
         } else {
             $strParams .= '&';
         }
         foreach ($params as $param => $val) {
             $strParams .= $param . '=' . $val . '&';
         }
         $strParams = substr($strParams, 0, -1);
     }
     $request = Request::createFromGlobals();
     $protocol = $request->isSecure() ? 'https' : 'http';
     $baseUrl = $request->server->get('SERVER_NAME');
     $doc_root = $request->server->get('DOCUMENT_ROOT');
     $full_path = $request->server->get('SCRIPT_FILENAME');
     $file = basename($request->server->get('SCRIPT_FILENAME'));
     $urlSlug = str_replace($file, '', str_replace($doc_root, '', $full_path));
     $uri = ltrim($uri, '/');
     $urlSlug = ltrim($urlSlug, '/');
     return $protocol . '://' . $baseUrl . '/' . $urlSlug . $uri . $strParams;
 }
Example #3
0
 /**
  * @return bool
  */
 public static function checkAuth()
 {
     $currentCwd = getcwd();
     if (!self::$authenticated) {
         if (!defined('ACP3_ROOT_DIR')) {
             define('ACP3_ROOT_DIR', realpath(__DIR__ . '/../../../../../../../') . '/');
         }
         require_once ACP3_ROOT_DIR . 'vendor/autoload.php';
         $application = new Bootstrap(ApplicationMode::PRODUCTION);
         if ($application->startupChecks()) {
             $symfonyRequest = Request::createFromGlobals();
             $application->initializeClasses($symfonyRequest);
             chdir(ACP3_ROOT_DIR);
             $application->getContainer()->get('core.authentication')->authenticate();
             // if user has access permission...
             if ($application->getContainer()->get('users.model.user_model')->isAuthenticated()) {
                 if (!isset($_SESSION['KCFINDER'])) {
                     $_SESSION['KCFINDER'] = [];
                     $_SESSION['KCFINDER']['disabled'] = false;
                 }
                 // User has permission, so make sure KCFinder is not disabled!
                 $_SESSION['KCFINDER']['disabled'] = false;
                 chdir($currentCwd);
                 self::$authenticated = true;
             }
         }
     }
     chdir($currentCwd);
     return self::$authenticated;
 }
 /**
  * BaseController constructor.
  *
  * @param BaseModel $model Model that will be handled by this Controller
  * @param BaseView $view View that will be rendered by this Controller
  */
 public function __construct(BaseModel $model, BaseView $view)
 {
     $this->model = $model;
     $this->view = $view;
     $this->request = empty(Runner::$request) ? Request::createFromGlobals() : Runner::$request;
     $this->session = new Session($this->request);
 }
Example #5
0
 public function dispatch()
 {
     $dispatcher = $this->router->getDispatcher();
     $request = Request::createFromGlobals();
     $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
     return $response->send();
 }
 /**
  * {@inheritdoc}
  */
 public function loadUserByUsername($username, $password = null)
 {
     // if the password is not passed in, we have arrived here from a login form, so grab it from the request
     if (null === $password) {
         $password = Request::createFromGlobals()->get('_password');
     }
     $credentials = array('email' => $username, 'password' => $password);
     $client = $this->irisEntityManager->getClient();
     // use the MAC in the session to access the cached system credentials
     $authData = $this->session->get('auth-data');
     if (!$client->hasValidCredentials($authData->get('systemKey'), $authData->get('systemSecret'))) {
         throw new BadCredentialsException('Invalid System credentials for IRIS');
     }
     // attempt to authenticate and get the Landlords key and secret
     if (false === ($oauthCredentials = $client->assume($credentials))) {
         // invalid credentials
         throw new UsernameNotFoundException('Invalid Landlord credentials for IRIS');
     }
     // create the User to return it to be stored in the session
     $user = new LandlordUser($authData->get('systemKey'), $authData->get('systemSecret'), $username, $password);
     // manually set the consumer key and secret as the username and password do not represent them
     $user->setConsumerKey($oauthCredentials['consumerKey']);
     $user->setConsumerSecret($oauthCredentials['consumerSecret']);
     return $user;
 }
Example #7
0
 /**
  * Get Request either from the container or else create it from globals.
  *
  * @return \Symfony\Component\HttpFoundation\Request
  */
 protected function getRequest()
 {
     if ($this->getContainer()->isRegistered('Symfony\\Component\\HttpFoundation\\Request') || $this->getContainer()->isInServiceProvider('Symfony\\Component\\HttpFoundation\\Request')) {
         return $this->getContainer()->get('Symfony\\Component\\HttpFoundation\\Request');
     }
     return Request::createFromGlobals();
 }
Example #8
0
 protected function processView()
 {
     $this->preProcessView();
     $themeSettings = Container::get('theme_settings');
     $request = Request::createFromGlobals();
     /*if ($request->isXmlHttpRequest()) {
                 if ($request->request->has('ajaxData')) {
                     $ajaxData = $request->request->get('ajaxData');
                     if (isset($ajaxData['component']) && isset($ajaxData['block'])) {
                         $themeSettings = $themeSettings['items'][$ajaxData['block']][$ajaxData['component']];
                         $globalTemplateData = array(
                             'errors' => $this->errors,
                         );
     
                         $globalTemplateData = array_merge_recursive(
                             $globalTemplateData,
                             $themeSettings
                         );
                         return $globalTemplateData;
                     }
                 }
             }*/
     $globalTemplateData = array('errors' => $this->errors);
     $globalTemplateData = array_merge_recursive($globalTemplateData, $themeSettings);
     //dynamic template data, wich uses in all templates (many templates)
     //menu data, sidebar data, etc
     return $globalTemplateData;
 }
Example #9
0
 /**
  * Apply the request filters, call the front controller and returns a Response
  *
  * @param string $path
  * @return Response
  * @throws \Exception
  */
 private function handleRequest($path)
 {
     try {
         // Create a request object
         $request = Request::createFromGlobals();
         // Decode the path and add the params to the request
         $controllerActionParams = $this->router->decode($path);
         $request->query->add($controllerActionParams->params);
         // Apply optional filters on the Request
         if ($this->provider->has('request.filters')) {
             foreach ($this->provider->lookup('request.filters') as $filter) {
                 // The request filter can return a Response. If it does, the controller won't be called
                 /** @var $filter RequestFilter */
                 $response = $filter->apply($request);
                 if ($response instanceof Response) {
                     return $response;
                 }
             }
         }
         // Execute the appropriate controller/action
         $controller = $this->provider->create($controllerActionParams->controller, $request);
         return $controller->handle($controllerActionParams->action);
     } catch (\Exception $e) {
         // Check if we have an exception controller
         if (!$this->provider->has('exception.controller')) {
             throw $e;
         }
         $exceptionController = $this->provider->lookup('exception.controller');
         return $exceptionController->handle($e);
     }
 }
 /**
  * Initializes the Contao framework.
  *
  * @return InitializeControllerResponse
  *
  * @Route("/_contao/initialize", name="contao_initialize")
  */
 public function indexAction()
 {
     @trigger_error('Custom entry points are deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
     $masterRequest = $this->get('request_stack')->getMasterRequest();
     $realRequest = Request::createFromGlobals();
     $scope = ContaoCoreBundle::SCOPE_FRONTEND;
     if (defined('TL_MODE') && 'BE' === TL_MODE) {
         $scope = ContaoCoreBundle::SCOPE_BACKEND;
     }
     // Necessary to generate the correct base path
     foreach (['REQUEST_URI', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF'] as $name) {
         $realRequest->server->set($name, str_replace(TL_SCRIPT, 'app.php', $realRequest->server->get($name)));
     }
     $realRequest->attributes->replace($masterRequest->attributes->all());
     // Initialize the framework with the real request
     $this->get('request_stack')->push($realRequest);
     if (method_exists('Symfony\\Component\\DependencyInjection\\Container', 'enterScope')) {
         $this->container->enterScope($scope);
     }
     $this->container->get('contao.framework')->initialize();
     // Add the master request again. When Kernel::handle() is finished,
     // it will pop the current request, resulting in the real request being active.
     $this->get('request_stack')->push($masterRequest);
     return new InitializeControllerResponse('', 204);
 }
Example #11
0
 public function __construct(UnderlyingRequest $request = null)
 {
     $request = $request ?: UnderlyingRequest::createFromGlobals();
     $this->URI = $request->getPathInfo();
     $this->referrer = $request->server->get('HTTP_REFERER');
     parent::__construct($this->base($request), $this->attributes($request));
 }
 public function editAction($id, $threadid, $postid)
 {
     $request = Request::createFromGlobals();
     $em = $this->getDoctrine()->getManager();
     $user = $this->get('security.context')->getToken()->getUser();
     # get thread and validate
     $post = $em->getRepository('MaximModuleForumBundle:Post')->findOneBy(array("id" => $postid));
     if (!$post) {
         throw $this->createNotFoundException("Could not find the requested post");
     }
     if ($post->getCreatedBy()->getId() != $user->getId()) {
         throw new AccessDeniedException("You are not allowed to edit this post");
     }
     # create form
     $postedit = new PostEdit($post, $user);
     $form = $this->createForm(new PostEditType(), $postedit);
     # handle form
     $form->handleRequest($request);
     if ($form->isValid()) {
         $postedit = $form->getData();
         $em->flush();
         $this->get('session')->getFlashBag()->add('notice', 'Your post has been updated!');
         return $this->redirect($this->generateUrl('forum_thread_view', array('id' => $post->getThread()->getForum()->getId(), 'threadid' => $post->getThread()->getId())));
     }
     # set vars
     $data['form'] = $form->createView();
     $data['post'] = $post;
     return $this->render('MaximCMSBundle:Forum:editPost.html.twig', $data);
 }
Example #13
0
 public function __construct()
 {
     $this['app_version'] = "1.0";
     // property injection
     $this['request'] = Request::createFromGlobals();
     // static method injection
 }
Example #14
0
 public function __construct(StorageInterface $storage, Options $options, Request $request = null, IpTransformer $ip_transformer = null)
 {
     $this->storage = $storage;
     $this->options = $options;
     $this->request = $request ? $request : Request::createFromGlobals();
     $this->ip_transformer = $ip_transformer ? $ip_transformer : new IpTransformer();
 }
 /**
  * Creates a new request with values from PHP's super globals. 
  * Overwrite to fix an apache header bug. Read more here:
  * http://stackoverflow.com/questions/11990388/request-headers-bag-is-missing-authorization-header-in-symfony-2%E2%80%94
  *
  * @return Request A new request
  *
  * @api
  */
 public static function createFromGlobals()
 {
     $request = parent::createFromGlobals();
     //fix the bug.
     self::fixAuthHeader($request->headers);
     return $request;
 }
Example #16
0
 /**
  * Настраиваем зависимости фреймворка.
  */
 protected function setDefaultDependencies()
 {
     $this->container->set(Request::class, function (Container $c) {
         return Request::createFromGlobals();
     });
     $this->container->set(Response::class, function (Container $c) {
         return Response::create();
     });
     $this->container->set(RouteParser::class, function (Container $c) {
         return new RouteParser\Std();
     });
     $this->container->set(RouteCollector::class, function (Container $c) {
         /** @var RouteParser $routeParser */
         $routeParser = $c->get(RouteParser::class);
         return new RouteCollector($routeParser, new RouteDataGenerator());
     });
     $this->container->set(RouteDispatcher::class, function (Container $c) {
         /** @var RouteCollector $router */
         $router = $c->get(RouteCollector::class);
         return new RouteDispatcher($router->getData());
     });
     $this->container->set(UrlGenerator::class, function (Container $c) {
         /** @var RouteCollector $routeCollector */
         $routeCollector = $c->get(RouteCollector::class);
         /** @var RouteParser $routeParser */
         $routeParser = $c->get(RouteParser::class);
         return new UrlGenerator($routeCollector, $routeParser);
     });
 }
Example #17
0
 public static function compress(string $output)
 {
     $request = Request::createFromGlobals();
     // Check to see if we have data, if not, then return empty string
     if ($output === null) {
         return (string) '';
     }
     // Handle the supported compressions.
     $supported_enc = array();
     if ($request->headers->get('HTTP_ACCEPT_ENCODING')) {
         $supported_enc = explode(',', $request->headers->get('HTTP_ACCEPT_ENCODING'));
     }
     if (in_array('gzip', $supported_enc) === true) {
         header('Vary: Accept-Encoding');
         header('Content-Encoding: gzip');
         $encoded_output = gzencode($output, 9);
         return (string) $encoded_output;
     } elseif (in_array('deflate', $supported_enc) === true) {
         header('Vary: Accept-Encoding');
         header('Content-Encoding: deflate');
         $deflated_output = gzdeflate($output, 9);
         return (string) $deflated_output;
     } else {
         return (string) $output;
     }
 }
Example #18
0
 /**
  * Get the current request
  * @return \Symfony\Component\HttpFoundation\Request
  */
 public function getRequest()
 {
     if (is_null($this->request)) {
         $this->request = Request::createFromGlobals();
     }
     return $this->request;
 }
 public function action(RouterInterface $router, RequestContext $context)
 {
     $request = Request::createFromGlobals();
     $bPath = $context->getPathInfo();
     try {
         $parameters = $router->match($bPath);
         var_dump($parameters);
         $_controller = $parameters["_controller"];
         $_controller = explode(":", $_controller);
         $class = $_controller[0];
         $action = strtolower($_controller[1]) . "Action";
         $class = new $class();
         ob_start();
         if (method_exists($class, $action)) {
             $class->{$action}($request, new JsonResponse());
             $response = new Response(ob_get_clean());
         } else {
             $response = new Response('Not Found', 404);
         }
     } catch (ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred', 500);
     }
     $response->send();
 }
Example #20
0
 /**
  * Run Application.
  */
 public function run()
 {
     $request = $this['request'] = Request::createFromGlobals();
     $routes = $this['routes'];
     $context = $this['request_context'];
     $context->fromRequest($this['request']);
     $matcher = new UrlMatcher($routes, $context);
     $resolver = new ControllerResolver();
     try {
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         if (is_array($controller) && $controller[0] instanceof \Task\Controllers\BaseController) {
             $controller[0]->setRequest($request);
             $controller[0]->setApplication($this);
         }
         $response = call_user_func_array($controller, $arguments);
     } catch (ResourceNotFoundException $e) {
         $response = new JsonResponse(["errors" => ["type" => "Not found"]], Response::HTTP_NOT_FOUND);
     } catch (\Exception $e) {
         $response = new JsonResponse(["errors" => ["type" => $e->getMessage(), "stacktrace" => $e->getTraceAsString()]], Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     $response->headers->set("Access-Control-Allow-Origin", "*");
     $response->headers->set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
     $response->headers->set("Access-Control-Allow-Headers", "Content-Type");
     $response->headers->set("Server", "Test task REST");
     return $response;
 }
Example #21
0
 /**
  * Return the object instance (Singleton)
  *
  * @return \Symfony\Component\HttpFoundation\Request The object instance
  *
  */
 public static function getInstance()
 {
     if (static::$objInstance === null) {
         static::$objInstance = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     }
     return static::$objInstance;
 }
Example #22
0
 /**
  * @return Request
  */
 public function getRequest()
 {
     if (!$this->request) {
         $this->setRequest(Request::createFromGlobals());
     }
     return $this->request;
 }
 public function register(Application $app)
 {
     $app['access_control.cookie.options'] = $app->share(function () use($app) {
         return ['remoteaddr' => $app['config']->get('general/cookies_use_remoteaddr', true), 'browseragent' => $app['config']->get('general/cookies_use_browseragent', false), 'httphost' => $app['config']->get('general/cookies_use_httphost', true), 'lifetime' => $app['config']->get('general/cookies_lifetime', 1209600)];
     });
     $app['access_control.hash.strength'] = $app->share(function () use($app) {
         return max($app['config']->get('general/hash_strength'), 8);
     });
     $app['access_control'] = $app->share(function ($app) {
         $tracker = new AccessControl\AccessChecker($app['storage.lazy'], $app['request_stack'], $app['session'], $app['dispatcher'], $app['logger.flash'], $app['logger.system'], $app['permissions'], $app['randomgenerator'], $app['access_control.cookie.options']);
         return $tracker;
     });
     $app['access_control.login'] = $app->share(function ($app) {
         $login = new AccessControl\Login($app);
         return $login;
     });
     $app['access_control.password'] = $app->share(function ($app) {
         $password = new AccessControl\Password($app);
         return $password;
     });
     $app['password_factory'] = $app->share(function () {
         return new PasswordFactory();
     });
     $app['token.authentication.name'] = $app->share(function ($app) {
         $request = $app['request_stack']->getCurrentRequest() ?: Request::createFromGlobals();
         $name = 'bolt_authtoken_' . md5($request->getHttpHost() . $request->getBaseUrl());
         return $name;
     });
 }
Example #24
0
 /**
  * start up the system, load configs etc...
  *
  * @access public
  */
 public function __construct()
 {
     // load up the configuration
     $this->loadConfig();
     // load up the request
     $this->request = Request::createFromGlobals();
 }
Example #25
0
 /**
  * @Route("/register", name="security_register")
  * @Method("POST")
  */
 public function registerAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $request = Request::createFromGlobals();
     $email = $request->request->get('email');
     $password = $request->request->get('password');
     $ico = trim($request->request->get('ico'));
     $user = new User();
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
     $user->setEmail($email);
     $user->setIco($ico);
     $backgroundImages = ['animal', 'corn', 'farming', 'chicken'];
     shuffle($backgroundImages);
     $user->setBackgroundImage($backgroundImages[0]);
     $profileImages = ['animal', 'corn', 'farming', 'chicken'];
     shuffle($profileImages);
     $user->setProfileImage($profileImages[0]);
     $em->persist($user);
     $em->flush();
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->get('security.token_storage')->setToken($token);
     //rabbit MQ
     $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
     $channel = $connection->channel();
     $channel->queue_declare('ico_queue', false, false, false, false);
     $json = json_encode(["userId" => $user->getId(), "ico" => $ico]);
     $msg = new AMQPMessage($json);
     $channel->basic_publish($msg, '', 'ico_queue');
     dump(" [x] Sent '{$ico}'\n");
     $channel->close();
     $connection->close();
     return $this->redirect($this->generateUrl('main_overview'));
 }
 /**
  * Tests tablesort_init().
  */
 function testTableSortInit()
 {
     // Test simple table headers.
     $headers = array('foo', 'bar', 'baz');
     // Reset $request->query to prevent parameters from Simpletest and Batch API
     // ending up in $ts['query'].
     $expected_ts = array('name' => 'foo', 'sql' => '', 'sort' => 'asc', 'query' => array());
     $request = Request::createFromGlobals();
     $request->query->replace(array());
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.');
     // Test with simple table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test with simple table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('sort' => 'DESC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts['sort'] = 'desc';
     $expected_ts['query'] = array('alpha' => 'beta');
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.');
     // Test complex table headers.
     $headers = array('foo', array('data' => '1', 'field' => 'one', 'sort' => 'asc', 'colspan' => 1), array('data' => '2', 'field' => 'two', 'sort' => 'desc'));
     // Reset $_GET from previous assertion.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '2'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '2', 'sql' => 'two', 'sort' => 'desc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers sorted correctly.');
     // Test complex table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test complex table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '1', 'sort' => 'ASC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array('alpha' => 'beta'));
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.');
 }
 public function update()
 {
     echo 'no ';
     $input = Request::createFromGlobals();
     //  echo $input->request->get('token');
     if ($this->checkCsrf($input->request->get('token'))) {
         echo 'update';
         /*try{
         
                         $this->app->settingsForm->validator($_POST);
         
                         $this->app['general_setting_db']->update( 'id', \Input::post('id'), [
                             'site_url'            => \Input::post('site_url'),
                             'site_title'          => \Input::post('site_title'),
                             'sentFromEmail'          => \Input::post('sentFromEmail'),
                             'footer_text'         => \Input::post('footer_text'),
                             //'popular_video_views' => Input::post('popular_video_views'),
                         ] );
                         \App::flash('settings-msg', 'General settings updated!');
                         \Response::redirect( $this->site_url.'/admin-area/settings');
         
                     }catch (\Doowebdev\Validation\DooFormValidationException $e)
                     {
                         $this->data['site_title_errors'] =  $e->getErrorFor()->first('site_title');
                         return \View::display('admin/setting/settings.twig', $this->data );
                    }*/
     }
     return '';
 }
Example #28
0
 /**
  * @covers \Foote\Ginny\Command\GinnyInput::getOptionsFromRequest
  * @covers \Foote\Ginny\Command\GinnyInput::__construct
  */
 public function testgetOptionsFromRequest()
 {
     $request = Request::createFromGlobals();
     $argv = $request->server->get('argv');
     $request->server->set('argv', ['ginny:generate', '--root=my/root/path/', '--extra=none', '-p', 'Manage', 'test1', 'test2=result2']);
     // ensures that $request->server in GinnyInput::get() loads the new argv
     $request->overrideGlobals();
     $passed = GinnyInput::getOptionsFromRequest();
     $this->assertTrue(array_key_exists('--root', $passed));
     $this->assertTrue(array_key_exists('--extra', $passed));
     $this->assertTrue(array_key_exists('-p', $passed));
     $this->assertEquals('my/root/path/', $passed['--root']);
     $this->assertEquals('none', $passed['--extra']);
     $this->assertEquals('Manage', $passed['-p']);
     //test that the other stuff isn't pass on
     $this->assertFalse(array_key_exists('test1', $passed));
     $this->assertFalse(array_key_exists('--test1', $passed));
     $this->assertFalse(array_key_exists('test2', $passed));
     $this->assertFalse(array_key_exists('--test2', $passed));
     $yaml = new \Symfony\Component\Yaml\Parser();
     $local_defaults = $yaml->parse(file_get_contents(__DIR__ . '/../../ginny.dist.yml'));
     $local_defaults['root'] = __DIR__ . '/../../';
     /**
      * Ensure that GinnyInput::getOptionsFromRequest() is invoked when get()
      * is called without $passed. -p=Manage above should override prefix=Admin
      * found in $local_defaults
      */
     $input = new GinnyInput($local_defaults);
     $this->assertEquals('Manage', $input->getParameterOption('--prefix'));
     // restore $_SERVER['argv']
     $request->server->set('argv', $argv);
     $request->overrideGlobals();
 }
 public static function getRequest()
 {
     if (self::$request_instance === NULL) {
         self::$request_instance = Request::createFromGlobals();
     }
     return self::$request_instance;
 }
Example #30
-1
 public function onRequest($request, $response)
 {
     // global vars used by: Symfony\Component\HttpFoundation\Request::createFromGlobals()
     // this static method is alse used by Illuminate\Auth\Guard
     $this->setGlobal($request);
     // according to : Illuminate\Http\Request::capture
     // static::enableHttpMethodParameterOverride(); // this line moved to $this->bootstrap() :
     $laravel_request = \Illuminate\Http\Request::createFromBase(\Symfony\Component\HttpFoundation\Request::createFromGlobals());
     // see: Illuminate\Foundation\Http\Kernel::handle($request)
     $laravel_response = $this->kernel->handle($laravel_request);
     //  sometimes there are errors saying 'http_onReceive: connection[...] is closed' and this type of error make worker restart
     if (!$this->swoole_http_server->exist($response->fd)) {
         return;
     }
     foreach ($laravel_response->headers->allPreserveCase() as $name => $values) {
         foreach ($values as $value) {
             $response->header($name, $value);
         }
     }
     foreach ($laravel_response->headers->getCookies() as $cookie) {
         $response->cookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
     }
     // I think " $l_response->send()" is enough
     // $response->status($l_response->getStatusCode());
     // gzip use nginx
     // $response->gzip(1);
     ob_start();
     // $laravel_response->send() contains setting header and cookie ,and $response->header and $response->cookie do same jobs.
     // They are all necessary , according by my test
     $laravel_response->send();
     $response->end(ob_get_clean());
     $this->kernel->terminate($laravel_request, $laravel_response);
     $this->app->restoreAfterRequest();
 }