method() public static method

Get the request method.
public static method ( ) : string
return string
Example #1
0
 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
     // Create an http request object
     $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
     if ($this->_options) {
         // Set custom options
         $http_request->setOptions($this->_options);
     }
     // Set headers
     $http_request->setHeaders($request->headers()->getArrayCopy());
     // Set cookies
     $http_request->setCookies($request->cookie());
     // Set query data (?foo=bar&bar=foo)
     $http_request->setQueryData($request->query());
     // Set the body
     if ($request->method() == HTTP_Request::PUT) {
         $http_request->addPutData($request->body());
     } else {
         $http_request->setBody($request->body());
     }
     try {
         $http_request->send();
     } catch (HTTPRequestException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPMalformedHeaderException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPEncodingException $e) {
         throw new Request_Exception($e->getMessage());
     }
     // Build the response
     $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
     return $response;
 }
Example #2
0
 /**
  * Test the Request::method method.
  *
  * @group laravel
  */
 public function testMethodReturnsTheHTTPRequestMethod()
 {
     $this->setServerVar('REQUEST_METHOD', 'POST');
     $this->assertEquals('POST', Request::method());
     $this->setPostVar(Request::spoofer, 'PUT');
     $this->assertEquals('PUT', Request::method());
 }
Example #3
0
 /**
  * The default handler for following redirects, triggered by the presence of
  * a Location header in the response.
  *
  * The client's follow property must be set TRUE and the HTTP response status
  * one of 201, 301, 302, 303 or 307 for the redirect to be followed.
  *
  * @param Request        $request
  * @param Response       $response
  * @param Request_Client $client
  */
 public static function on_header_location(Request $request, Response $response, Request_Client $client)
 {
     // Do we need to follow a Location header ?
     if ($client->follow() and in_array($response->status(), [201, 301, 302, 303, 307])) {
         // Figure out which method to use for the follow request
         switch ($response->status()) {
             default:
             case 301:
             case 307:
                 $follow_method = $request->method();
                 break;
             case 201:
             case 303:
                 $follow_method = Request::GET;
                 break;
             case 302:
                 // Cater for sites with broken HTTP redirect implementations
                 if ($client->strict_redirect()) {
                     $follow_method = $request->method();
                 } else {
                     $follow_method = Request::GET;
                 }
                 break;
         }
         // Prepare the additional request, copying any follow_headers that were present on the original request
         $orig_headers = $request->headers()->getArrayCopy();
         $follow_headers = array_intersect_assoc($orig_headers, array_fill_keys($client->follow_headers(), true));
         $follow_request = Request::factory($response->headers('Location'))->method($follow_method)->headers($follow_headers);
         if ($follow_method !== Request::GET) {
             $follow_request->body($request->body());
         }
         return $follow_request;
     }
     return null;
 }
