├── lib ├── halo_HttpResponse.php ├── halo_IHelperMapping.php ├── halo_IHelperFactory.php ├── halo_IHelperMappingAware.php ├── halo_IRegisteredHelpersAware.php ├── halo_IRegisteredHelperNamesAware.php ├── halo_IRequestHelperFactory.php ├── halo_IController.php ├── halo_mvc_multiaction_IMethodNameResolver.php ├── halo_IView.php ├── halo_IHandlerMapping.php ├── halo_view_AbstractUriView.php ├── halo_base.context.php ├── halo_IViewResolver.php ├── halo_IHandlerAdapter.php ├── halo_IViewFactory.php ├── halo_helper_SystemRequestHelperFactory.php ├── halo_view_skittle_SkittleUriView.php ├── halo_helper_skittle_SkittleHelperMappingAdapter.php ├── halo_handler_ControllerHandlerAdapter.php ├── halo_mvc_IController.php ├── halo_view_skittle_SubstrateResourceLocatorAdapter.php ├── halo_mvc_multiaction_PropertiesMethodNameResolver.php ├── halo_handler_AbstractUriHandlerMapping.php ├── halo_view_InternalResourceViewResolver.php ├── halo_view_skittle_SkittleResourceLocatorView.php ├── halo_IHandlerInterceptor.php ├── halo_mvc_multiaction_InternalPathMethodNameResolver.php ├── halo_ModelAndView.php ├── halo_handler_HandlerExecutionChain.php ├── halo_view_AbstractViewResolver.php ├── halo_DispatcherUtil.php ├── halo_view_AbstractResourceViewResolver.php ├── halo_view_skittle_SkittleViewFactory.php ├── halo_view_ViewFactoryResourceViewResolver.php ├── halo_view_skittle_AbstractSkittleView.php ├── halo_helper_UriHelperFactory.php ├── halo_helper_UriHelper.php ├── halo_handler_SimpleUriHandlerMapping.php ├── halo_mvc_multiaction_ConfigurationMethodNameResolver.php ├── halo_mvc_multiaction_ParameterMethodNameResolver.php ├── halo_HelperUtil.php ├── halo_helper_CompositeRequestHelperMapping.php ├── halo_mvc_multiaction_MultiActionController.php ├── halo_handler_AbstractHandlerMapping.php ├── halo_HttpRequest.php └── halo_Dispatcher.php ├── .gitignore ├── README └── LICENSE /lib/halo_HttpResponse.php: -------------------------------------------------------------------------------- 1 | uri = $uri; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /lib/halo_base.context.php: -------------------------------------------------------------------------------- 1 | add('halo.dispatcher', array( 4 | 'className' => 'halo_Dispatcher', 5 | 'dependencies' => array( 6 | 'halo.helpers.systemHelpers', 7 | ), 8 | )); 9 | 10 | $context->add('halo.controllerHandlerAdapter', array( 11 | 'className' => 'halo_handler_ControllerHandlerAdapter', 12 | )); 13 | 14 | $context->add('halo.helpers.systemHelpers', array( 15 | 'className' => 'halo_helper_SystemRequestHelperFactory', 16 | )); -------------------------------------------------------------------------------- /lib/halo_IViewResolver.php: -------------------------------------------------------------------------------- 1 | helperNames); 8 | } 9 | public function helper($name, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 10 | switch($name) { 11 | case 'httpRequest': 12 | return $httpRequest; 13 | break; 14 | case 'httpResponse': 15 | return $httpResponse; 16 | break; 17 | default: 18 | return null; 19 | break; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /lib/halo_view_skittle_SkittleUriView.php: -------------------------------------------------------------------------------- 1 | helperMapping = $helperMapping; 20 | } 21 | 22 | /** 23 | * Returns the helper object associated with the specified name. 24 | * @param string $name 25 | * @return object|null The helper object whose name is $name 26 | */ 27 | public function helper($name) { 28 | return $this->helperMapping->helper($name); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /lib/halo_handler_ControllerHandlerAdapter.php: -------------------------------------------------------------------------------- 1 | handleRequest($httpRequest, $httpResponse); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /lib/halo_mvc_IController.php: -------------------------------------------------------------------------------- 1 | resourceLocator = $resourceLocator; 21 | } 22 | 23 | /** 24 | * Attempt to find a target 25 | * @param $target 26 | * @param $realPath 27 | */ 28 | public function find($target, $realPath = false) { 29 | return $this->resourceLocator->find($target, $realPath); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /lib/halo_mvc_multiaction_PropertiesMethodNameResolver.php: -------------------------------------------------------------------------------- 1 | setConfiguration(new dd_configuration_MapConfiguration($mappings)); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /lib/halo_handler_AbstractUriHandlerMapping.php: -------------------------------------------------------------------------------- 1 | registerHandlers(); 18 | } 19 | 20 | /** 21 | * Register a handler 22 | * @param $uriPaths 23 | * @param $handlerName 24 | */ 25 | protected function registerHandler($uriPaths, $handlerName) { 26 | if ( ! is_array($uriPaths) ) $uriPaths = array($uriPaths); 27 | foreach ( $uriPaths as $uriPath ) { 28 | $this->registeredHandlers[$uriPath] = $handlerName; 29 | } 30 | } 31 | 32 | /** 33 | * Register handlers 34 | */ 35 | abstract protected function registerHandlers(); 36 | 37 | } -------------------------------------------------------------------------------- /lib/halo_view_InternalResourceViewResolver.php: -------------------------------------------------------------------------------- 1 | classLoader->load($this->viewClass); 26 | return new $this->viewClass($viewUri); 27 | } 28 | 29 | /** 30 | * Set view class name 31 | * @param $viewClass 32 | */ 33 | public function setViewClass($viewClass) { 34 | $this->viewClass = $viewClass; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /lib/halo_view_skittle_SkittleResourceLocatorView.php: -------------------------------------------------------------------------------- 1 | resourceLocator = $resourceLocator; 25 | } 26 | 27 | /** 28 | * Instantiate Skittle. 29 | * @param $model 30 | * @param $httpRequest 31 | * @param $httpResponse 32 | */ 33 | public function instantiate(array $model, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 34 | return new skittle_Skittle($this->resourceLocator); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /lib/halo_IHandlerInterceptor.php: -------------------------------------------------------------------------------- 1 | prefix = ($prefix !== null ? $prefix : ""); 13 | } 14 | protected function getPrefix() { 15 | return $this->prefix; 16 | } 17 | public function setSuffix($suffix) { 18 | $this->suffix = ($suffix !== null ? $suffix : ""); 19 | } 20 | protected function getSuffix() { 21 | return $this->suffix; 22 | } 23 | 24 | /** 25 | * (non-PHPdoc) 26 | * @see halo_mvc_multiaction_IMethodNameResolver::getHandlerMethodName() 27 | */ 28 | public function getHandlerMethodName(halo_HttpRequest $request){ 29 | $urlPath = $request->getRequestedUri(); 30 | $methodName = basename($urlPath, ".php"); 31 | $methodName = $this->prefix. $methodName. $this->suffix; 32 | return $methodName; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /lib/halo_ModelAndView.php: -------------------------------------------------------------------------------- 1 | view = $viewMixed; 10 | $this->isReferenced = false; 11 | } else { 12 | $this->viewName = $viewMixed; 13 | $this->isReferenced = true; 14 | } 15 | $this->model = $model === null ? array() : $model; 16 | } 17 | public function isReferenced() { 18 | return $this->isReferenced; 19 | } 20 | public function getView() { 21 | return $this->view; 22 | } 23 | public function getViewName() { 24 | return $this->viewName; 25 | } 26 | public function getModel() { 27 | return $this->model; 28 | } 29 | public function keys() { 30 | return array_keys($this->model); 31 | } 32 | public function exists($key) { 33 | return array_key_exists($key, $this->model); 34 | } 35 | public function get($key) { 36 | return $this->model[$key]; 37 | } 38 | public function set($key, $value = null) { 39 | $this->model[$key] = $value; 40 | } 41 | } -------------------------------------------------------------------------------- /lib/halo_handler_HandlerExecutionChain.php: -------------------------------------------------------------------------------- 1 | handler = $handler->getHandler(); 27 | $this->interceptors = array_merge($handler->getInterceptors(), $interceptors); 28 | } else { 29 | $this->handler = $handler; 30 | $this->interceptors = $interceptors; 31 | } 32 | } 33 | 34 | /** 35 | * Get the handler 36 | */ 37 | public function getHandler() { 38 | return $this->handler; 39 | } 40 | 41 | /** 42 | * Get the interceptors 43 | */ 44 | public function getInterceptors() { 45 | return $this->interceptors; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /lib/halo_view_AbstractViewResolver.php: -------------------------------------------------------------------------------- 1 | classLoader = new substrate_ClasspathClassLoader(); 31 | } else { 32 | $this->classLoader = $classLoader; 33 | } 34 | } 35 | 36 | /** 37 | * Set the stone order 38 | * 39 | * Used for sorting multiple stones of a given implementation. 40 | * @param $stoneOrder 41 | */ 42 | public function setStoneOrder($stoneOrder) { $this->stoneOrder = $stoneOrder; } 43 | 44 | /** 45 | * Get the stone order 46 | * 47 | * Used for sorting multiple stones of a given implementation. 48 | * @param $stoneOrder 49 | */ 50 | public function getStoneOrder() { return $this->stoneOrder; } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Dragonfly Development Inc 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Dragonfly Development Inc nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /lib/halo_DispatcherUtil.php: -------------------------------------------------------------------------------- 1 | attribute(self::$CONTEXT_KEY); 41 | } 42 | 43 | /** 44 | * Set the Substrate context for an HTTP Request. 45 | * @param halo_HttpRequest $httpRequest 46 | * @param substrate_Context $context 47 | */ 48 | public static function SET_CONTEXT(halo_HttpRequest $httpRequest, substrate_Context $context) { 49 | return $httpRequest->setAttribute(self::$CONTEXT_KEY, $context); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /lib/halo_view_AbstractResourceViewResolver.php: -------------------------------------------------------------------------------- 1 | prefix . $viewName . $this->suffix; 26 | return $this->doResolveViewUri($viewUri, $viewName, $httpRequest, $httpResponse); 27 | } 28 | 29 | /** 30 | * Continue resolving the view URI 31 | * 32 | * Expected to return instance of halo_view_IView or null if not accepted. 33 | * @param string $viewUri 34 | * @param string $viewName 35 | * @param halo_HttpRequest $httpRequest 36 | * @param halo_HttpResponse $httpResponse 37 | */ 38 | abstract public function doResolveViewUri($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse); 39 | 40 | /** 41 | * Set prefix 42 | * @param $preffix 43 | */ 44 | public function setPrefix($prefix) { 45 | $this->prefix = $prefix; 46 | } 47 | 48 | /** 49 | * Set suffix 50 | * @param $suffix 51 | */ 52 | public function setSuffix($suffix) { 53 | $this->suffix = $suffix; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /lib/halo_view_skittle_SkittleViewFactory.php: -------------------------------------------------------------------------------- 1 | substrateResourceLocatorAdapter = new halo_view_skittle_SubstrateResourceLocatorAdapter($resourceLocator); 21 | } 22 | 23 | /** 24 | * (non-PHPdoc) 25 | * @see halo_IViewFactory::supports() 26 | */ 27 | public function supports($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 28 | if ( $this->substrateResourceLocatorAdapter->find($viewUri) ) { 29 | // If our resource locator can find the view URI we know that 30 | // the view we create will be able to support it. 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | /** 37 | * (non-PHPdoc) 38 | * @see halo_IViewFactory::buildView() 39 | */ 40 | public function buildView($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 41 | return new halo_view_skittle_SkittleResourceLocatorView($viewUri, $this->substrateResourceLocatorAdapter); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /lib/halo_view_ViewFactoryResourceViewResolver.php: -------------------------------------------------------------------------------- 1 | viewFactory = $viewFactory; 23 | } 24 | 25 | /** 26 | * Resolve the view (conditionally) 27 | * 28 | * Checks the underlying halo_IViewFactory by way of supports() to see 29 | * if the view built by the factory will support the view request. If it 30 | * does support it, the factory will build a view. If not, null is returned. 31 | * 32 | * This view resolver is safe to use if view resolver chaining is desired 33 | * since it may return null in some cases. 34 | * 35 | * @param $viewUri 36 | * @param $viewName 37 | * @param $httpRequest 38 | * @param $httpResponse 39 | */ 40 | public function doResolveViewUri($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 41 | if ( $this->viewFactory->supports($viewUri, $viewName, $httpRequest, $httpResponse) ) { 42 | return $this->viewFactory->buildView($viewUri, $viewName, $httpRequest, $httpResponse); 43 | } 44 | return null; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /lib/halo_view_skittle_AbstractSkittleView.php: -------------------------------------------------------------------------------- 1 | instantiate($model, $httpRequest, $httpResponse); 21 | if ( $this->helperMapping ) { 22 | $skittle->addHelperMapping(new halo_helper_skittle_SkittleHelperMappingAdapter($this->helperMapping)); 23 | } 24 | if ( $this->helperNames ) { 25 | foreach ( $this->helperNames as $helperName ) { 26 | $skittle->addHelper($helperName); 27 | } 28 | } 29 | return $skittle->stringInc($this->uri, $model); 30 | } 31 | 32 | public function setRegisteredHelperNames(array $helperNames = null) { 33 | $this->helperNames = $helperNames; 34 | } 35 | 36 | public function setHelperMapping(halo_IHelperMapping $helperMapping) { 37 | $this->helperMapping = $helperMapping; 38 | } 39 | 40 | abstract public function instantiate(array $model, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse); 41 | 42 | } -------------------------------------------------------------------------------- /lib/halo_helper_UriHelperFactory.php: -------------------------------------------------------------------------------- 1 | uriConfiguration = $uriConfiguration; 41 | } 42 | 43 | public function setPrefix($prefix) { 44 | $this->prefix = $prefix; 45 | } 46 | 47 | public function setBaseSuffix($baseSuffix) { 48 | $this->baseSuffix = $baseSuffix; 49 | } 50 | 51 | public function setSecureBaseSuffix($secureBaseSuffix) { 52 | $this->secureBaseSuffix = $secureBaseSuffix; 53 | } 54 | 55 | public function supports($name) { 56 | return $name == 'uri'; 57 | } 58 | 59 | public function helper($name, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 60 | $uri = new halo_helper_UriHelper( 61 | $this->uriConfiguration, 62 | $httpRequest->scriptPathRoot(), 63 | true, 64 | $httpRequest->envExport() 65 | ); 66 | if ( $this->prefix ) $uri->setPrefix($this->prefix); 67 | if ( $this->baseSuffix ) $uri->setBaseSuffix($this->baseSuffix); 68 | if ( $this->secureBaseSuffix ) $uri->setSecureBaseSuffix($this->secureBaseSuffix); 69 | return $uri; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /lib/halo_helper_UriHelper.php: -------------------------------------------------------------------------------- 1 | mappings = $mappings; 36 | $this->default = $default; 37 | if ( $default !== null ) { 38 | $this->useDefault = true; 39 | } else { 40 | $this->useDefault = false; 41 | } 42 | } 43 | 44 | /** 45 | * Get the actual handler 46 | * @param $httpRequest 47 | */ 48 | protected function getHandlerInternal(halo_HttpRequest $httpRequest) { 49 | $uri = $httpRequest->requestedUri(); 50 | if ( $this->useDefault and ( $uri === null or $uri === '' ) and $this->default !== null ) { 51 | return $this->context->get($this->default); 52 | } 53 | if ( isset($this->registeredHandlers[$uri]) ) { 54 | return $this->context->get($this->registeredHandlers[$uri]); 55 | } 56 | if ( self::$LOGGER->isInfoEnabled() ) { 57 | self::$LOGGER->info('Unable to handle request for URI: [' . $uri . ']'); 58 | } 59 | return null; 60 | } 61 | 62 | /** 63 | * Register the handlers 64 | */ 65 | protected function registerHandlers() { 66 | foreach ( $this->mappings as $uri => $objectName ) { 67 | $this->registerHandler($uri, $objectName); 68 | } 69 | } 70 | 71 | } 72 | 73 | halo_handler_SimpleUriHandlerMapping::$LOGGER = dd_logging_LogFactory::get('halo_handler_SimpleUriHandlerMapping'); 74 | -------------------------------------------------------------------------------- /lib/halo_mvc_multiaction_ConfigurationMethodNameResolver.php: -------------------------------------------------------------------------------- 1 | configuration = $configuration; 29 | $this->pathMatcher = $pathMatcher; 30 | } 31 | 32 | /** 33 | * Informed that the context has started 34 | * @param $context 35 | */ 36 | public function informAboutContextStartup(substrate_Context $context) { 37 | if ( $this->pathMatcher === null ) { 38 | require_once('substrate_util_AntPathMatcher.php'); 39 | $this->pathMatcher = new substrate_util_AntPathMatcher(); 40 | } 41 | } 42 | 43 | /** 44 | * Set the configuration instances 45 | * @param $configuration 46 | */ 47 | public function setConfiguration(dd_configuration_IConfiguration $configuration) { 48 | $this->configuration = $configuration; 49 | } 50 | 51 | /** 52 | * Set the PathMatcher implementation to use for matching URL paths 53 | * against registered URL patterns. Default is halo_AntPathMatcher. 54 | * @see halo_AntPathMatcher 55 | */ 56 | public function setPathMatcher(halo_IPathMatcher $pathMatcher) { 57 | $this->pathMatcher = $pathMatcher; 58 | } 59 | 60 | /** 61 | * (non-PHPdoc) 62 | * @see halo_mvc_multiaction_IMethodNameResolver::getHandlerMethodName() 63 | */ 64 | public function getHandlerMethodName(halo_HttpRequest $request){ 65 | $uriPath = $request->getRequestedUri(); 66 | if ( $this->configuration->exists($uriPath) ) { 67 | return $this->configuration->get($uriPath); 68 | } 69 | 70 | foreach ($this->configuration->keys() as $key ) { 71 | if ($this->pathMatcher->match($key, $uriPath)) { 72 | return $this->configuration->get($key); 73 | } 74 | } 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /lib/halo_mvc_multiaction_ParameterMethodNameResolver.php: -------------------------------------------------------------------------------- 1 | paramName = $paramName; 33 | $this->methodParamNames = $methodParamNames; 34 | } 35 | 36 | /** 37 | * Set the param name 38 | * @param $paramName 39 | */ 40 | public function setParamName($paramName) { 41 | $this->paramName = $paramName; 42 | } 43 | 44 | /** 45 | * Set the param names 46 | * @param $methodParamNames 47 | */ 48 | public function setMethodParamNames(Array $methodParamNames) { 49 | $this->methodParamNames = $methodParamNames; 50 | } 51 | 52 | /** 53 | * (non-PHPdoc) 54 | * @see halo_mvc_multiaction_IMethodNameResolver::getHandlerMethodName() 55 | */ 56 | public function getHandlerMethodName(halo_HttpRequest $request) { 57 | 58 | $methodName = ''; 59 | 60 | if ($this->methodParamNames !== null) { 61 | foreach ($this->methodParamNames as $variable) { 62 | if($request->queryParam($variable) !== null){ 63 | $methodNamme = $request->queryParam($variable); 64 | break; 65 | } 66 | } 67 | } 68 | 69 | if ($methodName === null && $this->paramName !== null) { 70 | $methodName = $request->queryParam($this->paramName); 71 | } 72 | 73 | if ($methodName !== null && $methodName === "") { 74 | $methodName = null; 75 | } 76 | 77 | if ($methodName === null) { 78 | if ($this->defaultMethodName !== null) { 79 | $methodName = $this->defaultMethodName; 80 | } 81 | else { 82 | throw new Exception('Handler method, not found'); 83 | } 84 | } 85 | 86 | return $methodName; 87 | 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /lib/halo_HelperUtil.php: -------------------------------------------------------------------------------- 1 | attributeExists(self::$HELPER_MANAGER_KEY) ) { 28 | 29 | $context = halo_DispatcherUtil::GET_CONTEXT($httpRequest); 30 | 31 | $httpRequest->setAttribute( 32 | self::$HELPER_MANAGER_KEY, 33 | new halo_helper_CompositeRequestHelperMapping( 34 | $httpRequest, 35 | $httpResponse, 36 | $context->findStonesByImplementation('halo_IHelperMapping'), 37 | $context->findStonesByImplementation('halo_IHelperFactory'), 38 | $context->findStonesByImplementation('halo_IRequestHelperFactory') 39 | ) 40 | ); 41 | 42 | } 43 | 44 | return $httpRequest->attribute(self::$HELPER_MANAGER_KEY); 45 | 46 | } 47 | 48 | static public function PREPARE_VIEW(halo_IView $view, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 49 | 50 | if ( $view instanceof halo_IHelperMappingAware or $view instanceof halo_IRegisteredHelpersAware ) { 51 | 52 | $helperMapping = self::MANAGER($httpRequest, $httpResponse); 53 | 54 | if ( $view instanceof halo_IRegisteredHelpersAware ) { 55 | $view->setRegisteredHelpers(self::GET_REGISTERED_HELPERS($httpRequest, $helperMapping)); 56 | } 57 | 58 | if ( $view instanceof halo_IRegisteredHelperNamesAware ) { 59 | $view->setRegisteredHelperNames(self::GET_REGISTERED_HELPER_NAMES($httpRequest)); 60 | } 61 | 62 | if ( $view instanceof halo_IHelperMappingAware ) { 63 | $view->setHelperMapping($helperMapping); 64 | } 65 | 66 | } 67 | 68 | } 69 | 70 | public static function GET_REGISTERED_HELPER_NAMES(halo_HttpRequest $httpRequest) { 71 | return $httpRequest->attributeExists(self::$REGISTERED_HELPER_NAMES_KEY) ? 72 | $httpRequest->attribute(self::$REGISTERED_HELPER_NAMES_KEY) : array(); 73 | } 74 | 75 | public static function GET_REGISTERED_HELPERS(halo_HttpRequest $httpRequest, halo_IHelperMapping $helperMapping) { 76 | $helpers = array(); 77 | foreach ( self::GET_REGISTERED_HELPER_NAMES($httpRequest) as $helperName ) { 78 | $helpers[] = $helperMapping->helper($helperName); 79 | } 80 | return $helpers; 81 | } 82 | 83 | public static function REGISTER_HELPER_NAME(halo_HttpRequest $httpRequest, $name) { 84 | $helperNames = self::GET_REGISTERED_HELPER_NAMES($httpRequest); 85 | $helperNames[] = $name; 86 | $httpRequest->setAttribute(self::$REGISTERED_HELPER_NAMES_KEY, $helperNames); 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /lib/halo_helper_CompositeRequestHelperMapping.php: -------------------------------------------------------------------------------- 1 | httpRequest = $httpRequest; 14 | $this->httpResponse = $httpResponse; 15 | $this->mappings = $mappings; 16 | $this->factories = $factories; 17 | $this->requestFactories = $requestFactories; 18 | } 19 | 20 | public function supports($name) { 21 | 22 | if ( array_key_exists($name, $this->found) ) { 23 | return is_array($this->found[$name]) ? true : false; 24 | } 25 | 26 | // First check the mappings. 27 | foreach ( $this->mappings as $mappingIdx => $mapping ) { 28 | if ( $mapping->supports($name) ) { 29 | $this->found[$name] = array('mapping', $mappingIdx); 30 | return true; 31 | } 32 | } 33 | 34 | // Next check the factories. 35 | foreach ( $this->factories as $factoriesIdx => $factory ) { 36 | if ( $factory->supports($name) ) { 37 | $this->found[$name] = array('factory', $factoriesIdx); 38 | return true; 39 | } 40 | } 41 | 42 | // Next check the request factories. 43 | foreach ( $this->requestFactories as $requestFactoriesIdx => $requestFactory ) { 44 | if ( $requestFactory->supports($name) ) { 45 | $this->found[$name] = array('requestFactory', $requestFactoriesIdx); 46 | return true; 47 | } 48 | } 49 | 50 | return false; 51 | } 52 | 53 | public function helper($name) { 54 | 55 | if ( isset($this->instance[$name]) ) { 56 | return $this->instance[$name]; 57 | } 58 | 59 | $value = $this->internalHelper($name); 60 | 61 | if ( $value !== null ) { 62 | $this->instance[$name] = $value; 63 | } 64 | 65 | return $value; 66 | 67 | } 68 | 69 | public function internalHelper($name) { 70 | 71 | if ( ! $this->supports($name) ) { return null; } 72 | 73 | list($type, $idx) = $this->found[$name]; 74 | 75 | switch($type) { 76 | 77 | case 'mapping': 78 | $mapping = $this->mappings[$idx]; 79 | $helper = $mapping->helper($name); 80 | if ( $helper instanceof halo_helper_IRequestHelperFactory ) { 81 | // The mapper passed back a request helper factory. 82 | return $helper->helper($name, $this->httpRequest, $this->httpResponse); 83 | } 84 | if ( $helper instanceof halo_helper_IHelperFactory ) { 85 | // The mapper passed back a helper factory. 86 | return $helper->helper($name); 87 | } 88 | return $helper; 89 | break; 90 | 91 | case 'factory': 92 | $factory = $this->factories[$idx]; 93 | return $factory->helper($name); 94 | break; 95 | 96 | case 'requestFactory': 97 | $requestFactory = $this->requestFactories[$idx]; 98 | return $requestFactory->helper($name, $this->httpRequest, $this->httpResponse); 99 | break; 100 | 101 | default: 102 | return null; 103 | break; 104 | 105 | } 106 | 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /lib/halo_mvc_multiaction_MultiActionController.php: -------------------------------------------------------------------------------- 1 | methodNameResolver = $methodNameResolver; 30 | $this->delegate = $delegate === null ? $this : $delegate; 31 | } 32 | 33 | /** 34 | * (non-PHPdoc) 35 | * @see halo_mvc_IController::handleRequest() 36 | */ 37 | public function handleRequest(halo_HttpRequest $request, halo_HttpResponse $response){ 38 | $methodName = $this->methodNameResolver->getHandlerMethodName($request); 39 | return $this->invokeNamedMethod($methodName, $request, $response); 40 | } 41 | 42 | public function setDelegate($delegate) { 43 | $this->delegate = $delegate; 44 | } 45 | 46 | public function setMethodNameResolver(halo_mvc_multiaction_IMethodNameResolver $methodNameResolver) { 47 | $this->methodNameResolver = $methodNameResolver; 48 | } 49 | 50 | public function getMethodNameResolver() { 51 | return $this->methodNameResolver; 52 | } 53 | 54 | /** 55 | * Bind request parameters onto the given command stone 56 | * @param $request 57 | * @param $object 58 | */ 59 | public function bind(halo_HttpRequest $request, $object){ 60 | $reflectionClass = new ReflectionClass(get_class($object)); 61 | 62 | foreach ($request->getParameterNames() as $param) { 63 | $props = explode(".",$param); 64 | $value = $object; 65 | for ($index = 0; $index <= count($props)-2; $index++) { 66 | $prop = 'get'.ucfirst($props[$index]); 67 | if(method_exists($value , $prop)){ 68 | $value = $value->$prop(); 69 | } else { 70 | break; 71 | } 72 | } 73 | 74 | $prop = 'set'.ucfirst($props[count($props)-1]); 75 | if(method_exists($value , $prop)){ 76 | $value->$prop($request->getParameter($param)); 77 | $prop = 'get'.ucfirst($props[count($props)-1]); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * Invoke the method name on the delegate 84 | * @param string $methodName 85 | * @param halo_HttpRequest $request 86 | * @param halo_HttpResponse $response 87 | */ 88 | protected function invokeNamedMethod($methodName, halo_HttpRequest $request, halo_HttpResponse $response){ 89 | 90 | $method = new ReflectionMethod(get_class($this->delegate), $methodName); 91 | $parameters = $method->getParameters(); 92 | $params = Array(); 93 | $params[] = $request; 94 | $params[] = $response; 95 | 96 | if ($method->getNumberOfParameters() >= 3) { 97 | $commandReflectionClass = new ReflectionClass($parameters[2]->getClass()); 98 | $class = $parameters[2]->getClass()->getName(); 99 | $command = new $class; 100 | 101 | $this->bind($request, $command); 102 | $params[] = $command; 103 | } 104 | 105 | $returnValue = $method->invokeArgs($this->delegate, $params); 106 | return $returnValue; 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /lib/halo_handler_AbstractHandlerMapping.php: -------------------------------------------------------------------------------- 1 | getHandlerInternal($httpRequest); 46 | if ( $handler === null ) { 47 | $handler = $this->defaultHandler; 48 | } 49 | if ( $handler === null ) { 50 | return null; 51 | } 52 | if ( is_string($handler) ) { 53 | // 54 | } 55 | return $handler; 56 | } 57 | 58 | /** 59 | * We are Substrate context aware 60 | * @param $context 61 | */ 62 | public function informAboutContext(substrate_Context $context) { 63 | $this->context = $context; 64 | $this->initContext(); 65 | } 66 | 67 | /** 68 | * Initialize context 69 | */ 70 | protected function initContext() { 71 | $this->extendInterceptors($this->interceptors); 72 | $this->initInterceptors(); 73 | } 74 | 75 | /** 76 | * Get the adapted interceptors. 77 | */ 78 | protected function getAdaptedInterceptors() { 79 | return $this->adaptedInterceptors; 80 | } 81 | 82 | /** 83 | * Get the handler execution chain 84 | * @param mixed $handler 85 | * @return halo_handler_HandlerExecutionChain 86 | */ 87 | public function getHandlerExecutionChain(halo_HttpRequest $httpRequest) { 88 | $handler = $this->getHandler($httpRequest); 89 | if ( $handler !== null ) { 90 | // We must have found a handler, wrap it! 91 | return $this->getHandlerExecutionChainInternal($handler); 92 | } 93 | return null; 94 | } 95 | 96 | /** 97 | * Get the handler execution chain (internal) 98 | * @param mixed $handler 99 | * @return halo_handler_HandlerExecutionChain 100 | */ 101 | protected function getHandlerExecutionChainInternal($handler) { 102 | if ( $handler instanceof halo_handler_HandlerExecutionChain ) { 103 | $handler->addInterceptors($this->getAdaptedInterceptors()); 104 | return $handler; 105 | } else { 106 | return new halo_handler_HandlerExecutionChain($handler, $this->getAdaptedInterceptors()); 107 | } 108 | } 109 | 110 | /** 111 | * Set interceptors 112 | * @param $interceptors 113 | */ 114 | public function setInterceptors($interceptors) { 115 | if ( ! is_array($interceptors) ) { $interceptors = array($interceptors); } 116 | foreach ( $interceptors as $interceptor ) { 117 | $this->interceptors[] = $interceptor; 118 | } 119 | } 120 | 121 | /** 122 | * Hook to allow for additional interceptors to be registred. 123 | * @param Array 124 | */ 125 | public function extendInterceptors($interceptors) { 126 | // noop 127 | } 128 | 129 | /** 130 | * Initialize interceptors 131 | */ 132 | public function initInterceptors() { 133 | foreach ( $this->interceptors as $interceptor ) { 134 | if ( is_string($interceptor) ) { 135 | $interceptor = $this->context->get($interceptor); 136 | } 137 | $this->adaptedInterceptors[] = $this->adaptInterceptor($interceptor); 138 | } 139 | } 140 | 141 | /** 142 | * Make certain that this interceptor is something we can use 143 | * @param $interceptor 144 | */ 145 | public function adaptInterceptor($interceptor) { 146 | if ( $interceptor instanceof halo_IHandlerInterceptor ) { 147 | return $interceptor; 148 | //} elseif ( $interceptor instanceof halo_ISomethingElse ) { 149 | //return new halo_HandlerInterceptorInterfaceAdapter($interceptor); 150 | } else { 151 | throw new Exception('Interceptor of type "' . get_class($interceptor) . '" not supported.'); 152 | } 153 | } 154 | 155 | /** 156 | * Get the order of this stone 157 | */ 158 | public function getStoneOrder() { 159 | return $this->stoneOrder; 160 | } 161 | 162 | /** 163 | * Set the order of this stone 164 | * @param $stoneOrder 165 | */ 166 | public function setStoneOrder($stoneOrder) { 167 | $this->stoneOrder = $stoneOrder; 168 | } 169 | 170 | /** 171 | * Get a handler 172 | * @param $httpRequest 173 | */ 174 | abstract protected function getHandlerInternal(halo_HttpRequest $httpRequest); 175 | 176 | } -------------------------------------------------------------------------------- /lib/halo_HttpRequest.php: -------------------------------------------------------------------------------- 1 | method = $method; 111 | $this->queryParams = $queryParams; 112 | $this->postParams = $postParams; 113 | $this->fileData = $fileData; 114 | $this->env = $env; 115 | $this->body = $body; 116 | 117 | // Trim any leading slashes. 118 | $this->requestedUri = preg_replace('/^\/*/', '', $env['PATH_INFO']); 119 | 120 | if ( isset($env['REQUEST_URI']) ) { 121 | $requestUri = $env['REQUEST_URI']; 122 | $this->scriptPathRoot = $env['SCRIPT_PATH_ROOT'] = 123 | preg_replace('/\/+/', '/', $this->requestedUri ? 124 | substr($requestUri, 0, strpos($requestUri, $this->requestedUri)) : 125 | $requestUri); 126 | } else { 127 | $this->scriptPathRoot = $env['SCRIPT_PATH_ROOT'] = '/'; 128 | } 129 | 130 | // TODO: Does this actually make sense? 131 | $_SERVER = $this->env; 132 | 133 | } 134 | 135 | public function method() { return $this->method; } 136 | public function requestedUri() { return $this->requestedUri; } 137 | public function getRequestedUri() { return $this->deprecated()->requestedUri(); } 138 | public function getRequestedUrl() { return $this->deprecated()->requestedUri(); } 139 | 140 | public function scriptPathRoot() { return $this->scriptPathRoot; } 141 | 142 | public function queryParamExists($key) { return array_key_exists($key, $this->queryParams); } 143 | public function queryParam($key) { return isset($this->queryParams[$key]) ? $this->queryParams[$key] : null; } 144 | public function setQueryParam($key, $value = null) { $this->queryParams[$key] = $value; } 145 | public function unsetQueryParam($key) { unset($this->queryParams[$key]); } 146 | public function queryParams() { return $this->queryParams; } 147 | public function getQueryParams() { return $this->deprecated()->queryParams(); } 148 | 149 | public function postParamExists($key) { return array_key_exists($key, $this->postParams); } 150 | public function postParam($key) { return isset($this->postParams[$key]) ? $this->postParams[$key] : null; } 151 | public function setPostParam($key, $value = null) { $this->postParams[$key] = $value; } 152 | public function unsetPostParam($key) { unset($this->postParams[$key]); } 153 | public function postParams() { return $this->postParams; } 154 | public function getPostParams() { return $this->deprecated()->postParams(); } 155 | 156 | public function attributeExists($key) { return array_key_exists($key, $this->attributes); } 157 | public function attribute($key) { return isset($this->attributes[$key]) ? $this->attributes[$key] : null; } 158 | public function setAttribute($key, $value = null) { $this->attributes[$key] = $value; } 159 | public function unsetAttribute($key) { unset($this->attributes[$key]); } 160 | public function attributes() { return $this->attributes; } 161 | public function attributeKeys() { return array_keys($this->attributes); } 162 | public function getAttributes() { return $this->deprecated()->attributes(); } 163 | public function getAttributeKeys() { return $this->deprecated()->attributeKeys(); } 164 | 165 | public function uriParamExists($key) { return array_key_exists($key, $this->uriParams); } 166 | public function uriParam($key) { return isset($this->uriParams[$key]) ? $this->uriParams[$key] : null; } 167 | public function setUriParam($key, $value = null) { $this->uriParams[$key] = $value; } 168 | public function unsetUriParam($key) { unset($this->uriParams[$key]); } 169 | public function uriParams() { return $this->uriParams; } 170 | public function uriParamNames() { return array_keys($this->uriParams); } 171 | 172 | public function urlParamExists($key) { return $this->deprecated()->uriParamExists($key); } 173 | public function urlParam($key) { $this->deprecated()->uriParam($key); } 174 | public function setUrlParam($key, $value = null) { $this->deprecated()->setUriParam($key, $value); } 175 | public function unsetUrlParam($key) { $this->deprecated()->unsetUriParam($key); } 176 | public function urlParams() { $this->deprecated()->uriParams(); } 177 | public function getUrlParams() { $this->deprecated()->uriParams(); } 178 | public function urlParamNames() { $this->deprecated()->uriParamNames($key); } 179 | public function getUrlParamNames() { $this->deprecated()->uriParamNames($key); } 180 | 181 | public function fileParams() { return $this->fileParams; } 182 | public function fileParam($key, $secondKey = null) { 183 | if ( array_key_exists($key, $this->fileData) ) { 184 | $value = $this->fileData[$key]; 185 | if ( $secondKey === null ) { return $value; } 186 | elseif ( array_key_exists($secondKey, $value) ) { return $value[$secondKey]; } 187 | } 188 | return null; 189 | } 190 | 191 | public function envExists($key) { return array_key_exists($key, $this->env); } 192 | public function envKeys() { return array_keys($this->env); } 193 | public function env($key) { return isset($this->env[$key]) ? $this->env[$key] : null; } 194 | public function envExport() { return $this->env; } 195 | 196 | public function body() { return $this->body; } 197 | 198 | public function getFileParams() { return $this->deprecated()->fileParams(); } 199 | public function getFileParam($key, $secondKey = null) { return $this->deprecated()->fileParam($key, $secondKey); } 200 | 201 | protected function deprecated() { 202 | if ( self::$LOGGER->isWarnEnabled() ) { 203 | $back = debug_backtrace(); 204 | self::$LOGGER->warn('Deprecated call to ' . $back[1]['class'] . '::' . $back[1]['function'] . ', ' . $back[1]['file'] . ':' . $back[1]['line']); 205 | } 206 | return $this; 207 | } 208 | 209 | } 210 | 211 | halo_HttpRequest::$LOGGER = dd_logging_LogFactory::get('halo_HttpRequest'); 212 | 213 | -------------------------------------------------------------------------------- /lib/halo_Dispatcher.php: -------------------------------------------------------------------------------- 1 | context = $context; 42 | 43 | // Find all handler mappings. 44 | $this->handlerMappings = substrate_stones_OrderedUtil::SORT( 45 | $context->findStonesByImplementation('halo_IHandlerMapping') 46 | ); 47 | 48 | // Find all handler adapters. 49 | $this->handlerAdapters = substrate_stones_OrderedUtil::SORT( 50 | $context->findStonesByImplementation('halo_IHandlerAdapter') 51 | ); 52 | 53 | // Find all view resolvers. 54 | $this->viewResolvers = $context->findStonesByImplementation( 55 | 'halo_IViewResolver' 56 | ); 57 | 58 | } 59 | 60 | /** 61 | * Catch fatal errors 62 | * @param $buffer 63 | * @return buffer 64 | */ 65 | public function doServiceErrorHandler($buffer) { 66 | $error = error_get_last(); 67 | if ( $error !== null and $error['type'] == 1 ) { 68 | if ( self::$LOGGER->isFatalEnabled() ) { 69 | self::$LOGGER->fatal('SOMETHING MAJOR HAPPENED'); 70 | self::$LOGGER->fatal($error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line']); 71 | } 72 | $buffer = $this->triggerInternalServerError(); 73 | } 74 | return $buffer; 75 | } 76 | 77 | protected function triggerInternalServerError() { 78 | header('HTTP/1.1 500 Internal Server Error'); 79 | $content = ''; 80 | $content .= '500 Internal Server Error
'; 81 | $content .= 'An internal error has occurred.'; 82 | return $content; 83 | } 84 | 85 | /** 86 | * Handle internal server error 87 | */ 88 | protected function handleInternalServerError() { 89 | // TODO: Can we find a way to customize 500 error? 90 | echo $this->triggerInternalServerError(); 91 | } 92 | 93 | /** 94 | * Main entry point. 95 | * @param halo_HttpRequest $httpRequest 96 | * @param halo_HttpResponse $httpResponse 97 | */ 98 | public function doService(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 99 | 100 | $didCatchException = false; 101 | $exception = null; 102 | 103 | ob_start(array($this, 'doServiceErrorHandler')); 104 | 105 | try { 106 | $this->doServiceInternal($httpRequest, $httpResponse); 107 | } catch (Exception $e) { 108 | $didCatchException = true; 109 | $exception = $e; 110 | } 111 | 112 | if ( $didCatchException ) { 113 | if ( self::$LOGGER->isErrorEnabled() ) { 114 | self::$LOGGER->error('Something pretty bad happened.'); 115 | self::$LOGGER->error('Caught exception: ' . get_class($exception) . ' [code:' . $exception->getCode() . ']'); 116 | self::$LOGGER->error($exception->getMessage()); 117 | } 118 | while (ob_get_level()) { 119 | ob_end_clean(); 120 | } 121 | $this->handleInternalServerError(); 122 | } else { 123 | // Everything is all good here. 124 | ob_flush(); 125 | } 126 | } 127 | 128 | /** 129 | * This is a safe internal method for handling the service 130 | * @param halo_HttpRequest $httpRequest 131 | * @param halo_HttpResponse $httpResponse 132 | */ 133 | protected function doServiceInternal(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 134 | 135 | // Let's get this party started! 136 | halo_DispatcherUtil::SET_CONTEXT($httpRequest, $this->context); 137 | 138 | $handlerExecutionChain = $this->getHandlerExecutionChain($httpRequest); 139 | 140 | if ( $handlerExecutionChain === null or $handlerExecutionChain->getHandler() == null ) { 141 | throw new Exception('Unable to find a handler for request.'); 142 | } 143 | 144 | $handler = $handlerExecutionChain->getHandler(); 145 | $interceptorIdx = -1; 146 | foreach ( $handlerExecutionChain->getInterceptors() as $interceptor ) { 147 | $interceptorIdx++; 148 | if ( ! $interceptor->preHandle($httpRequest, $httpResponse, $handler) ) { 149 | $this->triggerAfterCompletion($handlerExecutionChain, $interceptorIdx, $httpRequest, $httpResponse); 150 | return; 151 | } 152 | } 153 | 154 | $handlerAdapter = $this->getHandlerAdapter($handler); 155 | 156 | if ( $handlerAdapter === null ) { 157 | throw new Exception('Unable to find a handler adapter for handler.'); 158 | } 159 | 160 | $modelAndView = $handlerAdapter->handle($httpRequest, $httpResponse, $handler); 161 | 162 | foreach ( $handlerExecutionChain->getInterceptors() as $interceptor ) { 163 | $interceptor->postHandle($httpRequest, $httpResponse, $handler, $modelAndView); 164 | } 165 | 166 | $this->render($modelAndView, $httpRequest, $httpResponse); 167 | 168 | $this->triggerAfterCompletion($handlerExecutionChain, $interceptorIdx, $httpRequest, $httpResponse); 169 | 170 | } 171 | 172 | /** 173 | * Get handler execution change for the request 174 | * 175 | * Checks all handler mappings to see if at least one can handle the 176 | * request (likely by way of examining the request URI). 177 | * 178 | * @param halo_HttpRequest $httpRequest 179 | * @return halo_handler_HandlerExecutionChain 180 | */ 181 | public function getHandlerExecutionChain(halo_HttpRequest $httpRequest) { 182 | foreach ( $this->handlerMappings as $handlerMapping ) { 183 | $handler = $handlerMapping->getHandlerExecutionChain($httpRequest); 184 | if ( $handler !== null ) { 185 | return $handler; 186 | } 187 | } 188 | return null; 189 | } 190 | 191 | /** 192 | * Find something that can handle this handler 193 | * @param $handler 194 | */ 195 | public function getHandlerAdapter($handler) { 196 | foreach ( $this->handlerAdapters as $handlerAdapter ) { 197 | if ( $handlerAdapter->supports($handler) ) { 198 | return $handlerAdapter; 199 | } 200 | } 201 | return null; 202 | } 203 | 204 | /** 205 | * Render 206 | * @param halo_ModelAndView $modelAndView 207 | * @param halo_HttpRequest $httpRequest 208 | * @param halo_HttpResponse $httpResponse 209 | */ 210 | public function render(halo_ModelAndView $modelAndView = null, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 211 | if ( $modelAndView === null ) return; 212 | $view = null; 213 | if ( $modelAndView->isReferenced() ) { 214 | $view = $this->resolveViewName($modelAndView->getViewName(), $httpRequest, $httpResponse); 215 | } else { 216 | $view = $modelAndView->getView(); 217 | } 218 | if ($view and is_object($view) and $view instanceof halo_IView ) { 219 | halo_HelperUtil::PREPARE_VIEW($view, $httpRequest, $httpResponse); 220 | $viewContent = $view->render($modelAndView->getModel(), $httpRequest, $httpResponse); 221 | print $viewContent; 222 | } 223 | } 224 | 225 | /** 226 | * Resolve a view name 227 | * @param $viewName 228 | * @param $httpRequest 229 | * @param $httpResponse 230 | */ 231 | public function resolveViewName($viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) { 232 | foreach ( $this->viewResolvers as $viewResolver ) { 233 | $view = $viewResolver->resolve($viewName, $httpRequest, $httpResponse); 234 | if ( $view !== null ) return $view; 235 | } 236 | throw new Exception('Could not resolve view name "' . $viewName . '"'); 237 | } 238 | 239 | /** 240 | * Trigger after completion (FINALLY) 241 | * @param $handlerExecutionChain 242 | * @param $interceptorIdx 243 | * @param $httpRequest 244 | * @param $httpResponse 245 | * @param $exception 246 | */ 247 | public function triggerAfterCompletion(halo_handler_HandlerExecutionChain $handlerExecutionChain, $interceptorIdx, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse, $exception = null) { 248 | if ( $handlerExecutionChain !== null ) { 249 | $interceptors = $handlerExecutionChain->getInterceptors(); 250 | for ( $i = $interceptorIdx; $i >= 0; $i-- ) { 251 | $interceptor = $interceptors[$i]; 252 | try { 253 | $interceptor->afterCompletion($httpRequest, $httpResponse, $handlerExecutionChain->getHandler(), $exception); 254 | } catch (Exception $e) { 255 | $this->logger->info('IHandlerInterceptor.afterCompletion() threw exception.'); 256 | } 257 | } 258 | } 259 | } 260 | 261 | } 262 | 263 | halo_Dispatcher::$LOGGER = dd_logging_LogFactory::get('halo_Dispatcher'); 264 | --------------------------------------------------------------------------------