[Beeframework-svn] SF.net SVN: beeframework:[255] trunk
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2014-10-09 11:59:38
|
Revision: 255 http://sourceforge.net/p/beeframework/code/255 Author: m_plomer Date: 2014-10-09 11:59:29 +0000 (Thu, 09 Oct 2014) Log Message: ----------- - implemented request-based filtering of interceptors in AntPathHandlerMapping - omissions from previous namespace refactoring Modified Paths: -------------- trunk/framework/Bee/Annotations/Utils.php trunk/framework/Bee/MVC/HandlerMapping/AbstractHandlerMapping.php trunk/framework/Bee/MVC/HandlerMapping/AntPathHandlerMapping.php trunk/framework/Bee/Persistence/Pdo/IResultSetExtractor.php trunk/framework/Bee/Persistence/Pdo/IStatementCallback.php trunk/framework/Bee/Persistence/Pdo/RowMapper/SingleColumn.php trunk/framework/Bee/Persistence/Pdo/Template.php trunk/framework/Bee/Security/Acls/Pdo/AclService.php trunk/framework/Bee/Security/Annotations/Secured.php trunk/framework/Bee/Security/Annotations/SecuredMethodDefinitionSource.php trunk/framework/Bee/Security/Namespace/GlobalMethodSecurityBeanDefinitionParser.php trunk/framework/Bee/Security/Provider/DaoAuthentication.php trunk/tests/Bee/Annotations/UtilsTest.php Added Paths: ----------- trunk/framework/Bee/Persistence/Exception/DataAccessException.php Removed Paths: ------------- trunk/framework/Bee/Persistence/Exception/DataAccess.php Modified: trunk/framework/Bee/Annotations/Utils.php =================================================================== --- trunk/framework/Bee/Annotations/Utils.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Annotations/Utils.php 2014-10-09 11:59:29 UTC (rev 255) @@ -1,6 +1,7 @@ <?php +namespace Bee\Annotations; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - use Addendum\ReflectionAnnotatedClass; use Addendum\ReflectionAnnotatedMethod; +use ReflectionMethod; + /** * User: mp * Date: Feb 19, 2010 * Time: 7:14:44 PM */ +class Utils { -class Bee_Annotations_Utils { - /** * Get a single {@link Annotation} of <code>annotationType</code> from the * supplied {@link Method}, traversing its super methods if no annotation @@ -33,7 +34,7 @@ * this explicitly. Tge * @param ReflectionMethod $method * @param $annotationClassName - * @return the annotation found, or <code>null</code> if none found + * @return mixed the annotation found, or <code>null</code> if none found */ public static function findAnnotation(ReflectionMethod $method, $annotationClassName) { $annotatedMethod = self::getReflectionAnnotatedMethodIfNecessary($method); Modified: trunk/framework/Bee/MVC/HandlerMapping/AbstractHandlerMapping.php =================================================================== --- trunk/framework/Bee/MVC/HandlerMapping/AbstractHandlerMapping.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/MVC/HandlerMapping/AbstractHandlerMapping.php 2014-10-09 11:59:29 UTC (rev 255) @@ -19,6 +19,7 @@ use Bee\IContext; use Bee\MVC\HandlerExecutionChain; use Bee\MVC\IController; +use Bee\MVC\IHandlerInterceptor; use Bee\MVC\IHandlerMapping; use Bee\MVC\IHttpRequest; use Exception; @@ -48,7 +49,7 @@ /** * Enter description here... * - * @var \Bee\MVC\IHandlerInterceptor[] + * @var IHandlerInterceptor[] */ private $interceptors = array(); @@ -81,7 +82,7 @@ /** * Enter description here... * - * @param \Bee\MVC\IHandlerInterceptor[] $interceptors + * @param IHandlerInterceptor[] $interceptors */ public function setInterceptors(array $interceptors) { $this->interceptors = $interceptors; @@ -90,7 +91,7 @@ /** * Enter description here... * - * @return \Bee\MVC\IHandlerInterceptor[] + * @return IHandlerInterceptor[] */ public function getInterceptors() { return $this->interceptors; @@ -112,11 +113,20 @@ } $hec = new HandlerExecutionChain($handlerBean); - $hec->addInterceptors($this->interceptors); + $hec->addInterceptors($this->filterInterceptors($request)); return $hec; } /** + * Default implementation returns unfiltered view of the interceptors collection. + * @param IHttpRequest $request + * @return IHandlerInterceptor[] + */ + protected function filterInterceptors(IHttpRequest $request) { + return $this->interceptors; + } + + /** * Resolves the actual controller bean name (may also return a controller instance directly) * @param IHttpRequest $request * @return mixed Modified: trunk/framework/Bee/MVC/HandlerMapping/AntPathHandlerMapping.php =================================================================== --- trunk/framework/Bee/MVC/HandlerMapping/AntPathHandlerMapping.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/MVC/HandlerMapping/AntPathHandlerMapping.php 2014-10-09 11:59:29 UTC (rev 255) @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\MVC\IHandlerInterceptor; use Bee\MVC\IHttpRequest; use Bee\Utils\AntPathMatcher; use Bee\Utils\IPathMatcher; @@ -50,7 +51,7 @@ * @return IPathMatcher */ public function getPathMatcher() { - return $this->pathMatcher; + return $this->pathMatcher ?: ($this->pathMatcher = new AntPathMatcher()); } /** @@ -65,8 +66,7 @@ * @return mixed */ protected function getControllerBeanName(IHttpRequest $request) { - $pathInfo = $request->getPathInfo(); - return $this->getElementByMatchingArrayKey($pathInfo, $this->handlerMappings, $this->getDefaultControllerBeanName()); + return $this->getElementByMatchingArrayKey($request->getPathInfo(), $this->handlerMappings, $this->getDefaultControllerBeanName()); } /** @@ -82,7 +82,7 @@ // shortcut for direct path matches $result = $array[$path]; } else { - $matcher = is_null($this->pathMatcher) ? new AntPathMatcher() : $this->pathMatcher; + $matcher = $this->getPathMatcher(); foreach($array as $mapping => $element) { if($matcher->match($mapping, $path)) { // if(($matcher->isPattern($mapping) && $matcher->match($mapping, $pathInfo)) || Strings::startsWith($pathInfo, $mapping)) { @@ -94,4 +94,20 @@ } return $result; } + + /** + * @param IHttpRequest $request + * @return IHandlerInterceptor[] + */ + protected function filterInterceptors(IHttpRequest $request) { + $result = array(); + $pathInfo = $request->getPathInfo(); + $matcher = $this->getPathMatcher(); + foreach($this->getInterceptors() as $key => $interceptor) { + if(!is_string($key) || $key == $pathInfo || $matcher->match($key, $pathInfo)) { + $result[] = $interceptor; + } + } + return $result; + } } \ No newline at end of file Deleted: trunk/framework/Bee/Persistence/Exception/DataAccess.php =================================================================== --- trunk/framework/Bee/Persistence/Exception/DataAccess.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Persistence/Exception/DataAccess.php 2014-10-09 11:59:29 UTC (rev 255) @@ -1,22 +0,0 @@ -<?php -/* - * Copyright 2008-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -class Bee_Persistence_Exception_DataAccess extends Exception { - public function __construct($message, Exception $cause = null) { - parent::__construct($message, 0, $cause); - } -} Copied: trunk/framework/Bee/Persistence/Exception/DataAccessException.php (from rev 251, trunk/framework/Bee/Persistence/Exception/DataAccess.php) =================================================================== --- trunk/framework/Bee/Persistence/Exception/DataAccessException.php (rev 0) +++ trunk/framework/Bee/Persistence/Exception/DataAccessException.php 2014-10-09 11:59:29 UTC (rev 255) @@ -0,0 +1,25 @@ +<?php +namespace Bee\Persistence\Exception; +/* + * Copyright 2008-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use Exception; + +class DataAccessException extends Exception { + public function __construct($message, Exception $cause = null) { + parent::__construct($message, 0, $cause); + } +} Modified: trunk/framework/Bee/Persistence/Pdo/IResultSetExtractor.php =================================================================== --- trunk/framework/Bee/Persistence/Pdo/IResultSetExtractor.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Persistence/Pdo/IResultSetExtractor.php 2014-10-09 11:59:29 UTC (rev 255) @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\Persistence\Exception\DataAccessException; /** * User: mp @@ -30,9 +31,7 @@ * (the extractor will typically be stateful in the latter case). * @throws PDOException if a PDOException is encountered getting column * values or navigating (that is, there's no need to catch PDOException) - * @throws Bee_Persistence_Exception_DataAccess in case of custom exceptions + * @throws DataAccessException in case of custom exceptions */ public function extractData(PDOStatement $rs); - -} -?> \ No newline at end of file +} \ No newline at end of file Modified: trunk/framework/Bee/Persistence/Pdo/IStatementCallback.php =================================================================== --- trunk/framework/Bee/Persistence/Pdo/IStatementCallback.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Persistence/Pdo/IStatementCallback.php 2014-10-09 11:59:29 UTC (rev 255) @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\Persistence\Exception\DataAccessException; /** * User: mp @@ -44,9 +45,7 @@ * @param ps active JDBC PreparedStatement * @return a result object, or <code>null</code> if none * @throws PDOException - * @throws Bee_Persistence_Exception_DataAccess in case of custom exceptions + * @throws DataAccessException in case of custom exceptions */ public function doInPreparedStatement(PDOStatement $ps); - -} -?> \ No newline at end of file +} \ No newline at end of file Modified: trunk/framework/Bee/Persistence/Pdo/RowMapper/SingleColumn.php =================================================================== --- trunk/framework/Bee/Persistence/Pdo/RowMapper/SingleColumn.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Persistence/Pdo/RowMapper/SingleColumn.php 2014-10-09 11:59:29 UTC (rev 255) @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\Persistence\Exception\DataAccessException; /** * User: mp @@ -26,9 +27,8 @@ public function mapRow(PDOStatement $rs, $rowNum) { $colCount = $rs->columnCount(); if($colCount != 1) { - throw new Bee_Persistence_Exception_DataAccess('Incorrect column count, is ' . $colCount . ', should be 1'); + throw new DataAccessException('Incorrect column count, is ' . $colCount . ', should be 1'); } return $rs->fetchColumn(); } -} -?> +} \ No newline at end of file Modified: trunk/framework/Bee/Persistence/Pdo/Template.php =================================================================== --- trunk/framework/Bee/Persistence/Pdo/Template.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Persistence/Pdo/Template.php 2014-10-09 11:59:29 UTC (rev 255) @@ -15,6 +15,7 @@ * limitations under the License. */ use Bee\Framework; +use Bee\Persistence\Exception\DataAccessException; use Bee\Utils\Assert; /** @@ -86,7 +87,7 @@ new Bee_Persistence_Pdo_RowMapper_SingleColumn())); $count = count($results); if($count != 1) { - throw new Bee_Persistence_Exception_DataAccess('Incorrect result size, is ' .$count. ', expected 1'); + throw new DataAccessException('Incorrect result size, is ' .$count. ', expected 1'); } return $results[0]; } @@ -100,7 +101,7 @@ * @param pss object that knows how to set values on the prepared statement. * If this is null, the SQL will be assumed to contain no bind parameters. * @param rse object that will extract results. - * @return an arbitrary result object, as returned by the ResultSetExtractor + * @return mixed an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem */ public function query(Bee_Persistence_Pdo_IStatementCreator $psc, Bee_Persistence_Pdo_IStatementSetter $pss, @@ -158,7 +159,7 @@ // Release Connection early, to avoid potential connection pool deadlock // in the case when the exception translator hasn't been initialized yet. // $sql = $this->getSql($psc); - throw new Bee_Persistence_Exception_DataAccess('Bee_Persistence_Pdo_Template caught an exception', $ex); + throw new DataAccessException('Bee_Persistence_Pdo_Template caught an exception', $ex); // throw getExceptionTranslator().translate("PreparedStatementCallback", sql, ex); } } Modified: trunk/framework/Bee/Security/Acls/Pdo/AclService.php =================================================================== --- trunk/framework/Bee/Security/Acls/Pdo/AclService.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Security/Acls/Pdo/AclService.php 2014-10-09 11:59:29 UTC (rev 255) @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\Persistence\Exception\DataAccessException; use Bee\Utils\Assert; /** @@ -211,7 +212,7 @@ try { return $this->pdoTemplate->queryScalarBySqlStringAndArgsArray(self::SELECT_OBJECT_IDENTITY_PRIMARY_KEY, array($oid->getType(), $oid->getIdentifier())); - } catch (Bee_Persistence_Exception_DataAccess $notFound) { + } catch (DataAccessException $notFound) { return null; } } @@ -419,5 +420,4 @@ return count($this->acl->getEntries()); } -} -?> +} \ No newline at end of file Modified: trunk/framework/Bee/Security/Annotations/Secured.php =================================================================== --- trunk/framework/Bee/Security/Annotations/Secured.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Security/Annotations/Secured.php 2014-10-09 11:59:29 UTC (rev 255) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Annotations; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Addendum\Annotation; /** * Created by IntelliJ IDEA. @@ -23,5 +25,4 @@ * To change this template use File | Settings | File Templates. */ -class Bee_Security_Annotations_Secured extends Annotation {} -?> +class Secured extends Annotation {} Modified: trunk/framework/Bee/Security/Annotations/SecuredMethodDefinitionSource.php =================================================================== --- trunk/framework/Bee/Security/Annotations/SecuredMethodDefinitionSource.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Security/Annotations/SecuredMethodDefinitionSource.php 2014-10-09 11:59:29 UTC (rev 255) @@ -1,6 +1,7 @@ <?php +namespace Bee\Security\Annotations; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Addendum\Annotation; use Addendum\ReflectionAnnotatedClass; +use Bee\Annotations\Utils; +use Bee_Security_ConfigAttributeDefinition; +use Bee_Security_Intercept_AbstractFallbackMethodDefinitionSource; +use ReflectionClass; +use ReflectionMethod; /** * Created by IntelliJ IDEA. @@ -24,9 +31,9 @@ * To change this template use File | Settings | File Templates. */ -class Bee_Security_Annotations_SecuredMethodDefinitionSource extends Bee_Security_Intercept_AbstractFallbackMethodDefinitionSource { +class SecuredMethodDefinitionSource extends Bee_Security_Intercept_AbstractFallbackMethodDefinitionSource { - const SECURED_ANNOTATION_CLASS_NAME = 'Bee_Security_Annotations_Secured'; + const SECURED_ANNOTATION_CLASS_NAME = 'Bee\Security\Annotations\Secured'; /** * @access protected @@ -51,7 +58,7 @@ * @return Bee_Security_ConfigAttributeDefinition */ protected function findAttributesForMethod(ReflectionMethod $method, $targetClassOrClassName) { - return $this->processAnnotation(Bee_Annotations_Utils::findAnnotation($method, self::SECURED_ANNOTATION_CLASS_NAME)); + return $this->processAnnotation(Utils::findAnnotation($method, self::SECURED_ANNOTATION_CLASS_NAME)); } /** @@ -67,10 +74,9 @@ * @return Bee_Security_ConfigAttributeDefinition */ private function processAnnotation(Annotation $a) { - if ($a == null || !($a instanceof Bee_Security_Annotations_Secured)) { + if ($a == null || !($a instanceof Secured)) { return null; } return new Bee_Security_ConfigAttributeDefinition($a->value); } } -?> Modified: trunk/framework/Bee/Security/Namespace/GlobalMethodSecurityBeanDefinitionParser.php =================================================================== --- trunk/framework/Bee/Security/Namespace/GlobalMethodSecurityBeanDefinitionParser.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Security/Namespace/GlobalMethodSecurityBeanDefinitionParser.php 2014-10-09 11:59:29 UTC (rev 255) @@ -33,7 +33,7 @@ class Bee_Security_Namespace_GlobalMethodSecurityBeanDefinitionParser implements IBeanDefinitionParser { - const SECURED_METHOD_DEFINITION_SOURCE_CLASS = 'Bee_Security_Annotations_SecuredMethodDefinitionSource'; + const SECURED_METHOD_DEFINITION_SOURCE_CLASS = 'Bee\Security\Annotations\SecuredMethodDefinitionSource'; const ATT_USE_SECURED = 'secured-annotations'; const ATT_ACCESS_MGR = "access-decision-manager-ref"; Modified: trunk/framework/Bee/Security/Provider/DaoAuthentication.php =================================================================== --- trunk/framework/Bee/Security/Provider/DaoAuthentication.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/framework/Bee/Security/Provider/DaoAuthentication.php 2014-10-09 11:59:29 UTC (rev 255) @@ -15,6 +15,8 @@ * limitations under the License. */ +use Bee\Persistence\Exception\DataAccessException; + class Bee_Security_Provider_DaoAuthentication extends Bee_Security_Provider_AbstractUserDetailsAuthentication { /** @@ -69,7 +71,7 @@ try { $loadedUser = $this->getUserDetailsService()->loadUserByUsername($username); - } catch (Bee_Persistence_Exception_DataAccess $repositoryProblem) { + } catch (DataAccessException $repositoryProblem) { throw new Bee_Security_Exception_Authentication($repositoryProblem->getMessage(), null, $repositoryProblem); } Modified: trunk/tests/Bee/Annotations/UtilsTest.php =================================================================== --- trunk/tests/Bee/Annotations/UtilsTest.php 2014-10-09 02:29:34 UTC (rev 254) +++ trunk/tests/Bee/Annotations/UtilsTest.php 2014-10-09 11:59:29 UTC (rev 255) @@ -1,6 +1,7 @@ <?php +namespace Bee\Annotations; /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +16,7 @@ * limitations under the License. */ use Addendum\Annotation; +use ReflectionClass; /** * User: mp @@ -22,46 +24,46 @@ * Time: 14:49 */ -class Bee_Annotations_UtilsTest /*extends PHPUnit_Framework_TestCase*/ { +class UtilsTest /*extends PHPUnit_Framework_TestCase*/ { public function testFindInheritedAnnotation() { - $class = new ReflectionClass('Bee_Annotations_UtilsTestChildAnnotatedClass'); + $class = new ReflectionClass('UtilsTestChildAnnotatedClass'); $method = $class->getMethod('testMethod'); - $annot = Bee_Annotations_Utils::findAnnotation($method, 'Bee_Annotations_UtilsTestAnnotation1'); + $annot = Utils::findAnnotation($method, 'UtilsTestAnnotation1'); -// $this->assertNotNull($annot, 'Annotation Bee_Annotations_UtilsTestAnnotation1 not found on Bee_Annotations_UtilsTestChildAnnotatedClass::testMethod()'); +// $this->assertNotNull($annot, 'Annotation UtilsTestAnnotation1 not found on UtilsTestChildAnnotatedClass::testMethod()'); // // $this->assertEquals('parentAnnotation', $annot->value); } } -class Bee_Annotations_UtilsTestAnnotation1 extends Annotation { +class UtilsTestAnnotation1 extends Annotation { public $value; } -class Bee_Annotations_UtilsTestAnnotation2 extends Annotation { +class UtilsTestAnnotation2 extends Annotation { public $value; } -class Bee_Annotations_UtilsTestParentAnnotatedClass { +class UtilsTestParentAnnotatedClass { /** * @return void * - * @Bee_Annotations_UtilsTestAnnotation1(value = "parentAnnotation") + * @UtilsTestAnnotation1(value = "parentAnnotation") */ public function testMethod() { } } -class Bee_Annotations_UtilsTestChildAnnotatedClass extends Bee_Annotations_UtilsTestParentAnnotatedClass { +class UtilsTestChildAnnotatedClass extends UtilsTestParentAnnotatedClass { /** * @return void * - * @Bee_Annotations_UtilsTestAnnotation2(value = "childAnnotation") + * @UtilsTestAnnotation2(value = "childAnnotation") */ public function testMethod() { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |