* @package Horde_Controller
* @subpackage Request
*/
-class Horde_Controller_Request_Base
+abstract class Horde_Controller_Request_Base
{
/**
* Request timestamp
/**
* The request body
*
+ * @TODO Allow overriding php://input, and make the default interface to
+ * return an SplFileObject, or a (doesn't currently exist) Horde_File
+ * object, instead of the raw data.
+ *
* @return string
*/
public function getBody()
{
if (!isset($this->_body)) {
- $this->_body = file_get_contents("php://input");
+ $this->_body = file_get_contents('php://input');
}
return $this->_body;
}
}
/**
- * Get rid of register_globals variables.
- *
- * @author Richard Heyes
- * @author Stefan Esser
- * @url http://www.phpguru.org/article.php?ne_id=60
- */
- public function reverseRegisterGlobals()
- {
- if (ini_get('register_globals')) {
- // Variables that shouldn't be unset
- $noUnset = array(
- 'GLOBALS',
- '_GET',
- '_POST',
- '_COOKIE',
- '_REQUEST',
- '_SERVER',
- '_ENV',
- '_FILES',
- );
-
- $input = array_merge(
- $_GET,
- $_POST,
- $_COOKIE,
- $_SERVER,
- $_ENV,
- $_FILES,
- isset($_SESSION) ? $_SESSION : array()
- );
-
- foreach ($input as $k => $v) {
- if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
- unset($GLOBALS[$k]);
- }
- }
- }
- }
-
- /**
- * @author Ilia Alshanetsky <ilia@php.net>
- */
- public function reverseMagicQuotes()
- {
- set_magic_quotes_runtime(0);
- if (get_magic_quotes_gpc()) {
- $input = array(&$_GET, &$_POST, &$_REQUEST, &$_COOKIE, &$_ENV, &$_SERVER);
-
- while (list($k, $v) = each($input)) {
- foreach ($v as $key => $val) {
- if (!is_array($val)) {
- $key = stripslashes($key);
- $input[$k][$key] = stripslashes($val);
- continue;
- }
- $input[] =& $input[$k][$key];
- }
- }
-
- unset($input);
- }
- }
-
- /**
* Turn this request into a URL-encoded query string.
*/
public function __toString()
return http_build_query($this);
}
- public function getPath()
- {
- }
+ abstract public function getPath();
/**
* Uniquely identify each request from others. This aids in threading
- * related log requests during troubleshooting on a busy server
+ * related log requests during troubleshooting on a busy server
*/
private function _initRequestId()
{
$this->_requestId = (string)new Horde_Support_Uuid;
}
-
- /**
- * The default locale (eg. en-us) the application uses.
- *
- * @var string
- * @access private
- */
- var $_defaultLocale = 'en-us';
-
- /**
- * The locales (eg. en-us, fi_fi, se_se etc) the application
- * supports.
- *
- * @var array
- * @access private
- */
- var $_supportedLocales = NULL;
-
- /**
- * Gets the used character encoding.
- *
- * Returns the name of the character encoding used in the body of
- * this request.
- *
- * @todo implement this method
- * @return string the used character encoding
- * @access public
- */
- function getCharacterEncoding()
- {
- // XXX: what to do with this?
- }
-
- /**
- * Gets the default locale for the application.
- *
- * @return string the default locale
- * @access public
- */
- function getDefaultLocale()
- {
- return $this->_defaultLocale;
- }
-
- /**
- * Gets the supported locales for the application.
- *
- * @return array the supported locales
- * @access public
- */
- function getSupportedLocales()
- {
- return $this->_supportedLocales;
- }
-
- /**
- * Deduces the clients preferred locale.
- *
- * You might want to override this method if you want to do more
- * sophisticated decisions. It gets the supported locales and the
- * default locale from the class attributes file and tries to find a
- * match. If no match is found it uses the default locale. The
- * locale is always changed into lowercase.
- *
- * @return string the locale
- * @access public
- */
- function getLocale()
- {
- require_once('HTTP.php');
-
- if ($this->_supportedLocales == NULL) {
- return $this->_defaultLocale;
- } else {
- return strtolower(HTTP::negotiateLanguage( $this->_supportedLocales,
- $this->_defaultLocale ));
- }
- }
-
- /**
- * Sets the default locale for the application.
- *
- * Create an instance of <code>Ismo_Core_Request</code> manually and
- * set the default locale with this method. Then add it as the
- * application's request class with
- * <code>Ismo_Core_Application::setRequest()</code>.
- *
- * @param string $locale the default locale
- * @access public
- */
- function setDefaultLocale($locale)
- {
- $this->_defaultLocale = str_replace('_', '-', $locale);
- }
-
- /**
- * Sets the locales supported by the application.
- *
- * Create an instance of <code>Ismo_Core_Request</code> manually and
- * set the supported locales with this method. Then add it as the
- * application's request class with
- * <code>Ismo_Core_Application::setRequest()</code>.
- *
- * @param array $locales the locales
- * @access public
- */
- function setSupportedLocales($locales)
- {
- if (is_array($locales)) {
- foreach ($locales as $n => $locale) {
- $this->_supportedLocales[ str_replace('_', '-', $locale) ] = true;
- }
- }
- }
-
}
*/
/**
+ * @TODO Allow specifying the stream where output is going instead of assuming
+ * STDOUT.
+ *
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
*/
class Horde_Controller_Response_Cli extends Horde_Controller_Response_Base
{
+ /**
+ * @var stream
+ */
+ protected $_stream;
+
+ public function construct()
+ {
+ $this->_stream = fopen('php://stdout');
+ }
+
+ /**
+ * Writes a string to the Response stream
+ *
+ * Can be called with an array of parameters or with a variable number of
+ * parameters like printf.
+ *
+ * @param string $string The string to write to the reponse stream
+ * @param array|params $params The parameters to replace in the string (think printf)
+ */
+ public function write($string, $params = null)
+ {
+ if (!is_array($params)) {
+ $params = func_get_args();
+ array_shift($params);
+ }
+ fwrite($this->_stream, vsprintf($string, $params));
+ }
+
+ /**
+ * Writes a newline-terminated string to the Response stream
+ *
+ * Can be called with an array of parameters or with a variable number of
+ * parameters like printf.
+ *
+ * @param string $string The string to write to the reponse stream
+ * @param array|params $params The parameters to replace in the string (think printf)
+ */
+ public function writeLn($string, $params = array())
+ {
+ if (!is_array($params)) {
+ $params = func_get_args();
+ array_shift($params);
+ }
+ $line = vsprintf($string, $params);
+ if (substr($line, -1) != "\n") {
+ $line .= "\n";
+ }
+ fwrite($this->_stream, $line);
+ }
}