initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004-2006 Sean Kerr.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package symfony
* @subpackage request
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Sean Kerr <skerr@mojavi.org>
* @version SVN: $Id: sfConsoleRequest.class.php 3606 2007-03-13 19:01:45Z fabien $
*/
class sfConsoleRequest extends sfRequest
{
/**
* Initializes this sfRequest.
*
* @param sfContext A sfContext instance
* @param array An associative array of initialization parameters
* @param array An associative array of initialization attributes
*
* @return boolean true, if initialization completes successfully, otherwise false
*
* @throws <b>sfInitializationException</b> If an error occurs while initializing this Request
*/
public function initialize($context, $parameters = array(), $attributes = array())
{
parent::initialize($context, $parameters, $attributes);
$this->getParameterHolder()->add($_SERVER['argv']);
}
/**
* Executes the shutdown procedure.
*
*/
public function shutdown()
{
}
}

View File

@ -0,0 +1,442 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004-2006 Sean Kerr.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfRequest provides methods for manipulating client request information such
* as attributes, errors and parameters. It is also possible to manipulate the
* request method originally sent by the user.
*
* @package symfony
* @subpackage request
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Sean Kerr <skerr@mojavi.org>
* @version SVN: $Id: sfRequest.class.php 4266 2007-06-19 12:44:54Z fabien $
*/
abstract class sfRequest
{
/**
* Process validation and execution for only GET requests.
*
*/
const GET = 2;
/**
* Skip validation and execution for any request method.
*
*/
const NONE = 1;
/**
* Process validation and execution for only POST requests.
*
*/
const POST = 4;
/**
* Process validation and execution for only PUT requests.
*
*/
const PUT = 5;
/**
* Process validation and execution for only DELETE requests.
*
*/
const DELETE = 6;
/**
* Process validation and execution for only HEAD requests.
*
*/
const HEAD = 7;
protected
$errors = array(),
$context = null,
$method = null,
$parameterHolder = null,
$config = null,
$attributeHolder = null;
/**
* Extracts parameter values from the request.
*
* @param array An indexed array of parameter names to extract
*
* @return array An associative array of parameters and their values. If
* a specified parameter doesn't exist an empty string will
* be returned for its value
*/
public function & extractParameters($names)
{
$array = array();
$parameters =& $this->parameterHolder->getAll();
foreach ($parameters as $key => &$value)
{
if (in_array($key, $names))
{
$array[$key] =& $value;
}
}
return $array;
}
/**
* Retrieves an error message.
*
* @param string An error name
*
* @return string An error message, if the error exists, otherwise null
*/
public function getError($name, $catalogue = 'messages')
{
$retval = null;
if (isset($this->errors[$name]))
{
$retval = $this->errors[$name];
// translate error message if needed
if (sfConfig::get('sf_i18n'))
{
$retval = $this->context->getI18N()->__($retval, null, $catalogue);
}
}
return $retval;
}
/**
* Retrieves an array of error names.
*
* @return array An indexed array of error names
*/
public function getErrorNames()
{
return array_keys($this->errors);
}
/**
* Retrieves an array of errors.
*
* @return array An associative array of errors
*/
public function getErrors()
{
return $this->errors;
}
/**
* Retrieves this request's method.
*
* @return int One of the following constants:
* - sfRequest::GET
* - sfRequest::POST
*/
public function getMethod()
{
return $this->method;
}
/**
* Indicates whether or not an error exists.
*
* @param string An error name
*
* @return boolean true, if the error exists, otherwise false
*/
public function hasError($name)
{
return array_key_exists($name, $this->errors);
}
/**
* Indicates whether or not any errors exist.
*
* @return boolean true, if any error exist, otherwise false
*/
public function hasErrors()
{
return (count($this->errors) > 0);
}
/**
* Initializes this sfRequest.
*
* @param sfContext A sfContext instance
* @param array An associative array of initialization parameters
* @param array An associative array of initialization attributes
*
* @return boolean true, if initialization completes successfully, otherwise false
*
* @throws <b>sfInitializationException</b> If an error occurs while initializing this Request
*/
public function initialize($context, $parameters = array(), $attributes = array())
{
$this->context = $context;
// initialize parameter and attribute holders
$this->parameterHolder = new sfParameterHolder();
$this->attributeHolder = new sfParameterHolder();
$this->parameterHolder->add($parameters);
$this->attributeHolder->add($attributes);
}
/**
* Retrieves the current application context.
*
* @return sfContext Current application context
*/
public function getContext()
{
return $this->context;
}
/**
* Retrieves a new sfRequest implementation instance.
*
* @param string A sfRequest implementation name
*
* @return sfRequest A sfRequest implementation instance
*
* @throws <b>sfFactoryException</b> If a request implementation instance cannot be created
*/
public static function newInstance($class)
{
// the class exists
$object = new $class();
if (!($object instanceof sfRequest))
{
// the class name is of the wrong type
$error = 'Class "%s" is not of the type sfRequest';
$error = sprintf($error, $class);
throw new sfFactoryException($error);
}
return $object;
}
/**
* Removes an error.
*
* @param string An error name
*
* @return string An error message, if the error was removed, otherwise null
*/
public function & removeError($name)
{
$retval = null;
if (isset($this->errors[$name]))
{
$retval =& $this->errors[$name];
unset($this->errors[$name]);
}
return $retval;
}
/**
* Sets an error.
*
* @param string An error name
* @param string An error message
*
*/
public function setError($name, $message)
{
if (sfConfig::get('sf_logging_enabled'))
{
$this->getContext()->getLogger()->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")');
}
$this->errors[$name] = $message;
}
/**
* Sets an array of errors
*
* If an existing error name matches any of the keys in the supplied
* array, the associated message will be overridden.
*
* @param array An associative array of errors and their associated messages
*
*/
public function setErrors($errors)
{
$this->errors = array_merge($this->errors, $errors);
}
/**
* Sets the request method.
*
* @param int One of the following constants:
*
* - sfRequest::GET
* - sfRequest::POST
* - sfRequest::PUT
* - sfRequest::DELETE
* - sfRequest::HEAD
*
* @return void
*
* @throws <b>sfException</b> - If the specified request method is invalid
*/
public function setMethod($methodCode)
{
$available_methods = array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD, self::NONE);
if (in_array($methodCode, $available_methods))
{
$this->method = $methodCode;
return;
}
// invalid method type
$error = 'Invalid request method: %s';
$error = sprintf($error, $methodCode);
throw new sfException($error);
}
/**
* Retrieves the parameters for the current request.
*
* @return sfParameterHolder The parameter holder
*/
public function getParameterHolder()
{
return $this->parameterHolder;
}
/**
* Retrieves the attributes holder.
*
* @return sfParameterHolder The attribute holder
*/
public function getAttributeHolder()
{
return $this->attributeHolder;
}
/**
* Retrieves an attribute from the current request.
*
* @param string Attribute name
* @param string Default attribute value
* @param string Namespace for the current request
*
* @return mixed An attribute value
*/
public function getAttribute($name, $default = null, $ns = null)
{
return $this->attributeHolder->get($name, $default, $ns);
}
/**
* Indicates whether or not an attribute exist for the current request.
*
* @param string Attribute name
* @param string Namespace for the current request
*
* @return boolean true, if the attribute exists otherwise false
*/
public function hasAttribute($name, $ns = null)
{
return $this->attributeHolder->has($name, $ns);
}
/**
* Sets an attribute for the request.
*
* @param string Attribute name
* @param string Value for the attribute
* @param string Namespace for the current request
*
*/
public function setAttribute($name, $value, $ns = null)
{
$this->attributeHolder->set($name, $value, $ns);
}
/**
* Retrieves a paramater for the current request.
*
* @param string Parameter name
* @param string Parameter default value
* @param string Namespace for the current request
*
*/
public function getParameter($name, $default = null, $ns = null)
{
return $this->parameterHolder->get($name, $default, $ns);
}
/**
* Indicates whether or not a parameter exist for the current request.
*
* @param string Parameter name
* @param string Namespace for the current request
*
* @return boolean true, if the paramater exists otherwise false
*/
public function hasParameter($name, $ns = null)
{
return $this->parameterHolder->has($name, $ns);
}
/**
* Sets a parameter for the current request.
*
* @param string Parameter name
* @param string Parameter value
* @param string Namespace for the current request
*
*/
public function setParameter($name, $value, $ns = null)
{
$this->parameterHolder->set($name, $value, $ns);
}
/**
* Executes the shutdown procedure.
*
*/
abstract function shutdown();
/**
* Overloads a given method.
*
* @param string Method name
* @param string Method arguments
*
* @return mixed User function callback
*
* @throws <b>sfException</b> if call fails
*/
public function __call($method, $arguments)
{
if (!$callable = sfMixer::getCallable('sfRequest:'.$method))
{
throw new sfException(sprintf('Call to undefined method sfRequest::%s', $method));
}
array_unshift($arguments, $this);
return call_user_func_array($callable, $arguments);
}
}

