createFromGlobals() public static method

Creates a new request with values from PHP's super globals.
public static createFromGlobals ( ) : Request
return Request A new request
Beispiel #1
0
 public function preview()
 {
     $request = \Request::getInstance();
     $c = \Page::getByID($this->request->get('cID'));
     $cp = new \Permissions($c);
     if ($cp->canViewPageVersions()) {
         $c->loadVersionObject(\Core::make('helper/security')->sanitizeInt($_REQUEST['cvID']));
         $spoofed_request = \Request::createFromGlobals();
         if ($device_handle = $request->headers->get('x-device-handle')) {
             if ($device = \Core::make('device/manager')->get($device_handle)) {
                 if ($agent = $device->getUserAgent()) {
                     $spoofed_request->headers->set('User-Agent', $agent);
                 }
             }
         }
         $spoofed_request->setCustomRequestUser(-1);
         $spoofed_request->setCurrentPage($c);
         \Request::setInstance($spoofed_request);
         $controller = $c->getPageController();
         $controller->runTask('view', array());
         $view = $controller->getViewObject();
         $response = new \Response();
         $content = $view->render();
         // Reset just in case.
         \Request::setInstance($request);
         $response->setContent($content);
         $response->send();
         exit;
     }
 }
Beispiel #2
0
 public function register()
 {
     $this->container->add('service.http.request', function () {
         return Request::createFromGlobals();
     });
     $this->container->add('service.http.route', function () {
         $route = new Route($this->container);
         foreach ($this->container->get('config')['http']['routes'] as $item) {
             $route->addRoute(strtoupper($item['method']), $item['path'], $item['target']);
         }
         return $route;
     });
     $this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () {
         return $this->container->get('service.http.request');
     });
     $this->container->add('service.view.view', function () {
         $view = new View();
         foreach ($this->container->get('config')['http']['views_path'] as $name => $path) {
             $view->addFolder($name, $path);
         }
         $request = $this->container->get('service.http.request');
         $view->loadExtension(new RequestExtension($request));
         $view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag()));
         $view->loadExtension(new BaseUrlExtension($request->getBasePath()));
         $assetBaseUrl = $this->container->get('config')['asset_base_url'];
         $view->loadExtension(new AssetUrlExtension($assetBaseUrl));
         if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) {
             $authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser();
             $view->loadExtension(new AuthenticatedUserExtension($authenticatedUser));
         }
         $view->addData(['applicationName' => $this->container->get('config')['application_name']]);
         return $view;
     });
 }
Beispiel #3
0
 /**
  * Handles the request and delivers the response.
  *
  * @param Request|null $request Request to process
  */
 public function run(BaseRequest $request = null)
 {
     if (null === $request) {
         $request = Request::createFromGlobals();
     }
     parent::run($request);
 }
Beispiel #4
0
 public function edit($media_id)
 {
     $this->form_validation->set_rules('meta', 'Meta', 'required');
     if ($this->form_validation->run() == FALSE) {
         $media = $this->medialib->getMedia();
         $media = $media->withDrafts()->findOrFail($media_id);
         $category = $media->category;
         $data['media'] = $media;
         $data['category'] = $category;
         $this->template->add_stylesheet('node_modules/awesomplete/awesomplete.css');
         $this->template->add_stylesheet('node_modules/video.js/dist/video-js.min.css');
         $this->template->add_script('node_modules/vue/dist/vue.min.js');
         $this->template->add_script('node_modules/awesomplete/awesomplete.min.js');
         $this->template->add_script('node_modules/video.js/dist/video.min.js');
         $this->template->add_script('javascript/elib.vue.js');
         $this->template->add_script('javascript/elib.js');
         $this->template->build('edit', $data);
     } else {
         $mediaLib = new Library\Media\Media();
         $media = $media->withDrafts()->findOrFail($media_id);
         $request = Request::createFromGlobals();
         $metadata = $request->request->get('meta');
         $mediaLib->setMetadata($media->id, $metadata);
         set_message_success('Metadata berhasil diperbarui.');
         redirect('elibrary/edit/' . $media->id, 'refresh');
     }
 }
Beispiel #5
0
 public function absoluteLink($path, Request $request = null)
 {
     if ($request === null) {
         $request = Request::createFromGlobals();
     }
     return $request->rootUri() . '/' . ltrim($path, '/');
 }
Beispiel #6
0
 public function sendRedirect($location)
 {
     $request = Request::createFromGlobals();
     $location = $request->baseUri() . '/' . ltrim($location, '/');
     $this->header('Location: ' . $location);
     $this->send();
 }
