Overview

Packages

  • tipy

Classes

  • Tipy
  • TipyApp
  • TipyCli
  • TipyCliSession
  • TipyConfig
  • TipyController
  • TipyCookie
  • TipyDAO
  • TipyEnv
  • TipyFlash
  • TipyInflector
  • TipyInput
  • TipyIOWrapper
  • TipyLogger
  • TipyMailer
  • TipyModel
  • TipyOutput
  • TipyRequest
  • TipySession
  • TipyTestCase
  • TipyTestRunner
  • TipyView

Exceptions

  • AssertionFailedException
  • CompileErrorException
  • CompileWarningException
  • CoreErrorException
  • CoreWarningException
  • DeprecatedException
  • NoMethodException
  • NoticeException
  • ParseException
  • RecoverableErrorException
  • StrictException
  • TipyDaoException
  • TipyException
  • TipyModelException
  • TipyRollbackException
  • TipyValidationException
  • UserDeprecatedException
  • UserErrorException
  • UserNoticeException
  • UserWarningException
  • WarningException
  • Overview
  • Package
  • Class
  • Deprecated
  • Todo
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 
<?php
/**
 * TipyRequest
 *
 * @package tipy
 */

/**
 * Access request and its header
 *
 * By default it is a TipyIOWrapper around $_SERVER superglobal
 *
 * <code>
 * class MyController extends TipyController {
 *     public function index() {
 *         $requestIsPost = $this->request->isPost();
 *         $userAgent = $this->request->get('HTTP_USER_AGENT');
 *         // ...
 *     }
 * }
 * </code>
 *
 * @see TipyIOWrapper
 */
class TipyRequest extends TipyIOWrapper {

    /**
     * Construct TipyRequest instance from $_SERVER
     */
    public function __construct() {
        parent::__construct();
        // little hack to autocreate $_SERVER if
        // auto_globals_jit is on
        $foo = $_SERVER['PHP_SELF'];
        $this->bind($_SERVER);
    }

    /**
     * Request URI
     * @return string
     */
    public function uri() {
        return $this->get('REQUEST_URI');
    }

    /**
     * Return request method: GET,POST,DELETE,etc...
     * @return string
     */
    public function method() {
        return $this->get('REQUEST_METHOD');
    }

    /**
     * Return true if request is a GET request
     * @return boolean
     */
    public function isGet() {
        return $this->method == 'GET';
    }

    /**
     * Return true if request is a POST request
     * @return boolean
     */
    public function isPost() {
        return $this->method == 'POST';
    }

    /**
     * Returns true if request is AJAX request
     * @return boolean
     */
    public function isXhr() {
        return $this->get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
    }

    /**
     * Return true if request is a PUT request
     * @return boolean
     */
    public function isPut() {
        return $this->method == 'PUT';
    }

    /**
     * Return true if request is a DELETE request
     * @return boolean
     */
    public function isDelete() {
        return $this->method == 'DELETE';
    }

    /**
     * Return true if request is a OPTIONS request
     * @return boolean
     */
    public function isOptions() {
        return $this->method == 'OPTIONS';
    }

    /**
     * Return true if request is a HEAD request
     * @return boolean
     */
    public function isHead() {
        return $this->method == 'HEAD';
    }

    /**
    * Returns the IP address of the client.
    *
    * @param bool $trust_proxy_headers Whether or not to trust the
    * proxy headers HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR.
    * ONLY use if your server is behind a proxy that sets these values
    * @return string
    */
    public function ip($trust_proxy_headers = false) {
        if (!$trust_proxy_headers) {
            return $_SERVER['REMOTE_ADDR'];
        }
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }
}
tipy API documentation generated by ApiGen