Example #4
0
 /**
  * Generates a signature for a packet request response
  *
  * @param array                  $packet
  * @param int|null               $code
  * @param string|\Exception|null $message
  *
  * @return array
  *
  */
 protected static function signPacket(array $packet, $code = null, $message = null)
 {
     $_ex = false;
     if ($code instanceof \Exception) {
         $_ex = $code;
         $code = null;
     } elseif ($message instanceof \Exception) {
         $_ex = $message;
         $message = null;
     }
     !$code && ($code = Response::HTTP_OK);
     $code = $code ?: ($_ex ? $_ex->getCode() : Response::HTTP_OK);
     $message = $message ?: ($_ex ? $_ex->getMessage() : null);
     $_startTime = \Request::server('REQUEST_TIME_FLOAT', \Request::server('REQUEST_TIME', $_timestamp = microtime(true)));
     $_elapsed = $_timestamp - $_startTime;
     $_id = sha1($_startTime . \Request::server('HTTP_HOST') . \Request::server('REMOTE_ADDR'));
     //  All packets have this
     $_packet = array_merge($packet, ['error' => false, 'status_code' => $code, 'request' => ['id' => $_id, 'version' => static::PACKET_VERSION, 'signature' => base64_encode(hash_hmac(config('dfe.signature-method'), $_id, $_id, true)), 'verb' => \Request::method(), 'request-uri' => \Request::getRequestUri(), 'start' => date('c', $_startTime), 'elapsed' => (double) number_format($_elapsed, 4)]]);
     //  Update the error entry if there was an error
     if (!array_get($packet, 'success', false) && !array_get($packet, 'error', false)) {
         $_packet['error'] = ['code' => $code, 'message' => $message, 'exception' => $_ex ? Json::encode($_ex) : false];
     } else {
         array_forget($_packet, 'error');
     }
     return $_packet;
 }
 /**
  * @param \Exception $exception
  * @return \Illuminate\Http\JsonResponse
  */
 public function format($exception)
 {
     // Define the response
     $result = ['errors' => trans('messages.sorry')];
     // Default response of 400
     $statusCode = 400;
     $addDebugData = $this->isDebugEnabled();
     switch (true) {
         case $exception instanceof HttpException:
             $statusCode = $exception->getStatusCode();
             $result['errors'] = $exception->getMessage();
             break;
         case $exception instanceof ValidationException:
             $result['errors'] = $exception->errors();
             $addDebugData = false;
             break;
     }
     // Prepare response
     $response = ['success' => false, 'result' => $result, 'meta' => ['version' => config('app.version.api'), 'request' => \Request::method() . ' ' . \Request::url(), 'debug' => $this->isDebugEnabled()]];
     // If the app is in debug mode && not Validation exception
     if ($addDebugData) {
         $response['debug'] = ['exception' => get_class($exception), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace()];
     }
     // Return a JSON response with the response array and status code
     return response()->json($response, $statusCode);
 }
 public function my_schedule()
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $data["actions"] = Session::get('actions');
         if (in_array('side_mi_horario', $data["actions"])) {
             $current_ay = AcademicYear::getCurrentAcademicYear();
             if (!$current_ay) {
                 return View::make('schedule/academic_year_error', $data);
             }
             $student = $data["user"]->student;
             $data["enrollment_info"] = $student->getCurrentEnrollment();
             $data["level"] = $data["enrollment_info"]->level;
             $data["schedules_data"] = $data["level"]->schedules()->orderBy('initial_hour')->get();
             return View::make('schedule/my_schedule', $data);
         } else {
             // Llamo a la función para registrar el log de auditoria
             $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registerLog(10, $log_description);
             Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
             return Redirect::to('/dashboard');
         }
     } else {
         return View::make('error/error');
     }
 }
Example #7
0
 /**
  * @param $parameters
  */
 protected function readDbObjectForInjection($parameters)
 {
     /** @var Route $route */
     $route = \Request::route();
     $object = null;
     foreach ($parameters as $key => $value) {
         if ($value instanceof CmfDbObject) {
             // get only last object in params
             $object = $value;
         }
     }
     if (!empty($object)) {
         $id = $route->parameter('id', false);
         if ($id === false && \Request::method() !== 'GET') {
             $id = \Request::get('id', false);
         }
         if (empty($id)) {
             $this->sendRecordNotFoundResponse();
         }
         $conditions = ['id' => $id];
         $this->addConditionsForDbObjectInjection($route, $object, $conditions);
         $this->addParentIdsConditionsForDbObjectInjection($route, $object, $conditions);
         $object->find($conditions);
         if (!$object->exists()) {
             $this->sendRecordNotFoundResponse();
         }
     }
 }
 public function action_edit($id)
 {
     $post = \Blog\Models\Post::find($id);
     if ($post === null) {
         return Event::first('404');
     }
     if (Str::lower(Request::method()) == "post") {
         $validator = Validator::make(Input::all(), self::$rules);
         if ($validator->passes()) {
             $post->title = Input::get('title');
             if (Input::get('slug')) {
                 $post->slug = Str::slug(Input::get('slug'));
             } else {
                 $post->slug = Str::slug(Input::get('title'));
             }
             $post->intro = Input::get('intro');
             $post->content = Input::get('content');
             $post->author_id = Input::get('author_id');
             $post->category_id = Input::get('category_id');
             $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time');
             $post->save();
             return Redirect::to_action('blog::admin.post@list');
         } else {
             return Redirect::back()->with_errors($validator)->with_input();
         }
     } else {
         $categories = array();
         $originalCategories = \Blog\Models\Category::all();
         foreach ($originalCategories as $cat) {
             $categories[$cat->id] = $cat->name;
         }
         return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories);
     }
 }
Example #9
0
 public static function instance(&$uri = TRUE)
 {
     if (!Request::$instance) {
         if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
             Request::$protocol = 'https';
         }
         if (isset($_SERVER['REQUEST_METHOD'])) {
             Request::$method = $_SERVER['REQUEST_METHOD'];
         }
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
             Request::$is_ajax = TRUE;
         }
         Request::$client_ip = self::get_client_ip();
         if (Request::$method !== 'GET' and Request::$method !== 'POST') {
             parse_str(file_get_contents('php://input'), $_POST);
         }
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
         }
         if (isset($_SERVER['HTTP_REFERER'])) {
             Request::$referrer = $_SERVER['HTTP_REFERER'];
         }
         if ($uri === TRUE) {
             $uri = Request::detect_uri();
         }
         $uri = preg_replace('#//+#', '/', $uri);
         $uri = preg_replace('#\\.[\\s./]*/#', '', $uri);
         Request::$instance = new Request($uri);
     }
     return Request::$instance;
 }
Example #10
0
 public static function start($path_info)
 {
     $path_info = "/" . ltrim($path_info, "/");
     $failed = true;
     $args;
     switch (Request::method()) {
         case "GET":
             $map = self::$map_get;
             break;
         case "POST":
             $map = self::$map_post;
             break;
         default:
             $map = $map_other_methods;
     }
     foreach ($map as $re => $fn) {
         if (preg_match("/" . str_replace("/", "\\/", $re) . "/", $path_info, $args)) {
             array_shift($args);
             $args = array_map(function ($arg) {
                 return urldecode($arg);
             }, $args);
             try {
                 call_user_func_array($fn, $args);
                 $failed = false;
                 break;
             } catch (NextRoute $e) {
             }
         }
     }
     if ($failed) {
         not_found();
     }
 }
Example #11
0
 /**
  * @param Request $request
  * @return RouteResult
  */
 public function validate(Request $request)
 {
     $parameters = [];
     $matched = $this->method === $request->method();
     $matched = $matched && preg_match($this->path, $request->path(), $parameters);
     return new RouteResult($matched, $parameters, $this->response_factory);
 }
Example #12
0
 /**
  * Converting the site URL to fit to the HTTP request
  *
  * @return  void
  */
 public function onAfterInitialise()
 {
     if (App::isAdmin() || Config::get('debug')) {
         return;
     }
     if (Notify::any()) {
         return;
     }
     if (User::isGuest() && Request::method() == 'GET') {
         $id = $this->getId();
         if ($data = App::get('cache')->get($id)) {
             App::get('response')->setContent($data);
             App::get('response')->compress(App::get('config')->get('gzip', false));
             if ($this->params->get('browsercache', false)) {
                 App::get('response')->headers->set('HTTP/1.x 304 Not Modified', true);
             }
             App::get('response')->headers->set('ETag', $id);
             App::get('response')->send();
             if ($profiler = App::get('profiler')) {
                 $profiler->mark('afterCache');
                 echo implode('', $profiler->marks());
             }
             App::close();
         }
     }
 }
Example #13
0
 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   request to send
  * @return  Response
  * @uses    [PHP cURL](http://php.net/manual/en/book.curl.php)
  */
 public function _send_message(Request $request)
 {
     // Calculate stream mode
     $mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+';
     // Process cookies
     if ($cookies = $request->cookie()) {
         $request->headers('cookie', http_build_query($cookies, NULL, '; '));
     }
     // Get the message body
     $body = $request->body();
     if (is_resource($body)) {
         $body = stream_get_contents($body);
     }
     // Set the content length
     $request->headers('content-length', (string) strlen($body));
     list($protocol) = explode('/', $request->protocol());
     // Create the context
     $options = array(strtolower($protocol) => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $body));
     // Create the context stream
     $context = stream_context_create($options);
     stream_context_set_option($context, $this->_options);
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     $stream = fopen($uri, $mode, FALSE, $context);
     $meta_data = stream_get_meta_data($stream);
     // Get the HTTP response code
     $http_response = array_shift($meta_data['wrapper_data']);
     if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) {
         $protocol = $matches[1][0];
         $status = (int) $matches[2][0];
     } else {
         $protocol = NULL;
         $status = NULL;
     }
     // Create a response
     $response = $request->create_response();
     $response_header = $response->headers();
     // Process headers
     array_map(array($response_header, 'parse_header_string'), array(), $meta_data['wrapper_data']);
     $response->status($status)->protocol($protocol)->body(stream_get_contents($stream));
     // Close the stream after use
     fclose($stream);
     return $response;
 }
