[Beeframework-svn] SF.net SVN: beeframework:[245] trunk
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2014-10-08 12:21:05
|
Revision: 245 http://sourceforge.net/p/beeframework/code/245 Author: m_plomer Date: 2014-10-08 12:21:00 +0000 (Wed, 08 Oct 2014) Log Message: ----------- fixed AntPathToRegexTransformer and RegexMappingInvocationResolver behavior on trailing /** patterns Modified Paths: -------------- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php trunk/framework/Bee/Utils/AntPathToRegexTransformer.php trunk/tests/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolverTest.php trunk/tests/Bee/Utils/AntPathDataProvider.php Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2014-10-08 09:12:00 UTC (rev 244) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2014-10-08 12:21:00 UTC (rev 245) @@ -1,5 +1,6 @@ <?php namespace Bee\MVC\Controller\Multiaction\HandlerMethodInvocator; + /* * Copyright 2008-2014 the original author or authors. * @@ -82,12 +83,11 @@ */ public function getInvocationDefinition(Bee_MVC_IHttpRequest $request) { $pathInfo = $request->getPathInfo(); + /** @var MethodInvocation[] $matchingPatterns */ $matchingPatterns = array(); foreach ($this->mappedMethods as $regex => $invocInfo) { - $matches = array(); if (preg_match($regex, $pathInfo, $matches) === 1) { $invocInfo->setParamValues($matches); -// return $invocInfo; $matchingPatterns[$regex] = $invocInfo; } } @@ -97,32 +97,31 @@ } uksort($matchingPatterns, function ($patternA, $patternB) use ($matchingPatterns, $pathInfo) { - /** @var MethodInvocation[] $matchingPatterns */ - $matchA = $matchingPatterns[$patternA]; - $matchB = $matchingPatterns[$patternB]; - $emptyMatches = 0; $litLength = function ($carry, $item) use (&$emptyMatches) { if ($carry === false) { return $item; } - if($item) { - if(substr($item, -1) == '/') { + if ($item) { + if (substr($item, -1) == '/') { $item = substr($item, 0, -1); } - return preg_replace('#/'.preg_quote($item).'#', '', $carry, 1); + return preg_replace('#/' . preg_quote($item) . '#', '', $carry, 1); } $emptyMatches++; return $carry; }; + + $matchA = $matchingPatterns[$patternA]; $litA = array_reduce($matchA->getParamValues(), $litLength, false); $litA = preg_replace('#//#', '/', $litA); + $litCountA = substr_count($litA, '/'); $emptyMatches *= -1; + $matchB = $matchingPatterns[$patternB]; $litB = array_reduce($matchB->getParamValues(), $litLength, false); $litB = preg_replace('#//#', '/', $litB); - $litCountA = substr_count($litA, '/'); $litCountB = substr_count($litB, '/'); if ($litCountA != $litCountB) { @@ -145,7 +144,10 @@ if ($countA != $countB) { return $countA - $countB; } - return -$emptyMatches; + if($emptyMatches != 0) { + return -$emptyMatches; + } + return strlen($matchA->getAntPathPattern()) - strlen($matchB->getAntPathPattern()); }); if (self::getLog()->isDebugEnabled()) { @@ -169,5 +171,4 @@ } return self::$methodMetadataMap[$methodFullName]; } - } \ No newline at end of file Modified: trunk/framework/Bee/Utils/AntPathToRegexTransformer.php =================================================================== --- trunk/framework/Bee/Utils/AntPathToRegexTransformer.php 2014-10-08 09:12:00 UTC (rev 244) +++ trunk/framework/Bee/Utils/AntPathToRegexTransformer.php 2014-10-08 12:21:00 UTC (rev 245) @@ -27,7 +27,8 @@ '#\*#' => '([^/]*)', // "*" matches any string that does not contain slashes '#\(\[\^/\]\*\)\(\[\^/\]\*\)/#' => '((?:[^/]+/)*?)', // "**/" - replaced by "([^/]+)" above - matches 0:n path elements '#\(\[\^/\]\*\)\(\[\^/\]\*\)#' => '(.*?)', - '#(^|(?<=[^(*]))\?#' => '[^/]' + '#(^|(?<=[^(*]))\?#' => '[^/]', + '#/\(\.\*\?\)$#' => '(?:/(.*?))??' ); public static $TYPE_EXPRESSION_MAP = array( @@ -80,4 +81,12 @@ $matches = array(); return !!preg_match(self::PARAMETER_MATCH, $antPathPattern, $matches); } + + public static function test($antPathPattern = '/**') { + foreach(self::$SIMPLE_REPLACEMENTS as $pattern => $replace) { + var_dump($antPathPattern); + $antPathPattern = preg_replace($pattern, $replace, $antPathPattern); + echo $antPathPattern . '<hr/>'; + } + } } \ No newline at end of file Modified: trunk/tests/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolverTest.php =================================================================== --- trunk/tests/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolverTest.php 2014-10-08 09:12:00 UTC (rev 244) +++ trunk/tests/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolverTest.php 2014-10-08 12:21:00 UTC (rev 245) @@ -36,6 +36,7 @@ public function testMapping(RegexMappingInvocationResolver $resolver, $pathInfo, $expectedAntPath, $expectedParams = array()) { $request = new HttpRequestMock($pathInfo); $invocation = $resolver->getInvocationDefinition($request); + $this->assertTrue(!is_null($invocation)); $this->assertEquals($expectedAntPath, $invocation->getAntPathPattern()); $res = array_intersect_key($invocation->getParamValues(), array_flip($invocation->getUrlParameterPositions())); @@ -94,7 +95,7 @@ '/complicated/more/x/y/z/compliment/hermelin/hase', '/complicated/more/**/compl*/{string2}/**', array('hermelin')), - + array($testMapping, '', '/**') ); } Modified: trunk/tests/Bee/Utils/AntPathDataProvider.php =================================================================== --- trunk/tests/Bee/Utils/AntPathDataProvider.php 2014-10-08 09:12:00 UTC (rev 244) +++ trunk/tests/Bee/Utils/AntPathDataProvider.php 2014-10-08 12:21:00 UTC (rev 245) @@ -103,10 +103,12 @@ array("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing/testing", False), array("/x/x/**/bla", "/x/x/x/", False), + array("/x/x/**/bla", "/x/x/bla", true), array("/test/**", "/test", true), - array("", "", True)//, + array("/**", "", true), + array("", "", true)//, // array("/{bla}.*", "/testing.html", True) // #65 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |