--- /dev/null
+<?php
+/**
+ * Copyright 2007 Maintainable Software, LLC
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author Mike Naberezny <mike@maintainable.com>
+ * @author Derek DeVries <derek@maintainable.com>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php
+ * @category Horde
+ * @package Horde_Controller
+ * @subpackage Response
+ */
+
+/**
+ * Handles managing of what types of responses the client can handle and which
+ * one was requested.
+ *
+ * @author Mike Naberezny <mike@maintainable.com>
+ * @author Derek DeVries <derek@maintainable.com>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php
+ * @category Horde
+ * @package Horde_Controller
+ * @subpackage Response
+ */
+class Horde_Controller_Mime_Type
+{
+ public $symbol;
+ public $synonyms;
+ public $string;
+
+ public static $set = array();
+ public static $lookup = array();
+ public static $extensionLookup = array();
+ public static $registered = false;
+
+ public function __construct($string, $symbol = null, $synonyms = array())
+ {
+ $this->string = $string;
+ $this->symbol = $symbol;
+ $this->synonyms = $synonyms;
+ }
+
+ public function __toString()
+ {
+ return $this->symbol;
+ }
+
+ public static function lookup($string)
+ {
+ if (!empty(self::$lookup[$string])) {
+ return self::$lookup[$string];
+ } else {
+ return null;
+ }
+ }
+
+ public static function lookupByExtension($ext)
+ {
+ if (!empty(self::$extensionLookup[$ext])) {
+ return self::$extensionLookup[$ext];
+ } else {
+ return null;
+ }
+ }
+
+ public static function register($string, $symbol, $synonyms = array(), $extSynonyms = array())
+ {
+ $type = new Horde_Controller_Mime_Type($string, $symbol, $synonyms);
+ self::$set[] = $type;
+
+ // add lookup strings
+ foreach (array_merge((array)$string, $synonyms) as $string) {
+ self::$lookup[$string] = $type;
+ }
+
+ // add extesnsion lookups
+ foreach (array_merge((array)$symbol, $extSynonyms) as $ext) {
+ self::$extensionLookup[$ext] = $type;
+ }
+ }
+
+ /**
+ * @todo - actually parse the header. This is simply mocked out
+ * with common types for now
+ */
+ public static function parse($acceptHeader)
+ {
+ $types = array();
+
+ if (strstr($acceptHeader, 'text/javascript')) {
+ if (isset(self::$extensionLookup['js'])) {
+ $types[] = self::$extensionLookup['js'];
+ }
+
+ } elseif (strstr($acceptHeader, 'text/html')) {
+ if (isset(self::$extensionLookup['html'])) {
+ $types[] = self::$extensionLookup['html'];
+ }
+
+ } elseif (strstr($acceptHeader, 'text/xml')) {
+ if (isset(self::$extensionLookup['xml'])) {
+ $types[] = self::$extensionLookup['xml'];
+ }
+
+ // default to html
+ } else {
+ if (isset(self::$extensionLookup['html'])) {
+ $types[] = self::$extensionLookup['html'];
+ }
+ }
+ return $types;
+ }
+
+ /**
+ * Register mime types
+ * @todo - move this elsewhere?
+ */
+ public static function registerTypes()
+ {
+ if (!self::$registered) {
+ Horde_Controller_Mime_Type::register("*/*", 'all');
+ Horde_Controller_Mime_Type::register("text/plain", 'text', array(), array('txt'));
+ Horde_Controller_Mime_Type::register("text/html", 'html', array('application/xhtml+xml'), array('xhtml'));
+ Horde_Controller_Mime_Type::register("text/javascript", 'js', array('application/javascript', 'application/x-javascript'), array('xhtml'));
+ Horde_Controller_Mime_Type::register("application/json", 'json');
+ Horde_Controller_Mime_Type::register("text/csv", 'csv');
+ Horde_Controller_Mime_Type::register("application/xml", 'xml', array('text/xml', 'application/x-xml'));
+ self::$registered = true;
+ }
+ }
+
+}
*/
public function __construct($options = array())
{
- $this->_initSessionData();
-
- // superglobal data if not passed in thru constructor
- $this->_get = isset($options['get']) ? $options['get'] : $_GET;
- $this->_post = isset($options['post']) ? $options['post'] : $_POST;
- $this->_cookie = isset($options['cookie']) ? $options['cookie'] : $_COOKIE;
- $this->_request = isset($options['request']) ? $options['request'] : $_REQUEST;
-
- parent::__construct($options);
-
- $this->_pathParams = array();
- // $this->_formattedRequestParams = $this->_parseFormattedRequestParameters();
-
- // use FileUpload object to store files
- $this->_setFilesSuperglobals();
-
- // disable all superglobal data to force us to use correct way
- //@TODO
- //$_GET = $_POST = $_FILES = $_COOKIE = $_REQUEST = $_SERVER = array();
-
- $this->_domain = $this->getServer('SERVER_NAME');
- $this->_uri = trim($this->getServer('REQUEST_URI'), '/');
- $this->_method = $this->getServer('REQUEST_METHOD');
- // @TODO look at HTTP_X_FORWARDED_FOR, handling multiple addresses: http://weblogs.asp.net/james_crowley/archive/2007/06/19/gotcha-http-x-forwarded-for-returns-multiple-ip-addresses.aspx
- $this->_remoteIp = $this->getServer('REMOTE_ADDR');
- $this->_port = $this->getServer('SERVER_PORT');
- $this->_https = $this->getServer('HTTPS');
- $this->_isAjax = $this->getServer('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
+ try {
+ $this->_initSessionData();
+
+ // register default mime types
+ Horde_Controller_Mime_Type::registerTypes();
+
+ // superglobal data if not passed in thru constructor
+ $this->_get = isset($options['get']) ? $options['get'] : $_GET;
+ $this->_post = isset($options['post']) ? $options['post'] : $_POST;
+ $this->_cookie = isset($options['cookie']) ? $options['cookie'] : $_COOKIE;
+ $this->_request = isset($options['request']) ? $options['request'] : $_REQUEST;
+
+ parent::__construct($options);
+
+ $this->_pathParams = array();
+ //$this->_formattedRequestParams = $this->_parseFormattedRequestParameters();
+
+ // use FileUpload object to store files
+ $this->_setFilesSuperglobals();
+
+ // disable all superglobal data to force us to use correct way
+ //@TODO
+ //$_GET = $_POST = $_FILES = $_COOKIE = $_REQUEST = $_SERVER = array();
+
+ $this->_domain = $this->getServer('SERVER_NAME');
+ $this->_uri = trim($this->getServer('REQUEST_URI'), '/');
+ $this->_method = $this->getServer('REQUEST_METHOD');
+ // @TODO look at HTTP_X_FORWARDED_FOR, handling multiple addresses: http://weblogs.asp.net/james_crowley/archive/2007/06/19/gotcha-http-x-forwarded-for-returns-multiple-ip-addresses.aspx
+ $this->_remoteIp = $this->getServer('REMOTE_ADDR');
+ $this->_port = $this->getServer('SERVER_PORT');
+ $this->_https = $this->getServer('HTTPS') || $this->getServer('SSL_PROTOCOL') || $this->getServer('HTTP_X_CLUSTER_SSL');
+ $this->_isAjax = $this->getServer('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
+ } catch (Exception $e) {
+ $this->_malformed = true;
+ $this->_exception = $e;
+ }
}
}
}
- // $this->_contentType = Horde_Controller_Mime_Type::lookup($type);
+ $this->_contentType = Horde_Controller_Mime_Type::lookup($type);
}
return $this->_contentType;
}
<dir name="lib">
<dir name="Horde">
<dir name="Controller">
+ <dir name="Mime">
+ <file name="Type.php" role="php" />
+ </dir> <!-- /lib/Horde/Controller/Mime -->
<dir name="Request">
<file name="Base.php" role="php" />
<file name="Http.php" role="php" />
<file name="Mock.php" role="php" />
- </dir> <!-- /lib/Horde/Controller/Requeset -->
+ </dir> <!-- /lib/Horde/Controller/Request -->
<dir name="Response">
<file name="Base.php" role="php" />
<file name="Http.php" role="php" />
<file name="Base.php" role="php" />
<file name="Dispatcher.php" role="php" />
<file name="Exception.php" role="php" />
+ <file name="Mime.php" role="php" />
</dir> <!-- /lib/Horde/Controller -->
</dir> <!-- /lib/Horde -->
</dir> <!-- /lib -->
<install name="lib/Horde/Controller/Base.php" as="Horde/Controller/Base.php" />
<install name="lib/Horde/Controller/Dispatcher.php" as="Horde/Controller/Dispatcher.php" />
<install name="lib/Horde/Controller/Exception.php" as="Horde/Controller/Exception.php" />
+ <install name="lib/Horde/Controller/Mime/Type.php" as="Horde/Controller/Mime/Type.php" />
<install name="lib/Horde/Controller/Request/Base.php" as="Horde/Controller/Request/Base.php" />
<install name="lib/Horde/Controller/Request/Http.php" as="Horde/Controller/Request/Http.php" />
<install name="lib/Horde/Controller/Request/Mock.php" as="Horde/Controller/Request/Mock.php" />