Example #14
0
 /**
  * Constructor
  *
  * @param Request  $request
  * @param Response $response
  */
 public function __construct(Request $request, Response $response)
 {
     // Ajax-like request setting if HMVC call or POST request with param `is_ajax` == `true`
     if ($request->is_ajax() or $request !== Request::initial() or $request->method() === HTTP_Request::POST and $request->post('is_ajax') === 'true') {
         $request->requested_with('xmlhttprequest');
     }
     parent::__construct($request, $response);
 }
Example #15
0
 /**
  * @dataProvider data_is_method_allowed
  */
 public function test_is_method_allowed($route_method, $requested_method, $expected_result)
 {
     $this->markTestSkipped();
     $route = Route::set('route_check', 'uri', NULL, array('method' => $route_method))->defaults(array('controller' => 'uri'));
     $request = new Request('uri');
     $request->method($requested_method);
     $this->assertEquals($expected_result, $route->is_method_allowed($route, array(), $request));
 }
Example #16
0
 public static function before_validation()
 {
     // change rules when updating
     if (Request::method() == 'PUT') {
         // unique: ignore values on record with id
         $id = self::get('current_id');
         self::$rules['name'] .= ",name,{$id}";
     }
 }
Example #17
0
 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   request to send
  * @return  Response
  */
 public function _send_message(Request $request)
 {
     // Response headers
     $response_headers = array();
     // Set the request method
     $options[CURLOPT_CUSTOMREQUEST] = $request->method();
     // Set the request body. This is perfectly legal in CURL even
     // if using a request other than POST. PUT does support this method
     // and DOES NOT require writing data to disk before putting it, if
     // reading the PHP docs you may have got that impression. SdF
     $options[CURLOPT_POSTFIELDS] = $request->body();
     // Process headers
     if ($headers = $request->headers()) {
         $http_headers = array();
         foreach ($headers as $key => $value) {
             $http_headers[] = $key . ': ' . $value;
         }
         $options[CURLOPT_HTTPHEADER] = $http_headers;
     }
     // Process cookies
     if ($cookies = $request->cookie()) {
         $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; ');
     }
     // Create response
     $response = $request->create_response();
     $response_header = $response->headers();
     // Implement the standard parsing parameters
     $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string');
     $this->_options[CURLOPT_RETURNTRANSFER] = TRUE;
     $this->_options[CURLOPT_HEADER] = FALSE;
     // Apply any additional options set to
     $options += $this->_options;
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     // Open a new remote connection
     $curl = curl_init($uri);
     // Set connection options
     if (!curl_setopt_array($curl, $options)) {
         throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response body
     $body = curl_exec($curl);
     // Get the response information
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($body === FALSE) {
         $error = curl_error($curl);
     }
     // Close the connection
     curl_close($curl);
     if (isset($error)) {
         throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error));
     }
     $response->status($code)->body($body);
     return $response;
 }
 public function parametros()
 {
     $maestra = json_decode(File::get(app_path("config/maestra.php")), true);
     if (Request::method() == "POST") {
         $maestra["is_fondo"] = Input::get('is_fondo', false);
         $maestra["fondo_%"] = Input::get('fondo_%', 14);
     }
     File::put(app_path("config/maestra.php"), json_encode($maestra));
     return View::make('admin/parametros')->withMaestra($maestra);
 }
Example #19
0
 public function matches(Request $request, $include_http_method = true, &$matches = null)
 {
     $path = str_replace($request->baseUri(), '', $request->uriPath());
     $method = $request->method();
     if ($include_http_method) {
         preg_match($this->compiled_path, $method . '#' . $path, $matches);
     } else {
         preg_match($this->compiled_path_without_http_method, $path, $matches);
     }
     return count($matches) > 0;
 }