Beispiel #7
0
 public function run()
 {
     $request = Request::createFromGlobals();
     ob_start();
     $controlerResponse = $this->router->handleRequest($request);
     $response = $this->_getResponse($controlerResponse);
     $buf = ob_get_flush();
     $response->content = $buf . $response->content;
     $response->send();
 }
Beispiel #8
0
 /**
  * init appliaction
  *
  */
 public function init($path)
 {
     $this->initSelf();
     $request = \Request::createFromGlobals();
     $this->registerServices();
     $this->container = $this->singleton('container');
     $this->container->setAppPath($path);
     $this->router = new Router($this->container, $request);
     $this->router->match();
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bindIf('request', function () {
         return Request::createFromGlobals();
     });
     $this->app->singleton('Jscssbooster', function ($app) {
         return new Jscssbooster($app);
     });
     $this->app->singleton('Jscssbooster.bladeext', function ($app) {
         return new BladeExt($app);
     });
 }
Beispiel #10
0
 public function register()
 {
     $this->container['request'] = function () {
         return Request::createFromGlobals();
     };
     $this->container['Symfony\\Component\\HttpFoundation\\Request'] = function () {
         return $this->container->get('request');
     };
     $this->container['route'] = function () {
         $route = new Route($this->container);
         return $route;
     };
     $this->container->inflector('Jirro\\Component\\Http\\RouteAwareInterface')->invokeMethod('setRoute', ['route']);
 }
Beispiel #11
0
 public function start()
 {
     $request = Request::createFromGlobals();
     $response = new Response();
     $found = false;
     $requestKey = $request->server->REQUEST_METHOD . '@' . $request->server->PATH_INFO;
     foreach ($this->paths as $path => $callback) {
         if (preg_match('#^' . preg_replace('#\\{.*?\\}#', '([a-zA-Z0-9]+)', $path) . '$#', $requestKey, $params)) {
             array_shift($params);
             $params[] = $request;
             $params[] = $response;
             call_user_func_array($callback, $params);
             $found = true;
         }
     }
     if (!$found) {
         $this->errorPaths[Response::HTTP_NOT_FOUND]($request, $response);
     }
     $response->send();
 }
Beispiel #12
0
 /**
  * init appliaction
  *
  */
 public function init($path, $loader)
 {
     $this->initSelf();
     $this->doBootstrap($loader);
     $request = \Request::createFromGlobals();
     $this->registerServices();
     \EventDispatcher::dispatch(KernalEvent::INIT);
     $this->container = $this->singleton('container');
     $this->container->setAppPath($path);
     if ($this->container->isDebug()) {
         $debugbar = new \Group\Debug\DebugBar();
         self::getInstance()->singletons['debugbar'] = $debugbar;
     }
     $handler = new ExceptionsHandler();
     $handler->bootstrap($this);
     $this->container->setRequest($request);
     $this->router = new Router($this->container);
     self::getInstance()->router = $this->router;
     $this->router->match();
 }
 public function __construct()
 {
     $this->request = Request::createFromGlobals();
 }
Beispiel #14
0
<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = (require __DIR__ . '/../bootstrap/app.php');
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
date_default_timezone_set($_ENV['LOCALE']);
$app->run(Request::createFromGlobals());
Beispiel #15
0
 /**
  * Establishes the object instances that should be used for requests 
  * and responses.
  * 
  * @param \Micro\Request $req
  * @param \Micro\Responder $resp
  * @return array|\Micro\Request|\Micro\Response
  */
 protected function prepareRequestAndResponse(Request $req = null, Responder $resp = null)
 {
     return array($req ?: Request::createFromGlobals(), $resp ?: new Responder());
 }
 public function updateAction()
 {
     $request = Request::createFromGlobals();
     $session = $this->container->get('arii_core.session');
     $GlobalParams = array('ref_date', 'ref_past', 'ref_future', 'ref_refresh', 'spooler', 'custom_spooler');
     foreach ($GlobalParams as $p) {
         if ($request->query->get($p)) {
             $session->set($p, $request->query->get($p));
         }
     }
     print $session->get('ref_past');
     foreach (array('STOPPED', 'FAILURE', 'SUCCESS', 'RUNNING', 'LATE') as $s) {
         $status = $session->get('status');
         if ($request->get($s) == 'true') {
             $status[$s] = 1;
         }
         if ($request->get($s) == 'false') {
             $status[$s] = 0;
         }
         $session->set('status', $status);
     }
     print_r($session->get('status'));
     //file_put_contents("c:/temp.txt", $session->get('status'));
     # Cas particulier
     /*
     foreach ( array('STOPPED','FAILURE','SUCCESS','RUNNING','LATE') as $s ){
     if ($request->query->get($s)) {
         $Status = $session->get( 'Status' );
        // $r = 0;
         if ($request->query->get($s) == 'true')
         {   
             $r = 1;
         }
         elseif ($request->query->get($s) == 'false')
         {
             $r = 0;
         }
         $Status[$s] = $r;
         $session->set( 'Status', $Status );
     } 
     }
     * 
     */
     // print_r($Status);
     exit;
 }