View File

@ -0,0 +1,865 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004-2006 Sean Kerr.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfWebRequest class.
*
* This class manages web requests. It parses input from the request and store them as parameters.
* sfWebRequest is able to parse request with routing support enabled.
*
* @package symfony
* @subpackage request
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Sean Kerr <skerr@mojavi.org>
* @version SVN: $Id: sfWebRequest.class.php 4642 2007-07-17 11:32:43Z fabien $
*/
class sfWebRequest extends sfRequest
{
/**
* A list of languages accepted by the browser.
* @var array
*/
protected $languages = null;
/**
* A list of charsets accepted by the browser
* @var array
*/
protected $charsets = null;
/**
* @var array List of content types accepted by the client.
*/
protected $acceptableContentTypes = null;
protected $pathInfoArray = null;
protected $relativeUrlRoot = null;
/**
* Retrieves an array of file information.
*
* @param string A file name
*
* @return array An associative array of file information, if the file exists, otherwise null
*/
public function getFile($name)
{
return ($this->hasFile($name) ? $this->getFileValues($name) : null);
}
/**
* Retrieves a file error.
*
* @param string A file name
*
* @return int One of the following error codes:
*
* - <b>UPLOAD_ERR_OK</b> (no error)
* - <b>UPLOAD_ERR_INI_SIZE</b> (the uploaded file exceeds the
* upload_max_filesize directive
* in php.ini)
* - <b>UPLOAD_ERR_FORM_SIZE</b> (the uploaded file exceeds the
* MAX_FILE_SIZE directive that
* was specified in the HTML form)
* - <b>UPLOAD_ERR_PARTIAL</b> (the uploaded file was only
* partially uploaded)
* - <b>UPLOAD_ERR_NO_FILE</b> (no file was uploaded)
*/
public function getFileError($name)
{
return ($this->hasFile($name) ? $this->getFileValue($name, 'error') : UPLOAD_ERR_NO_FILE);
}
/**
* Retrieves a file name.
*
* @param string A file nam.
*
* @return string A file name, if the file exists, otherwise null
*/
public function getFileName($name)
{
return ($this->hasFile($name) ? $this->getFileValue($name, 'name') : null);
}
/**
* Retrieves an array of file names.
*
* @return array An indexed array of file names
*/
public function getFileNames()
{
return array_keys($_FILES);
}
/**
* Retrieves an array of files.
*
* @return array An associative array of files
*/
public function getFiles()
{
return $_FILES;
}
/**
* Retrieves a file path.
*
* @param string A file name
*
* @return string A file path, if the file exists, otherwise null
*/
public function getFilePath($name)
{
return ($this->hasFile($name) ? $this->getFileValue($name, 'tmp_name') : null);
}
/**
* Retrieve a file size.
*
* @param string A file name
*
* @return int A file size, if the file exists, otherwise null
*/
public function getFileSize($name)
{
return ($this->hasFile($name) ? $this->getFileValue($name, 'size') : null);
}
/**
* Retrieves a file type.
*
* This may not be accurate. This is the mime-type sent by the browser
* during the upload.
*
* @param string A file name
*
* @return string A file type, if the file exists, otherwise null
*/
public function getFileType($name)
{
return ($this->hasFile($name) ? $this->getFileValue($name, 'type') : null);
}
/**
* Indicates whether or not a file exists.
*
* @param string A file name
*
* @return boolean true, if the file exists, otherwise false
*/
public function hasFile($name)
{
if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))
{
return isset($_FILES[$match[1]]['name'][$match[2]]);
}
else
{
return isset($_FILES[$name]);
}
}
/**
* Indicates whether or not a file error exists.
*
* @param string A file name
*
* @return boolean true, if the file error exists, otherwise false
*/
public function hasFileError($name)
{
return ($this->hasFile($name) ? ($this->getFileValue($name, 'error') != UPLOAD_ERR_OK) : false);
}
/**
* Indicates whether or not any file errors occured.
*
* @return boolean true, if any file errors occured, otherwise false
*/
public function hasFileErrors()
{
foreach ($this->getFileNames() as $name)
{
if ($this->hasFileError($name) === true)
{
return true;
}
}
return false;
}
/**
* Indicates whether or not any files exist.
*
* @return boolean true, if any files exist, otherwise false
*/
public function hasFiles()
{
return (count($_FILES) > 0);
}
/**
* Retrieves a file value.
*
* @param string A file name
* @param string Value to search in the file
*
* @return string File value
*/
public function getFileValue($name, $key)
{
if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))
{
return $_FILES[$match[1]][$key][$match[2]];
}
else
{
return $_FILES[$name][$key];
}
}
/**
* Retrieves all the values from a file.
*
* @param string A file name
*
* @return array Associative list of the file values
*/
public function getFileValues($name)
{
if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))
{
return array(
'name' => $_FILES[$match[1]]['name'][$match[2]],
'type' => $_FILES[$match[1]]['type'][$match[2]],
'tmp_name' => $_FILES[$match[1]]['tmp_name'][$match[2]],
'error' => $_FILES[$match[1]]['error'][$match[2]],
'size' => $_FILES[$match[1]]['size'][$match[2]],
);
}
else
{
return $_FILES[$name];
}
}
/**
* Retrieves an extension for a given file.
*
* @param string A file name
*
* @return string Extension for the file
*/
public function getFileExtension($name)
{
$fileType = $this->getFileType($name);
if (!$fileType)
{
return '.bin';
}
$mimeTypes = unserialize(file_get_contents(sfConfig::get('sf_symfony_data_dir').'/data/mime_types.dat'));
return isset($mimeTypes[$fileType]) ? '.'.$mimeTypes[$fileType] : '.bin';
}
/**
* Initializes this sfRequest.
*
* @param sfContext A sfContext instance
* @param array An associative array of initialization parameters
* @param array An associative array of initialization attributes
*
* @return boolean true, if initialization completes successfully, otherwise false
*
* @throws <b>sfInitializationException</b> If an error occurs while initializing this Request
*/
public function initialize($context, $parameters = array(), $attributes = array())
{
parent::initialize($context, $parameters, $attributes);
if (isset($_SERVER['REQUEST_METHOD']))
{
switch ($_SERVER['REQUEST_METHOD'])
{
case 'GET':
$this->setMethod(self::GET);
break;
case 'POST':
$this->setMethod(self::POST);
break;
case 'PUT':
$this->setMethod(self::PUT);
break;
case 'DELETE':
$this->setMethod(self::DELETE);
break;
case 'HEAD':
$this->setMethod(self::HEAD);
break;
default:
$this->setMethod(self::GET);
}
}
else
{
// set the default method
$this->setMethod(self::GET);
}
// load parameters from GET/PATH_INFO/POST
$this->loadParameters();
}
/**
* Returns the array that contains all request information ($_SERVER or $_ENV).
*
* This information is stored in the [sf_path_info_array] constant.
*
* @return array Path information
*/
protected function getPathInfoArray()
{
if (!$this->pathInfoArray)
{
// parse PATH_INFO
switch (sfConfig::get('sf_path_info_array'))
{
case 'SERVER':
$this->pathInfoArray =& $_SERVER;
break;
case 'ENV':
default:
$this->pathInfoArray =& $_ENV;
}
}
return $this->pathInfoArray;
}
/**
* Retrieves the uniform resource identifier for the current web request.
*
* @return string Unified resource identifier
*/
public function getUri()
{
$pathArray = $this->getPathInfoArray();
if ($this->isAbsUri())
{
return $pathArray['REQUEST_URI'];
}
return $this->getUriPrefix().$pathArray['REQUEST_URI'];
}
/**
* See if the client is using absolute uri
*
* @return boolean true, if is absolute uri otherwise false
*/
public function isAbsUri()
{
$pathArray = $this->getPathInfoArray();
return preg_match('/^http/', $pathArray['REQUEST_URI']);
}
/**
* Returns Uri prefix, including protocol, hostname and server port.
*
* @return string Uniform resource identifier prefix
*/
public function getUriPrefix()
{
$pathArray = $this->getPathInfoArray();
if ($this->isSecure())
{
$standardPort = '443';
$proto = 'https';
}
else
{
$standardPort = '80';
$proto = 'http';
}
$port = $pathArray['SERVER_PORT'] == $standardPort || !$pathArray['SERVER_PORT'] ? '' : ':'.$pathArray['SERVER_PORT'];
return $proto.'://'.$pathArray['SERVER_NAME'].$port;
}
/**
* Retrieves the path info for the current web request.
*
* @return string Path info
*/
public function getPathInfo()
{
$pathInfo = '';
$pathArray = $this->getPathInfoArray();
// simulate PATH_INFO if needed
$sf_path_info_key = sfConfig::get('sf_path_info_key');
if (!isset($pathArray[$sf_path_info_key]) || !$pathArray[$sf_path_info_key])
{
if (isset($pathArray['REQUEST_URI']))
{
$script_name = $this->getScriptName();
$uri_prefix = $this->isAbsUri() ? $this->getUriPrefix() : '';
$pathInfo = preg_replace('/^'.preg_quote($uri_prefix, '/').'/','',$pathArray['REQUEST_URI']);
$pathInfo = preg_replace('/^'.preg_quote($script_name, '/').'/', '', $pathInfo);
$prefix_name = preg_replace('#/[^/]+$#', '', $script_name);
$pathInfo = preg_replace('/^'.preg_quote($prefix_name, '/').'/', '', $pathInfo);
$pathInfo = preg_replace('/'.preg_quote($pathArray['QUERY_STRING'], '/').'$/', '', $pathInfo);
}
}
else
{
$pathInfo = $pathArray[$sf_path_info_key];
if ($sf_relative_url_root = $this->getRelativeUrlRoot())
{
$pathInfo = preg_replace('/^'.str_replace('/', '\\/', $sf_relative_url_root).'\//', '', $pathInfo);
}
}
// for IIS
if (isset($_SERVER['SERVER_SOFTWARE']) && false !== stripos($_SERVER['SERVER_SOFTWARE'], 'iis') && $pos = stripos($pathInfo, '.php'))
{
$pathInfo = substr($pathInfo, $pos + 4);
}
if (!$pathInfo)
{
$pathInfo = '/';
}
return $pathInfo;
}
/**
* Loads GET, PATH_INFO and POST data into the parameter list.
*
*/
protected function loadParameters()
{
// merge GET parameters
if (get_magic_quotes_gpc())
{
$_GET = sfToolkit::stripslashesDeep($_GET);
}
$this->getParameterHolder()->addByRef($_GET);
$pathInfo = $this->getPathInfo();
if ($pathInfo)
{
// routing map defined?
$r = sfRouting::getInstance();
if ($r->hasRoutes())
{
$results = $r->parse($pathInfo);
if ($results !== null)
{
$this->getParameterHolder()->addByRef($results);
}
else
{
$this->setParameter('module', sfConfig::get('sf_error_404_module'));
$this->setParameter('action', sfConfig::get('sf_error_404_action'));
}
}
else
{
$array = explode('/', trim($pathInfo, '/'));
$count = count($array);
for ($i = 0; $i < $count; $i++)
{
// see if there's a value associated with this parameter,
// if not we're done with path data
if ($count > ($i + 1))
{
$this->getParameterHolder()->setByRef($array[$i], $array[++$i]);
}
}
}
}
// merge POST parameters
if (get_magic_quotes_gpc())
{
$_POST = sfToolkit::stripslashesDeep((array) $_POST);
}
$this->getParameterHolder()->addByRef($_POST);
// move symfony parameters in a protected namespace (parameters prefixed with _sf_)
foreach ($this->getParameterHolder()->getAll() as $key => $value)
{
if (0 === stripos($key, '_sf_'))
{
$this->getParameterHolder()->remove($key);
$this->setParameter($key, $value, 'symfony/request/sfWebRequest');
unset($_GET[$key]);
}
}
if (sfConfig::get('sf_logging_enabled'))
{
$this->getContext()->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true))));
}
}
/**
* Moves an uploaded file.
*
* @param string A file name
* @param string An absolute filesystem path to where you would like the
* file moved. This includes the new filename as well, since
* uploaded files are stored with random names
* @param int The octal mode to use for the new file
* @param boolean Indicates that we should make the directory before moving the file
* @param int The octal mode to use when creating the directory
*
* @return boolean true, if the file was moved, otherwise false
*
* @throws <b>sfFileException</b> If a major error occurs while attempting to move the file
*/
public function moveFile($name, $file, $fileMode = 0666, $create = true, $dirMode = 0777)
{
if ($this->hasFile($name) && $this->getFileValue($name, 'error') == UPLOAD_ERR_OK && $this->getFileValue($name, 'size') > 0)
{
// get our directory path from the destination filename
$directory = dirname($file);
if (!is_readable($directory))
{
$fmode = 0777;
if ($create && !@mkdir($directory, $dirMode, true))
{
// failed to create the directory
$error = 'Failed to create file upload directory "%s"';
$error = sprintf($error, $directory);
throw new sfFileException($error);
}
// chmod the directory since it doesn't seem to work on
// recursive paths
@chmod($directory, $dirMode);
}
else if (!is_dir($directory))
{
// the directory path exists but it's not a directory
$error = 'File upload path "%s" exists, but is not a directory';
$error = sprintf($error, $directory);
throw new sfFileException($error);
}
else if (!is_writable($directory))
{
// the directory isn't writable
$error = 'File upload path "%s" is not writable';
$error = sprintf($error, $directory);
throw new sfFileException($error);
}
if (@move_uploaded_file($this->getFileValue($name, 'tmp_name'), $file))
{
// chmod our file
@chmod($file, $fileMode);
return true;
}
}
return false;
}
/**
* Returns referer.
*
* @return string
*/
public function getReferer()
{
$pathArray = $this->getPathInfoArray();
return isset($pathArray['HTTP_REFERER']) ? $pathArray['HTTP_REFERER'] : '';
}
/**
* Returns current host name.
*
* @return string
*/
public function getHost()
{
$pathArray = $this->getPathInfoArray();
return isset($pathArray['HTTP_X_FORWARDED_HOST']) ? $pathArray['HTTP_X_FORWARDED_HOST'] : (isset($pathArray['HTTP_HOST']) ? $pathArray['HTTP_HOST'] : '');
}
/**
* Returns current script name.
*
* @return string
*/
public function getScriptName()
{
$pathArray = $this->getPathInfoArray();
return isset($pathArray['SCRIPT_NAME']) ? $pathArray['SCRIPT_NAME'] : (isset($pathArray['ORIG_SCRIPT_NAME']) ? $pathArray['ORIG_SCRIPT_NAME'] : '');
}
/**
* Returns request method.
*
* @return string
*/
public function getMethodName()
{
$pathArray = $this->getPathInfoArray();
return isset($pathArray['REQUEST_METHOD']) ? $pathArray['REQUEST_METHOD'] : 'GET';
}
/**
* Gets a list of languages acceptable by the client browser
*
* @return array Languages ordered in the user browser preferences
*/
public function getLanguages()
{
if ($this->languages)
{
return $this->languages;
}
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
return array();
}
$languages = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($languages as $lang)
{
if (strstr($lang, '-'))
{
$codes = explode('-', $lang);
if ($codes[0] == 'i')
{
// Language not listed in ISO 639 that are not variants
// of any listed language, which can be registerd with the
// i-prefix, such as i-cherokee
if (count($codes) > 1)
{
$lang = $codes[1];
}
}
else
{
for ($i = 0, $max = count($codes); $i < $max; $i++)
{
if ($i == 0)
{
$lang = strtolower($codes[0]);
}
else
{
$lang .= '_'.strtoupper($codes[$i]);
}
}
}
}
$this->languages[] = $lang;
}
return $this->languages;
}
/**
* Gets a list of charsets acceptable by the client browser.
*
* @return array List of charsets in preferable order
*/
public function getCharsets()
{
if ($this->charsets)
{
return $this->charsets;
}
if (!isset($_SERVER['HTTP_ACCEPT_CHARSET']))
{
return array();
}
$this->charsets = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT_CHARSET']);
return $this->charsets;
}
/**
* Gets a list of content types acceptable by the client browser
*
* @return array Languages ordered in the user browser preferences
*/
public function getAcceptableContentTypes()
{
if ($this->acceptableContentTypes)
{
return $this->acceptableContentTypes;
}
if (!isset($_SERVER['HTTP_ACCEPT']))
{
return array();
}
$this->acceptableContentTypes = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT']);
return $this->acceptableContentTypes;
}
/**
* Returns true id the request is a XMLHttpRequest (via prototype 'HTTP_X_REQUESTED_WITH' header).
*
* @return boolean
*/
public function isXmlHttpRequest()
{
return ($this->getHttpHeader('X_REQUESTED_WITH') == 'XMLHttpRequest');
}
public function getHttpHeader($name, $prefix = 'http')
{
if ($prefix)
{
$prefix = strtoupper($prefix).'_';
}
$name = $prefix.strtoupper(strtr($name, '-', '_'));
$pathArray = $this->getPathInfoArray();
return isset($pathArray[$name]) ? stripslashes($pathArray[$name]) : null;
}
/**
* Gets a cookie value.
*
* @return mixed
*/
public function getCookie($name, $defaultValue = null)
{
$retval = $defaultValue;
if (isset($_COOKIE[$name]))
{
$retval = get_magic_quotes_gpc() ? stripslashes($_COOKIE[$name]) : $_COOKIE[$name];
}
return $retval;
}
/**
* Returns true if the current request is secure (HTTPS protocol).
*
* @return boolean
*/
public function isSecure()
{
$pathArray = $this->getPathInfoArray();
return (
(isset($pathArray['HTTPS']) && (strtolower($pathArray['HTTPS']) == 'on' || strtolower($pathArray['HTTPS']) == 1))
||
(isset($pathArray['HTTP_X_FORWARDED_PROTO']) && strtolower($pathArray['HTTP_X_FORWARDED_PROTO']) == 'https')
);
}
/**
* Retrieves relative root url.
*
* @return string URL
*/
public function getRelativeUrlRoot()
{
if ($this->relativeUrlRoot === null)
{
$this->relativeUrlRoot = sfConfig::get('sf_relative_url_root', preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName()));
}
return $this->relativeUrlRoot;
}
/**
* Sets the relative root url for the current web request.
*
* @param string Value for the url
*/
public function setRelativeUrlRoot($value)
{
$this->relativeUrlRoot = $value;
}
/**
* Executes the shutdown procedure.
*
*/
public function shutdown()
{
}
/**
* Splits an HTTP header for the current web request.
*
* @param string Header to split
*/
public function splitHttpAcceptHeader($header)
{
$values = array();
foreach (array_filter(explode(',', $header)) as $value)
{
// Cut off any q-value that might come after a semi-colon
if ($pos = strpos($value, ';'))
{
$q = (float) trim(substr($value, $pos + 3));
$value = trim(substr($value, 0, $pos));
}
else
{
$q = 1;
}
$values[$value] = $q;
}
arsort($values);
return array_keys($values);
}
}