Example #20
0
 public function __construct()
 {
     //Run if request is 'POST' or 'PUT'
     $verb = Request::method();
     if ($verb === 'POST' || $verb === 'PUT') {
         $fields = Config::get('litmus::config.form.palette');
         foreach ($fields as $field) {
             $this->rules[$field['name']] = $field['rule'];
         }
     }
 }
Example #21
0
 public function testQueriesServerForInfo()
 {
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['HTTP_HOST'] = 'derp.com';
     $_SERVER['REQUEST_URI'] = '/';
     $_SERVER['HTTP_REFERER'] = 'http://google.com/';
     $this->assertEquals('POST', Request::method());
     $this->assertEquals('derp.com', Request::host());
     $this->assertEquals('/', Request::path());
     $this->assertEquals('http://google.com/', Request::referer());
 }
Example #22
0
 /**
  * Calculate the signature of a request.
  * Should be called just before the request is sent.
  *
  * @param Request $request
  * @param $private_key
  * @return string Calculated HMAC
  */
 public static function calculate_hmac(Request $request, $private_key)
 {
     // Consolidate data that's not in the main route (params)
     $query = array_change_key_case($request->query());
     $post = array_change_key_case($request->post());
     // Sort alphabetically
     ksort($query);
     ksort($post);
     $data_to_sign = ['method' => $request->method(), 'uri' => $request->uri(), 'post' => $post, 'query' => $query];
     // Calculate the signature
     return hash_hmac('sha256', json_encode($data_to_sign), $private_key);
 }
Example #23
0
 /**
  * This will publish the story to the database
  */
 public function publishStory()
 {
     $oRequestInstance = \Request::instance();
     $oRouteInstance = \Route::current();
     // get the extra custom data supplied by the user
     $aCustomData = $this->getCustomSuppliedData();
     $uri = head($oRouteInstance->methods()) . ' ' . $oRouteInstance->uri();
     $aData = ['ip_address' => \Input::getClientIp(), 'domain' => \Request::root(), 'path' => \Request::path(), 'request_method' => $oRequestInstance->getMethod(), 'query_string' => $oRequestInstance->getQueryString(), 'post_string' => \Request::method() == "POST" ? json_encode(\Input::all()) : NULL, 'is_ajax' => \Request::ajax(), 'is_secure' => \Request::secure(), 'route_uri' => $uri ?: '-', 'route_name' => $oRouteInstance->getName() ?: '-', 'route_action' => $oRouteInstance->getActionName() ?: '-', 'class_method' => \Request::method()];
     // merge the custom data to the already built data
     $aData = array_merge($aData, $aCustomData);
     // save the collected data
     $this->getSessionManager()->saveCollectedData($aData);
 }
