Вход Регистрация
Файл: concrete5.7.5.6/concrete/src/Http/RequestBase.php
Строк: 165
<?php

namespace ConcreteCoreHttp;

use 
Core;
use 
SymfonyComponentHttpFoundationRequest as SymfonyRequest;

/**
 * @package    Core
 * @category   Concrete
 * @author     Andrew Embler <andrew@concrete5.org>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */

/**
 * An object that represents a particular request to the Concrete-powered website. The request object then determines what is being requested, based on the path, and presents itself to the rest of the dispatcher (which loads the page, etc...).
 *
 * @package    Core
 * @author     Andrew Embler <andrew@concrete5.org>
 * @category   Concrete
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */
class RequestBase extends SymfonyRequest
{
    
/**
     * @var bool
     */
    
protected $hasCustomRequestUser;

    
/**
     * @var ConcreteCoreUserUserInfo
     */
    
protected $customRequestUser;

    
/**
     * @var string
     */
    
protected $customRequestDateTime;

    
/**
     * @var SymfonyRequest
     */
    
protected static $instance;

    
/**
     * @var ConcreteCorePagePage
     */
    
protected $c;

    
/**
     * @return static
     */
    
public static function getInstance()
    {
        if (
self::$instance === null) {
            
self::$instance = static::createFromGlobals();
        }

        return 
self::$instance;
    }

    
/**
     * @param SymfonyRequest $instance
     */
    
public static function setInstance(SymfonyRequest $instance)
    {
        
self::$instance $instance;
    }

    
/**
     * @return ConcreteCorePagePage
     */
    
public function getCurrentPage()
    {
        return 
$this->c;
    }

    
/**
     * @param ConcreteCorePagePage $c
     */
    
public function setCurrentPage(ConcreteCorePagePage $c)
    {
        
$this->$c;
    }

    public function 
clearCurrentPage()
    {
        
$this->null;
    }

    
/**
     * @return ConcreteCoreUserUserInfo
     */
    
public function getCustomRequestUser()
    {
        return 
$this->customRequestUser;
    }

    
/**
     * @param ConcreteCoreUserUserInfo $ui
     */
    
public function setCustomRequestUser($ui)
    {
        
$this->hasCustomRequestUser true;
        
$this->customRequestUser $ui;
    }

    
/**
     * @return bool
     */
    
public function hasCustomRequestUser()
    {
        return 
$this->hasCustomRequestUser;
    }

    
/**
     * @return string
     */
    
public function getCustomRequestDateTime()
    {
        return 
$this->customRequestDateTime;
    }

    
/**
     * @param string $date
     */
    
public function setCustomRequestDateTime($date)
    {
        
$this->customRequestDateTime $date;
    }

    
/**
     * Determines whether a request matches a particular pattern.
     *
     * @param string $pattern
     *
     * @return bool
     */
    
public function matches($pattern)
    {
        return 
Core::make('helper/text')->match($pattern$this->getPath());
    }

    
/**
     * Returns the full path for a request.
     *
     * @return string
     */
    
public function getPath()
    {
        
$pathInfo rawurldecode($this->getPathInfo());
        
$path '/' trim($pathInfo'/');

        return (
$path == '/') ? '' $path;
    }

    
/**
     * If no arguments are passed, returns the post array. If a key is passed, it returns the value as it exists in the post array.
     * If a default value is provided and the key does not exist in the POST array, the default value is returned.
     *
     * @param string $key
     * @param mixed $defaultValue
     *
     * @return mixed
     */
    
public static function post($key null$defaultValue null)
    {
        if (
$key == null) {
            return 
$_POST;
        }
        if (isset(
$_POST[$key])) {
            return (
is_string($_POST[$key])) ? trim($_POST[$key]) : $_POST[$key];
        }

        return 
$defaultValue;
    }

    
/**
     * @param string $key
     * @param mixed $defaultValue
     *
     * @return mixed
     */
    
public static function request($key null$defaultValue null)
    {
        if (
$key == null) {
            return 
$_REQUEST;
        }
        
$req self::createFromGlobals();
        if (
$req->query->has($key)) {
            return 
$req->query->get($key);
        } else {
            if (
$req->request->has($key)) {
                return 
$req->request->get($key);
            }
        }

        return 
$defaultValue;
    }

    
/**
     * @return bool
     */
    
public static function isPost()
    {
        return isset(
$_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST';
    }
}
Онлайн: 4
Реклама