Beispiel #17
0
<?php

require './example.php';
// use Thenbsp\Wechat\Util\Http;
// use Thenbsp\Wechat\Util\Request;
// use Thenbsp\Wechat\Util\Serialize;
// 生成带参数的二维码
// $options = array(
//     'expire_seconds'    => 604800,
//     'action_name'       => 'QR_SCENE',
//     'action_info'       => array(
//         'scene' => array(
//             'scene_id' => '123456'
//         )
//     )
// );
// $options = Serialize::encode($options, 'json');
// $request = Http::post('https://api.weixin.qq.com/cgi-bin/qrcode/create', array(
//     'query' => array(
//         'access_token' => $accessToken->getAccessToken()
//     ),
//     'body' => $options
// ));
// $response = $request->json();
// echo sprintf('<img  src="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s" />', $response['ticket']);
// 记录请求内容
$request = Request::createFromGlobals();
$cache->set(date('YmdHis'), $request->getContent());
Beispiel #18
0
 public function testMethodCanBeInjectedViaPostParam()
 {
     $_POST['_method'] = 'put';
     $request = Request::create(false, 'localhost', '/test');
     $this->assertEquals('PUT', $request->method());
     $_SERVER['REQUEST_URI'] = '/test';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $request = Request::createFromGlobals();
     $this->assertEquals('PUT', $request->method());
     unset($_POST['_method']);
 }
 public function getRequest()
 {
     if (!$this->has('request')) {
         $this->set('request', Request::createFromGlobals());
     }
     return $this->get('request');
 }
Beispiel #20
0
<?php

/* Inversion of control */
$input = fopen('php://stdin', 'r');
echo "\nDigita il tuo nome: ";
$nome = fread($input, 200);
registra_nome($nome);
echo "\nDigita il tuo cognome: ";
$cognome = fread($input, 200);
registra_cognome($cognome);
echo "\nDigita il tuo indirizzo: ";
$indirizzo = fread($input, 200);
registra_indirizzo($indirizzo);
require 'shell.php';
$shell = new Shell();
$shell . question("Digita il tuo nome: ", 'registra_nome');
$shell . question("Digita il tuo cognome: ", 'registra_conome');
$shell . question("Digita il tuo indirizzo: ", 'registra_indirizzo');
$shell . execute();
/* Dependency Injection container */
$flickr_api = $container->get('flickr_api');
//...
$photo_sets = $flickr_api->getPhotoSets();
//...
$recent_photos = $flickr_api->getRecentPhotos(12);
//...
/* Uso del DIC */
$container = new DIC();
$response = $container->get('http_kernel')->handle(Request::createFromGlobals());
$response->sendHeaders();
$response->sendContent();
 public function validate()
 {
     $ak = $this->getAttributeKeyObject();
     if (is_object($ak)) {
         $e = \Core::make('error');
         if ($this->isFormSubmission()) {
             $controller = $ak->getController();
             $validator = $controller->getValidator();
             $control = $this->getPageTypeComposerFormLayoutSetControlObject();
             $response = $validator->validateSaveValueRequest($controller, \Request::createFromGlobals());
             /**
              * @var $response ResponseInterface
              */
             if (!$response->isValid()) {
                 $error = $response->getErrorObject();
                 $e->add($error);
             }
         } else {
             $value = $this->getPageTypeComposerControlDraftValue();
             if (!is_object($value)) {
                 $control = $this->getPageTypeComposerFormLayoutSetControlObject();
                 $e->add(t('The field %s is required', $control->getPageTypeComposerControlLabel()));
             } else {
                 $controller = $ak->getController();
                 $validator = $controller->getValidator();
                 $response = $validator->validateCurrentAttributeValue($controller, $value);
                 if (!$response->isValid()) {
                     $error = $response->getErrorObject();
                     $e->add($error);
                 }
             }
         }
         return $e;
     }
 }
 /**
  * Runs the application.
  *
  * @return self
  */
 public function run()
 {
     $req = Request::createFromGlobals();
     $this->handleRequest($req)->send();
     return $this;
 }
Beispiel #23
0
function yolo($controller)
{
    $request = Request::createFromGlobals();
    $response = $controller($request);
    $response->send();
}