Example #24
0
 /**
  * Get object of Response.
  *
  * @param string $packageRoot
  * @param Request $request
  *
  * @return Response|null
  */
 public function getResponse($packageRoot, Request $request)
 {
     $packageRoot = rtrim($packageRoot, '/');
     $path = $packageRoot . '/Route/' . $request->route() . '/' . $request->method() . '.php';
     if (file_exists($path)) {
         require $path;
         $controllerClass = $request->package() . '\\Route_' . str_replace('/', '_', $request->route()) . '\\' . $request->method();
         /**
          * @var BaseController $controller
          */
         $controller = new $controllerClass($packageRoot, $request);
         /**
          * Call handler.
          */
         $handler = $_POST['handler'] ?? $_GET['handler'] ?? 'index';
         if (preg_match('/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $handler) && method_exists($controllerClass, $handler)) {
             $controller->{$handler}();
             return $controller->getResponse();
         }
     }
     return null;
 }
Example #25
0
 public static function init()
 {
     if (ini_get('magic_quotes_gpc')) {
         self::$get = $_GET;
         self::$post = $_POST;
     } else {
         self::$get = $_GET = self::addSlashes($_GET);
         self::$post = $_POST = self::addSlashes($_POST);
     }
     self::$cookie = $_COOKIE;
     self::$file = $_FILES;
     self::$method = $_SERVER['REQUEST_METHOD'];
 }
Example #26
0
 /**
  * Main request singleton instance. If no URI is provided, the URI will
  * be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF.
  *
  *     $request = Request::instance();
  *
  * @param   string   URI of the request
  * @return  Request
  */
 public static function instance($uri = TRUE)
 {
     if (!Request::$instance) {
         if (isset($_SERVER['REQUEST_METHOD'])) {
             // Use the server request method
             Request::$method = $_SERVER['REQUEST_METHOD'];
         }
         if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
             // This request is secure
             Request::$protocol = 'https';
         }
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
             // This request is an AJAX request
             Request::$is_ajax = TRUE;
         }
         if (isset($_SERVER['HTTP_REFERER'])) {
             // There is a referrer for this request
             Request::$referrer = $_SERVER['HTTP_REFERER'];
         }
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             // Set the client user agent
             Request::$user_agent = $_SERVER['HTTP_USER_AGENT'];
         }
         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
             // Use the forwarded IP address, typically set when the
             // client is using a proxy server.
             Request::$client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
             // Use the forwarded IP address, typically set when the
             // client is using a proxy server.
             Request::$client_ip = $_SERVER['HTTP_CLIENT_IP'];
         } elseif (isset($_SERVER['REMOTE_ADDR'])) {
             // The remote IP address
             Request::$client_ip = $_SERVER['REMOTE_ADDR'];
         }
         if (Request::$method !== 'GET' and Request::$method !== 'POST') {
             // Methods besides GET and POST do not properly parse the form-encoded
             // query string into the $_POST array, so we overload it manually.
             parse_str(file_get_contents('php://input'), $_POST);
         }
         if ($uri === TRUE) {
             // If the route wasn't passed, just generate the route from $_POST or $_GET values
             $uri = array_merge(JRequest::get('get'), JRequest::get('post'));
         }
         // Set the default request client
         $client = JFactory::getApplication()->isAdmin() ? 'admin' : 'site';
         // Create the instance singleton
         Request::$instance = Request::$current = new Request($uri, $client);
     }
     return Request::$instance;
 }
Example #27
0
 public function __call($method, $arguments)
 {
     $request = array_pop($arguments);
     // add support to sending requests to url's only
     if (!is_array($request)) {
         $request = ['url' => $request];
     }
     if ($this->valid($request)) {
         $request['method'] = Request::method($method);
         $this->request = $this->requestInstance($request);
         return $this->request->send();
     }
     throw new \Exception('Invalid Request Params sent to HttpClient');
 }
Example #28
0
 /**
  * This method checks to see if a view exists and if it does loads it along with any
  * associated data from the database. It then checks to see if a function exists for
  * the passed in page name (substituting dashes for underscores and runs that) if it exists.
  * @param  string  $page            The page name
  * @param  string  $variable        Allows us to pass a second variable to things
  * @return view                     Ideally a view of some kind
  */
 public function get_index($page = 'home', $variable = false)
 {
     $this->data['page'] = Page::where('slug', '=', $page)->first();
     $function = strtolower(Request::method() . '_' . str_replace('-', '_', $page));
     if (method_exists($this, $function)) {
         $this->{$function}($variable);
     } else {
         if (View::exists('site.' . $page)) {
             return View::make('site.' . $page, $this->data);
         } else {
             return Response::error('404');
         }
     }
 }
Example #29
0
 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     # URL: /cliqr/poll/:range_id
     $range_id = self::ensureMD5($action);
     # check activation of this plugin in range_id
     if (!$this->plugin->isActivated($range_id)) {
         throw new Trails_Exception(404);
     }
     # transform params
     # $action -> show/update, $args -> [range_id]
     $action = Request::method() === 'POST' && !Request::submitted('login_ticket') ? 'update' : 'show';
     $args = array($range_id);
 }
Example #30
0
 public function __construct()
 {
     $this->_redirectSlashes();
     // make an array from stuff between slashes from request path
     $this->path = explode('/', $_SERVER['REQUEST_URI']);
     self::$method = strtolower($_SERVER['REQUEST_METHOD']);
     self::$view = $this->_getView();
     self::$get = $this->_getParameters();
     if (self::$method === "post") {
         foreach ($_POST as $post => $value) {
             self::$get[] = $value;
         }
     }
     new Response();
 }