pax_global_header00006660000000000000000000000064120561714310014512gustar00rootroot0000000000000052 comment=9d4bace7b67ac1aa27c887cede85f45c71d34cf8 php-horde-controller-2.0.1/000077500000000000000000000000001205617143100155615ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/000077500000000000000000000000001205617143100214615ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/doc/000077500000000000000000000000001205617143100222265ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/doc/Horde/000077500000000000000000000000001205617143100232675ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/doc/Horde/Controller/000077500000000000000000000000001205617143100254125ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/doc/Horde/Controller/COPYING000066400000000000000000000024301205617143100264440ustar00rootroot00000000000000 Copyright 1999-2012 Horde LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/000077500000000000000000000000001205617143100222275ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/000077500000000000000000000000001205617143100232705ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller.php000066400000000000000000000010451205617143100261240ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller { /** * Process the incoming request. * * @param Horde_Controller_Request $request The incoming request. * @param Horde_Controller_Response $response The outgoing response. */ public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/000077500000000000000000000000001205617143100254135ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Base.php000066400000000000000000000102631205617143100270000ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ abstract class Horde_Controller_Base implements Horde_Controller { /** * This is marked private on purpose, so that you have to use the * getInjector() method to access it in derived classes. This is done so * that you don't assume its always set, since its set via setter-injection * to save on having to define a constructor param for it * * @var Horde_Injector */ private $_injector; /** * Private on purpose so you have to use getLogger(). * * @var Horde_Log_Logger */ private $_logger; /** * Private on purpose so you have to use getView(). * * @var Horde_View */ private $_view; /** * Private on purpose so you have to use getUrlWriter(). * * @var Horde_Controller_UrlWriter */ private $_urlWriter; /** * Set the injector for this controller * * @inject * * @param Horde_Injector The injector that this controller should use to create objects */ public function setInjector(Horde_Injector $injector) { $this->_injector = $injector; } /** * Get the injector for this controller * * @return Horde_Injector The injector previously set for this controller, * or a new Horde_Injector_TopLevel */ public function getInjector() { if (!$this->_injector) { $this->_injector = new Horde_Injector_TopLevel(); } return $this->_injector; } /** * Set the Logger for this controller * * @inject * * @param Horde_Log_Logger The logger to use for this controller */ public function setLogger(Horde_Log_Logger $logger) { $this->_logger = $logger; } /** * Get the logger assigned to this controller * * @return Horde_Log_Logger The logger for this controller */ public function getLogger() { if (!$this->_logger) { $this->_logger = new Horde_Log_Logger(new Horde_Log_Handler_Null()); } return $this->_logger; } /** * Set the Horde_View object to be used for this controller * * @inject * * @param Horde_View_Base The view object */ public function setView(Horde_View_Base $view) { $this->_view = $view; $this->_view->controller = $this; } /** * Gets the current view for this controller * * @note This method will create an empty Horde_View if none has been set. * * @return Horde_View_Base The view for this controller, or a new empty * Horde_View if none is set */ public function getView() { if (!$this->_view) { $this->setView($this->getInjector()->getInstance('Horde_View_Base')); } return $this->_view; } /** * Get the current request */ public function getRequest() { return $this->getInjector()->getInstance('Horde_Controller_Request'); } /** * Get the current response */ public function getResponse() { return $this->getInjector()->getInstance('Horde_Controller_Response'); } /** * Get an instance of UrlWriter for this controller. * * @return Horde_Controller_UrlWriter */ public function getUrlWriter() { // instantiate UrlWriter that will generate URLs for this controller if (!$this->_urlWriter) { // Need a reasonable way to get the :controller match from the URL - reverse route? // $defaults = array('controller' => $this->getControllerName()); $this->_urlWriter = $this->getInjector()->getInstance('Horde_Controller_UrlWriter'); } return $this->_urlWriter; } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Exception.php000066400000000000000000000012771205617143100300710ustar00rootroot00000000000000 * @author Derek DeVries * @author Chuck Hagenbuch * @license http://www.horde.org/licenses/bsd * @category Horde * @package Controller */ /** * @author Mike Naberezny * @author Derek DeVries * @author Chuck Hagenbuch * @license http://www.horde.org/licenses/bsd * @category Horde * @package Controller */ class Horde_Controller_Exception extends Horde_Exception_Wrapped { } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Filter/000077500000000000000000000000001205617143100266405ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Filter/Gzip.php000066400000000000000000000021521205617143100302620ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Filter_Gzip implements Horde_Controller_PostFilter { public function processResponse(Horde_Controller_Request $request, Horde_Controller_Response $response, Horde_Controller $controller) { $body = $response->getBody(); $body = gzencode($body); $response->setHeader('Content-Encoding', 'gzip'); $response->setHeader('Content-Length', $this->_byteCount($body)); $response->setBody($body); return $response; } /** * If mbstring is set to overload str* function then we could be counting * multi-byte chars as single bytes so we need to treat the string like its * 8-bit encoded to get an accurate byte count. */ protected function _byteCount($string) { if (ini_get('mbstring.func_overload') > 0) { return mb_strlen($string, '8bit'); } return strlen($string); } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/FilterCollection.php000066400000000000000000000007771205617143100314000ustar00rootroot00000000000000 * @author Bob McKee * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_FilterCollection { /** */ public function addPreFilter(Horde_Controller_PreFilter $filter); /** */ public function addPostFilter(Horde_Controller_PostFilter $filter); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/FilterRunner.php000066400000000000000000000053751205617143100305550ustar00rootroot00000000000000 * @author James Pepin * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_FilterRunner implements Horde_Controller_FilterCollection { /** * @var Horde_Controller */ protected $_controller; /** * @var array */ protected $_preFilters = array(); /** * @var array */ protected $_postFilters = array(); /** */ public function __construct(Horde_Controller $controller) { $this->_controller = $controller; } /** * Append filter to prefilters array * * @param Horde_Controller_PreFilter $filter */ public function addPreFilter(Horde_Controller_PreFilter $filter) { array_push($this->_preFilters, $filter); } /** * Prepend fitler to postfilters array * * @param Horde_Controller_PostFilter $filter */ public function addPostFilter(Horde_Controller_PostFilter $filter) { array_unshift($this->_postFilters, $filter); } /** * Executes filters and controller method. Execution happens in the following order: * * - Run processRequest() on prefilters in first-in-first-out order * - Run processRequest() on controller * - Run processResponse() on postfilters in first-in-last-out order * * @param Horde_Controller_Request $request * @param Horde_Controller_Response $response * * @return Horde_Controller_Response */ public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response) { if ($this->_applyPreFilters($request, $response) !== Horde_Controller_PreFilter::REQUEST_HANDLED) { $this->_controller->processRequest($request, $response); $this->_applyPostFilters($request, $response); } return $response; } /** */ protected function _applyPreFilters(Horde_Controller_Request $request, Horde_Controller_Response $response) { foreach ($this->_preFilters as $filter) { if ($filter->processRequest($request, $response, $this->_controller) === Horde_Controller_PreFilter::REQUEST_HANDLED) { return Horde_Controller_PreFilter::REQUEST_HANDLED; } } return Horde_Controller_PreFilter::REQUEST_CONTINUE; } /** */ protected function _applyPostFilters(Horde_Controller_Request $request, Horde_Controller_Response $response) { foreach ($this->_postFilters as $filter) { $filter->processResponse($request, $response, $this->_controller); } } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Null.php000066400000000000000000000006611205617143100270410ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Null implements Horde_Controller { public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response) { } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/PostFilter.php000066400000000000000000000007471205617143100302270ustar00rootroot00000000000000 * @author Bob McKee * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_PostFilter { public function processResponse(Horde_Controller_Request $request, Horde_Controller_Response $response, Horde_Controller $controller); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/PreFilter.php000066400000000000000000000010261205617143100300170ustar00rootroot00000000000000 * @author Bob McKee * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_PreFilter { const REQUEST_HANDLED = true; const REQUEST_CONTINUE = false; public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response, Horde_Controller $controller); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Request.php000066400000000000000000000013021205617143100275500ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_Request { /** */ public function getPath(); /** */ public function getMethod(); /** */ public function getGetVars(); /** */ public function getFileVars(); /** */ public function getServerVars(); /** */ public function getPostVars(); /** */ public function getCookieVars(); /** */ public function getRequestVars(); /** */ public function getSessionId(); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Request/000077500000000000000000000000001205617143100270435ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Request/Http.php000066400000000000000000000072001205617143100304720ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Request_Http implements Horde_Controller_Request { /** * Request path * @var string */ protected $_path; /** * All the headers * @var array */ protected $_headers = null; public function setPath($path) { $this->_path = $path; } public function getPath() { return $this->_path; } public function getMethod() { $serverVars = $this->getServerVars(); return $serverVars['REQUEST_METHOD']; } public function getGetVars() { return $_GET; } public function getFileVars() { return $_FILES; } public function getServerVars() { return $_SERVER; } public function getPostVars() { return $_POST; } public function getCookieVars() { return $_COOKIE; } public function getRequestVars() { return $_REQUEST; } public function getSessionId() { //TODO: how do we get session ID? //should probably be passing it in the constructor, or via setSession //we should definitely lazy-load sessions though cause we don't always care about it //perhaps a preFilter to start the session if the controller requests it, and then call setSession on the request //object return 0; } /** * Gets the value of header. * * Returns the value of the specified request header. * * @param string $name the name of the header * @return string the value of the specified header */ public function getHeader($name) { if ($this->_headers == null) { $this->_headers = $this->_getAllHeaders(); } $name = Horde_String::lower($name); if (isset($this->_headers[$name])) { return $this->_headers[$name]; } return null; } /** * Gets all the header names. * * Returns an array of all the header names this request * contains. * * @return array all the available headers as strings */ public function getHeaderNames() { if ($this->_headers == null) { $this->_headers = $this->_getAllHeaders(); } return array_keys($this->_headers); } /** * Gets all the headers. * * Returns an associative array of all the header names and values of this * request. * * @return array containing all the headers */ public function getHeaders() { if ($this->_headers == null) { $this->_headers = $this->_getAllHeaders(); } return $this->_headers; } /** * Returns all HTTP_* headers. * * Returns all the HTTP_* headers. Works both if PHP is an apache * module and if it's running as a CGI. * * @return array the headers' names and values */ private function _getAllHeaders() { if (function_exists('getallheaders')) { return array_change_key_case(getallheaders(), CASE_LOWER); } $result = array(); $server = $this->getServerVars(); reset($server); foreach ($server as $key => $value) { $header_name = substr($key, 0, 5); if ($header_name == 'HTTP_') { $hdr = str_replace('_', '-', Horde_String::lower(substr($key, 5))); $result[$hdr] = $value; } } return $result; } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Request/Mock.php000066400000000000000000000035641205617143100304550ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Request_Mock extends Horde_Controller_Request_Http { /** * Request variables. * * @var array */ protected $_vars; /** * Constructor. * * @param array $vars The request variables. */ public function __construct($vars = array()) { $this->setVars($vars); $server = $this->getServerVars(); if (!empty($server['REDIRECT_URL'])) { $this->setPath($server['REDIRECT_URL']); } else if (!empty($server['REQUEST_URI'])) { $this->setPath($server['REQUEST_URI']); } } /** * Set the request variables GET, POST, COOKIE, SERVER, REQUEST etc. * * @param array $vars The request variables. */ public function setVars($vars) { foreach ($vars as $key => $sub) { $this->_vars[strtoupper($key)] = $sub; } } /** * Gets the request variables GET, POST, COOKIE, SERVER, REQUEST etc. * * @param string $name The name of the superglobal whose vars to return */ protected function getVars($name) { if (isset($this->_vars[$name])) { return $this->_vars[$name]; } } public function getGetVars() { return $this->getVars('GET'); } public function getFileVars() { return $this->getVars('FILES'); } public function getServerVars() { return $this->getVars('SERVER'); } public function getPostVars() { return $this->getVars('POST'); } public function getCookieVars() { return $this->getVars('COOKIE'); } public function getRequestVars() { return $this->getVars('REQUEST'); } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Request/Null.php000066400000000000000000000016761205617143100305000ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Request_Null implements Horde_Controller_Request { /** */ public function getMethod() { } /** */ public function getPath() { } /** */ public function getParameters() { } /** */ public function getGetVars() { } /** */ public function getFileVars() { } /** */ public function getServerVars() { } /** */ public function getPostVars() { } /** */ public function getCookieVars() { } /** */ public function getRequestVars() { } /** */ public function getSessionId() { } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/RequestConfiguration.php000066400000000000000000000007271205617143100323120ustar00rootroot00000000000000 * @author James Pepin * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_RequestConfiguration { public function getControllerName(); public function setControllerName($controllerName); public function getSettingsExporterName(); public function setSettingsExporterName($settingsName); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Response.php000066400000000000000000000026041205617143100277240ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Response { protected $_headers = array(); protected $_body; protected $_requestConfiguration; public function __construct() { } public function setHeaders(array $headers) { $this->_headers = array_merge($this->_headers, $headers); } public function setHeader($name, $value) { $this->_headers[$name] = $value; } public function setContentType($contentType, $charset = 'UTF-8') { $this->setHeader('Content-Type', "$contentType; charset=$charset"); } public function setBody($body) { $this->_body = $body; } public function getHeaders() { return $this->_headers; } public function getBody() { return $this->_body; } public function internalRedirect() { return $this->_requestConfiguration != null; } public function setRedirectUrl($url) { $this->_headers['Location'] = $url; } public function getRedirectConfiguration() { return $this->_requestConfiguration; } public function setRedirectConfiguration(Horde_Controller_RequestConfiguration $config) { $this->_requestConfiguration = $config; } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/ResponseWriter.php000066400000000000000000000004301205617143100311140ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_ResponseWriter { public function writeResponse(Horde_Controller_Response $response); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/ResponseWriter/000077500000000000000000000000001205617143100304065ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/ResponseWriter/Web.php000066400000000000000000000012131205617143100316310ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_ResponseWriter_Web implements Horde_Controller_ResponseWriter { /** */ public function writeResponse(Horde_Controller_Response $response) { foreach ($response->getHeaders() as $key => $value) { header("$key: $value"); } $body = $response->getBody(); if (is_resource($body)) { stream_copy_to_stream($body, fopen('php://output', 'a')); } else { echo $body; } } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/ResponseWriter/WebDebug.php000066400000000000000000000022361205617143100326060ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_ResponseWriter_WebDebug implements Horde_Controller_ResponseWriter { public function writeResponse(Horde_Controller_Response $response) { $headerHtml = '
Headers:
';
        $headers = $response->getHeaders();
        foreach ($headers as $key => $value) {
            $headerHtml .= htmlspecialchars("$key: $value\n");
        }
        echo $headerHtml . '
'; if (isset($headers['Location'])) { echo '

Redirect To: ' . htmlspecialchars($headers['Location']) . '

'; } $body = $response->getBody(); if (is_resource($body)) { $body = stream_get_contents($body); } if (isset($headers['Content-Encoding']) && $headers['Content-Encoding'] == 'gzip') { // Strip off the header and inflate it echo gzinflate(substr($body, 10)); } else { echo $body; } } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/Runner.php000066400000000000000000000033541205617143100274020ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_Runner { protected $_logger; public function __construct(Horde_Log_Logger $logger) { $this->_logger = $logger; } public function execute(Horde_Injector $injector, Horde_Controller_Request $request, Horde_Controller_RequestConfiguration $config) { $this->_logger->debug('RequestConfiguration in Horde_Controller_Runner: ' . print_r($config, true)); $exporter = $injector->getInstance($config->getSettingsExporterName()); $exporter->exportBindings($injector); $controller = $config->getControllerName(); if (!$controller) { throw new Horde_Controller_Exception('No controller defined'); } $implementationBinder = new Horde_Injector_Binder_Implementation($controller); $injector->addBinder('Horde_Controller', new Horde_Injector_Binder_AnnotatedSetters($implementationBinder)); $filterRunner = $injector->createInstance('Horde_Controller_FilterRunner'); $exporter->exportFilters($filterRunner, $injector); $response = $filterRunner->processRequest($request, $injector->createInstance('Horde_Controller_Response')); if ($response->internalRedirect()) { $this->_logger->debug('Internal redirect'); return $this->execute($injector->createChildInjector(), $request, $response->getRedirectConfiguration()); } $this->_logger->debug('Returning Horde_Controller_Response'); return $response; } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/SettingsExporter.php000066400000000000000000000010341205617143100314530ustar00rootroot00000000000000 * @author James Pepin * @license http://www.horde.org/licenses/bsd BSD */ interface Horde_Controller_SettingsExporter { /** */ public function exportBindings(Horde_Injector $injector); /** */ public function exportFilters(Horde_Controller_FilterCollection $filters, Horde_Injector $injector); } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/SettingsExporter/000077500000000000000000000000001205617143100307445ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/SettingsExporter/Default.php000066400000000000000000000010741205617143100330430ustar00rootroot00000000000000 * @author James Pepin * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_SettingsExporter_Default implements Horde_Controller_SettingsExporter { /** */ public function exportBindings(Horde_Injector $injector) { } /** */ public function exportFilters(Horde_Controller_FilterCollection $filters, Horde_Injector $injector) { } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/lib/Horde/Controller/UrlWriter.php000066400000000000000000000044131205617143100300650ustar00rootroot00000000000000 * @author Derek DeVries * @author Chuck Hagenbuch * @license http://www.horde.org/licenses/bsd BSD */ class Horde_Controller_UrlWriter { /** * Defaults to merge into route parameters when not using named routes. * @var array */ protected $_defaults; /** * @var Horde_Routes_Util */ protected $_utils; /** * Class constructor * * @param Horde_Routes_Utils $utils Route utilities * @param array $defaults Defaults to merge for urlFor() */ public function __construct(Horde_Routes_Utils $utils, $defaults = array()) { $this->_utils = $utils; $this->_defaults = $defaults; } /** * Generate a URL. Same signature as Horde_Routes_Utils->urlFor(). * * @param $first mixed * @param $second mixed * @return string */ public function urlFor($first, $second = array()) { // anonymous route: serialize to params & merge defaults // urlFor(array('controller' => 'books')) if (is_array($first)) { $first = array_merge($this->_defaults, $this->_serializeToParams($first)); } // named route: serialize to params only (no merge) // urlFor('notes', array('action' => 'show', 'id' => 1)) if (is_array($second)) { $second = $this->_serializeToParams($second); } // url generation "route memory" is not useful here $this->_utils->mapperDict = array(); // generate url return $this->_utils->urlFor($first, $second); } /** * Serialize any objects in the collection supporting toParam() before * passing the collection to Horde_Routes. * * @param array $collection * @param array */ protected function _serializeToParams($collection) { foreach ($collection as &$value) { if (is_object($value) && method_exists($value, 'toParam')) { $value = $value->toParam(); } } return $collection; } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/000077500000000000000000000000001205617143100224405ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/000077500000000000000000000000001205617143100235015ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/000077500000000000000000000000001205617143100256245ustar00rootroot00000000000000php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/AllTests.php000066400000000000000000000001321205617143100300640ustar00rootroot00000000000000run(); php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/FilterRunnerTest.php000066400000000000000000000062351205617143100316220ustar00rootroot00000000000000getMock('Horde_Controller_PreFilter', array('processRequest')); $filter->expects($this->once()) ->method('processRequest') ->will($this->returnValue(Horde_Controller_PreFilter::REQUEST_HANDLED)); $runner = new Horde_Controller_FilterRunner($this->_getControllerMockNeverCalled()); $runner->addPreFilter($filter); $runner->processRequest($this->getMock('Horde_Controller_Request'), new Horde_Controller_Response()); } public function testShouldUsePreFiltersInFirstInFirstOutOrder() { // The second filter should never be called because first filter returns // REQUEST_HANDLED, meaning it can handle the request. $preFilter1 = $this->getMock('Horde_Controller_PreFilter', array('processRequest')); $preFilter1->expects($this->once()) ->method('processRequest') ->will($this->returnValue(Horde_Controller_PreFilter::REQUEST_HANDLED)); $preFilter2 = $this->getMock('Horde_Controller_PreFilter', array('processRequest')); $preFilter2->expects($this->never()) ->method('processRequest'); $runner = new Horde_Controller_FilterRunner($this->_getControllerMockNeverCalled()); $runner->addPreFilter($preFilter1); $runner->addPreFilter($preFilter2); $this->_runFilterRunner($runner); } public function testShouldUsePostFiltersInFirstInLastOutOrder() { // Both filters should be called because the first filter returns // REQUEST_HANDLED, meaning it can handle the request $postFilter1 = $this->getMock('Horde_Controller_PostFilter', array('processResponse')); $postFilter1->expects($this->once()) ->method('processResponse') ->will($this->returnValue(Horde_Controller_PreFilter::REQUEST_HANDLED)); $postFilter2 = $this->getMock('Horde_Controller_PostFilter', array('processResponse')); $postFilter2->expects($this->once()) ->method('processResponse'); $controller = $this->getMock('Horde_Controller', array('processRequest')); $controller->expects($this->once()) ->method('processRequest'); $runner = new Horde_Controller_FilterRunner($controller); $runner->addPostFilter($postFilter1); $runner->addPostFilter($postFilter2); $this->_runFilterRunner($runner); } private function _getControllerMockNeverCalled() { $controller = $this->getMock('Horde_Controller', array('processRequest')); $controller->expects($this->never()) ->method('processRequest'); return $controller; } private function _runFilterRunner(Horde_Controller_FilterRunner $runner) { $response = $this->getMock('Horde_Controller_Response', array('processRequest')); $response->expects($this->never())->method('processRequest'); $runner->processRequest(new Horde_Controller_Request_Null(), $response); } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/MockRequestTest.php000066400000000000000000000047471205617143100314530ustar00rootroot00000000000000 * @license http://www.horde.org/licenses/bsd */ /** * Test the mock request handler. * * Copyright 2011-2012 Horde LLC (http://www.horde.org/) * * @category Horde * @package Controller * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/bsd */ class Horde_Controller_MockRequestTest extends Horde_Test_Case { public function testEmptyGetPath() { $r = new Horde_Controller_Request_Mock(); $this->assertNull($r->getPath()); } public function testSetPath() { $r = new Horde_Controller_Request_Mock(); $r->setPath('R'); $this->assertEquals('R', $r->getPath()); } public function testGetPathRedirectUrl() { $r = new Horde_Controller_Request_Mock( array('SERVER' => array('REDIRECT_URL' => 'RE')) ); $this->assertEquals('RE', $r->getPath()); } public function testGetPathRequestUri() { $r = new Horde_Controller_Request_Mock( array('SERVER' => array('REQUEST_URI' => 'RU')) ); $this->assertEquals('RU', $r->getPath()); } /** * @dataProvider provideGets */ public function testGetGetVars($method, $key, $value) { $r = new Horde_Controller_Request_Mock(array($key => $value)); $this->assertEquals($value, $r->{$method}()); } public function provideGets() { return array( array('getGetVars', 'GET', array('X' => 'Y')), array('getFileVars', 'files', array('X' => 'Y')), array('getServerVars', 'server', array('X' => 'Y')), array('getPostVars', 'POST', array('X' => 'Y')), array('getCookieVars', 'cookie', array('X' => 'Y')), array('getRequestVars', 'REQUEST', array('X' => 'Y')), ); } public function testGetHeaders() { $r = new Horde_Controller_Request_Mock( array('SERVER' => array('HTTP_TEST' => 'test')) ); $this->assertEquals(array('test' => 'test'), $r->getHeaders()); } public function testGetHeaderNames() { $r = new Horde_Controller_Request_Mock( array('SERVER' => array('HTTP_TEST' => 'test')) ); $this->assertEquals(array('test'), $r->getHeaderNames()); } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/StreamTest.php000066400000000000000000000007351205617143100304350ustar00rootroot00000000000000setBody($body->fopen()); $writer = new Horde_Controller_ResponseWriter_Web(); ob_start(); $writer->writeResponse($response); $this->assertEquals('BODY', ob_get_clean()); } } php-horde-controller-2.0.1/Horde_Controller-2.0.1/test/Horde/Controller/bootstrap.php000066400000000000000000000001431205617143100303500ustar00rootroot00000000000000 ../../../lib php-horde-controller-2.0.1/package.xml000066400000000000000000000330251205617143100177010ustar00rootroot00000000000000 Horde_Controller pear.horde.org Controller Horde Controller libraries The controller part of an MVC system for Horde. Mike Naberezny mnaberez mike@naberezny.com yes Chuck Hagenbuch chuck chuck@horde.org yes 2012-11-19 2.0.1 1.0.0 stable stable BSD-2-Clause * [mms] Use new Horde_Test layout. 5.3.0 1.7.0 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Injector pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Log pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Support pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 mbstring zlib 0.1.0 0.1.0 beta beta 2010-12-08 BSD-2-Clause * Initial release. 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 BSD-2-Clause * First alpha release for Horde 4. 1.0.0beta1 1.0.0 beta beta 2011-03-16 BSD-2-Clause * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 BSD-2-Clause * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 BSD-2-Clause * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 BSD-2-Clause * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-07-27 BSD-2-Clause * [gwr] Fixed the debug response writer. * [gwr] Added a mock request class. * [gwr] Allow passing the response body as stream. 1.0.2 1.0.0 stable stable 2012-04-10 BSD-2-Clause * [rla] Add license file. 2.0.0alpha1 1.0.0 alpha stable 2012-07-05 BSD-2-Clause * First alpha release for Horde 5. 2.0.0beta1 1.0.0 beta stable 2012-07-19 BSD-2-Clause * First beta release for Horde 5. 2.0.0beta2 1.0.0 beta stable 2012-08-29 BSD-2-Clause * [jan] Fix superglobals access (Bug #11277). 2.0.0 1.0.0 stable stable 2012-10-30 BSD-2-Clause * First stable release for Horde 5. 2.0.1 1.0.0 stable stable 2012-11-19 BSD-2-Clause * [mms] Use new Horde_Test layout.