package.xml 0000664 0001750 0001750 00000035153 12653672727 011327 0 ustar jan jan
Horde_Controllerpear.horde.orgControllerHorde Controller librariesThe controller part of an MVC system for Horde.Mike Nabereznymnaberezmike@naberezny.comyesChuck Hagenbuchchuckchuck@horde.orgyes2016-02-012.0.41.0.0stablestableBSD-2-Clause
* [jan] Mark PHP 7 as supported.
5.3.08.0.0alpha18.0.0alpha11.7.0Horde_Exceptionpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Injectorpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Logpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Supportpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Utilpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Testpear.horde.org2.1.03.0.0alpha13.0.0alpha1mbstringzlib0.1.00.1.0betabeta2010-12-08BSD-2-Clause
* Initial release.
1.0.0alpha11.0.0alphaalpha2011-03-08BSD-2-Clause
* First alpha release for Horde 4.
1.0.0beta11.0.0betabeta2011-03-16BSD-2-Clause
* First beta release for Horde 4.
1.0.0RC11.0.0betabeta2011-03-22BSD-2-Clause
* First release candidate for Horde 4.
1.0.0RC21.0.0betabeta2011-03-29BSD-2-Clause
* Second release candidate for Horde 4.
1.0.01.0.0stablestable2011-04-06BSD-2-Clause
* First stable release for Horde 4.
1.0.11.0.0stablestable2011-07-27BSD-2-Clause
* [gwr] Fixed the debug response writer.
* [gwr] Added a mock request class.
* [gwr] Allow passing the response body as stream.
1.0.21.0.0stablestable2012-04-10BSD-2-Clause
* [rla] Add license file.
2.0.0alpha11.0.0alphastable2012-07-05BSD-2-Clause
* First alpha release for Horde 5.
2.0.0beta11.0.0betastable2012-07-19BSD-2-Clause
* First beta release for Horde 5.
2.0.0beta21.0.0betastable2012-08-29BSD-2-Clause
* [jan] Fix superglobals access (Bug #11277).
2.0.01.0.0stablestable2012-10-30BSD-2-Clause
* First stable release for Horde 5.
2.0.11.0.0stablestable2012-11-19BSD-2-Clause
* [mms] Use new Horde_Test layout.
2.0.21.0.0stablestable2015-01-08BSD-2-Clause
* [jan] Add Composer definition.
2.0.31.0.0stablestable2015-04-28BSD-2-Clause
* [jan] Fix issues with certain locales like Turkish.
2.0.41.0.0stablestable2016-02-01BSD-2-Clause
* [jan] Mark PHP 7 as supported.
Horde_Controller-2.0.4/doc/Horde/Controller/COPYING 0000664 0001750 0001750 00000002430 12653672727 020071 0 ustar jan jan Copyright 1999-2016 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.
Horde_Controller-2.0.4/lib/Horde/Controller/Filter/Gzip.php 0000664 0001750 0001750 00000002152 12653672727 021707 0 ustar jan jan
* @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);
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Request/Http.php 0000664 0001750 0001750 00000007200 12653672727 022117 0 ustar jan jan
* @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;
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Request/Mock.php 0000664 0001750 0001750 00000003575 12653672727 022104 0 ustar jan jan
* @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[Horde_String::upper($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');
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Request/Null.php 0000664 0001750 0001750 00000001676 12653672727 022125 0 ustar jan jan
* @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()
{
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/ResponseWriter/Web.php 0000664 0001750 0001750 00000001213 12653672727 023256 0 ustar jan jan
* @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;
}
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/ResponseWriter/WebDebug.php 0000664 0001750 0001750 00000002236 12653672727 024233 0 ustar jan jan
* @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 = '
';
}
$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;
}
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/SettingsExporter/Default.php 0000664 0001750 0001750 00000001074 12653672727 024470 0 ustar jan jan
* @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)
{
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Base.php 0000664 0001750 0001750 00000010263 12653672727 020425 0 ustar jan jan
* @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;
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Exception.php 0000664 0001750 0001750 00000001277 12653672727 021516 0 ustar jan jan
* @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
{
}
Horde_Controller-2.0.4/lib/Horde/Controller/FilterCollection.php 0000664 0001750 0001750 00000000777 12653672727 023025 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/lib/Horde/Controller/FilterRunner.php 0000664 0001750 0001750 00000005364 12653672727 022200 0 ustar jan jan
* @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)
{
$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);
}
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/Null.php 0000664 0001750 0001750 00000000661 12653672727 020466 0 ustar jan jan
* @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)
{
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/PostFilter.php 0000664 0001750 0001750 00000000747 12653672727 021654 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/lib/Horde/Controller/PreFilter.php 0000664 0001750 0001750 00000001026 12653672727 021444 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/lib/Horde/Controller/Request.php 0000664 0001750 0001750 00000001302 12653672727 021175 0 ustar jan jan
* @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();
}
Horde_Controller-2.0.4/lib/Horde/Controller/RequestConfiguration.php 0000664 0001750 0001750 00000000727 12653672727 023737 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/lib/Horde/Controller/Response.php 0000664 0001750 0001750 00000002604 12653672727 021351 0 ustar jan jan
* @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;
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/ResponseWriter.php 0000664 0001750 0001750 00000000430 12653672727 022541 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
*/
interface Horde_Controller_ResponseWriter
{
public function writeResponse(Horde_Controller_Response $response);
}
Horde_Controller-2.0.4/lib/Horde/Controller/Runner.php 0000664 0001750 0001750 00000003354 12653672727 021027 0 ustar jan jan
* @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;
}
}
Horde_Controller-2.0.4/lib/Horde/Controller/SettingsExporter.php 0000664 0001750 0001750 00000001034 12653672727 023100 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/lib/Horde/Controller/UrlWriter.php 0000664 0001750 0001750 00000004413 12653672727 021512 0 ustar jan jan
* @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;
}
}
Horde_Controller-2.0.4/lib/Horde/Controller.php 0000664 0001750 0001750 00000001045 12653672727 017551 0 ustar jan jan
* @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);
}
Horde_Controller-2.0.4/test/Horde/Controller/AllTests.php 0000664 0001750 0001750 00000000132 12653672727 021511 0 ustar jan jan run();
Horde_Controller-2.0.4/test/Horde/Controller/bootstrap.php 0000664 0001750 0001750 00000000143 12653672727 021775 0 ustar jan jan getMock('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);
}
}
Horde_Controller-2.0.4/test/Horde/Controller/MockRequestTest.php 0000664 0001750 0001750 00000004747 12653672727 023100 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd
*/
/**
* Test the mock request handler.
*
* Copyright 2011-2016 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());
}
}
Horde_Controller-2.0.4/test/Horde/Controller/phpunit.xml 0000664 0001750 0001750 00000000306 12653672727 021461 0 ustar jan jan
../../../lib
Horde_Controller-2.0.4/test/Horde/Controller/StreamTest.php 0000664 0001750 0001750 00000000735 12653672727 022062 0 ustar jan jan setBody($body->fopen());
$writer = new Horde_Controller_ResponseWriter_Web();
ob_start();
$writer->writeResponse($response);
$this->assertEquals('BODY', ob_get_clean());
}
}