[Beeframework-svn] SF.net SVN: beeframework:[190] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2014-07-25 09:09:00
|
Revision: 190 http://sourceforge.net/p/beeframework/code/190 Author: m_plomer Date: 2014-07-25 09:08:52 +0000 (Fri, 25 Jul 2014) Log Message: ----------- - Beans: introduced Base64StringPropertyEditor Modified Paths: -------------- trunk/framework/Bee/Beans/PropertyEditor/PropertyEditorRegistry.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/HandlerMethodMetadata.php trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php Added Paths: ----------- trunk/framework/Bee/Beans/PropertyEditor/Base64StringPropertyEditor.php Added: trunk/framework/Bee/Beans/PropertyEditor/Base64StringPropertyEditor.php =================================================================== --- trunk/framework/Bee/Beans/PropertyEditor/Base64StringPropertyEditor.php (rev 0) +++ trunk/framework/Bee/Beans/PropertyEditor/Base64StringPropertyEditor.php 2014-07-25 09:08:52 UTC (rev 190) @@ -0,0 +1,45 @@ +<?php +namespace Bee\Beans\PropertyEditor; +/* + * 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 Bee\Beans\IPropertyEditor; + +/** + * Class Base64StringPropertyEditor + * @package Bee\Beans\PropertyEditor + */ +class Base64StringPropertyEditor implements IPropertyEditor { + + /** + * Enter description here... + * + * @param mixed $value + * @return String + */ + public function toString($value) { + return base64_encode($value); + } + + /** + * Enter description here... + * + * @param String $value + * @return mixed + */ + public function fromString($value) { + return base64_decode($value); + } +} \ No newline at end of file Modified: trunk/framework/Bee/Beans/PropertyEditor/PropertyEditorRegistry.php =================================================================== --- trunk/framework/Bee/Beans/PropertyEditor/PropertyEditorRegistry.php 2014-07-25 08:39:10 UTC (rev 189) +++ trunk/framework/Bee/Beans/PropertyEditor/PropertyEditorRegistry.php 2014-07-25 09:08:52 UTC (rev 190) @@ -134,5 +134,6 @@ PropertyEditorRegistry::registerEditor(ITypeDefinitions::IPv6, new GenericPropertyEditor(FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)); PropertyEditorRegistry::registerEditor(ITypeDefinitions::UNIX_TIMESTAMP, new UnixTimestampPropertyEditor()); PropertyEditorRegistry::registerEditor(ITypeDefinitions::STRING, new StringPropertyEditor()); +PropertyEditorRegistry::registerEditor(ITypeDefinitions::BASE64, new Base64StringPropertyEditor()); PropertyEditorRegistry::registerEditor(ConstantPropertyEditor::TYPE_STRING, new ConstantPropertyEditor()); Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2014-07-25 08:39:10 UTC (rev 189) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2014-07-25 09:08:52 UTC (rev 190) @@ -122,7 +122,7 @@ * @return mixed */ protected function createDelegate(array $mapping) { - return new RegexMappingInvocationResolver($mapping); + return new RegexMappingInvocationResolver($mapping, $this->getPropertyEditorRegistry()); } /** @@ -131,4 +131,11 @@ public function setBeeContext(Bee_IContext $context) { $this->propertyEditorRegistry = new PropertyEditorRegistry($context); } + + /** + * @return PropertyEditorRegistry + */ + public function getPropertyEditorRegistry() { + return $this->propertyEditorRegistry; + } } \ No newline at end of file Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/HandlerMethodMetadata.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/HandlerMethodMetadata.php 2014-07-25 08:39:10 UTC (rev 189) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/HandlerMethodMetadata.php 2014-07-25 09:08:52 UTC (rev 190) @@ -2,8 +2,8 @@ namespace Bee\MVC\Controller\Multiaction\HandlerMethodInvocator; +use Bee\Beans\PropertyEditor\PropertyEditorRegistry; use Bee\Utils\ITypeDefinitions; -use Bee_Utils_Types; use ReflectionClass; use ReflectionMethod; @@ -42,10 +42,14 @@ */ private $parameterPositions; - function __construct(ReflectionMethod $method) { + /** + * @param ReflectionMethod $method + * @param PropertyEditorRegistry $propertyEditorRegistry + */ + function __construct(ReflectionMethod $method, PropertyEditorRegistry $propertyEditorRegistry) { $this->method = $method; - $typeNameMap = self::getDocBlockTypeHints($method); + $typeNameMap = self::getDocBlockTypeHints($method, $propertyEditorRegistry); $this->typeMap = array(); $this->requestParamPos = array(); $this->parameterPositions = array(); @@ -101,20 +105,23 @@ /** * @param ReflectionMethod $method + * @param PropertyEditorRegistry $propertyEditorRegistry * @return array */ - protected static function getDocBlockTypeHints(ReflectionMethod $method) { + protected static function getDocBlockTypeHints(ReflectionMethod $method, PropertyEditorRegistry $propertyEditorRegistry) { $importMap = self::getImportMap($method->getDeclaringClass()); $namespace = $method->getDeclaringClass()->getNamespaceName(); $matches = array(); preg_match_all(self::DOCBLOCK_PARAM_TYPE_HINT_MATCH, $method->getDocComment(), $matches); $types = $matches[1]; - array_walk($types, function (&$value) use ($importMap, $namespace) { + array_walk($types, function (&$value) use ($importMap, $namespace, $propertyEditorRegistry) { if (array_key_exists($value, $importMap)) { $value = $importMap[$value]; - } else if(!Bee_Utils_Types::isPrimitive($value) && !class_exists($value) && !interface_exists($value)) { + } else if(!$propertyEditorRegistry->editorExists($value)) { $value = $namespace . '\\' . $value; } + // test if property editor exists + $propertyEditorRegistry->getEditor($value); }); return array_combine($matches[2], $types); } Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php =================================================================== --- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2014-07-25 08:39:10 UTC (rev 189) +++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/RegexMappingInvocationResolver.php 2014-07-25 09:08:52 UTC (rev 190) @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use Bee\Beans\PropertyEditor\PropertyEditorRegistry; use Bee\Utils\AntPathToRegexTransformer; use Bee_MVC_IHttpRequest; use Logger; @@ -55,10 +56,11 @@ /** * @param array|ReflectionMethod[] $mapping + * @param PropertyEditorRegistry $propertyEditorRegistry */ - public function __construct(array $mapping) { + public function __construct(array $mapping, PropertyEditorRegistry $propertyEditorRegistry) { foreach ($mapping as $antPathPattern => $method) { - $methodMeta = self::getCachedMethodMetadata($method); + $methodMeta = self::getCachedMethodMetadata($method, $propertyEditorRegistry); $urlParameterPositions = array(); $regex = AntPathToRegexTransformer::getRegexForParametrizedPattern($antPathPattern, $methodMeta->getTypeMap(), $urlParameterPositions); @@ -160,10 +162,10 @@ return null; } - public static function getCachedMethodMetadata(ReflectionMethod $method) { + public static function getCachedMethodMetadata(ReflectionMethod $method, PropertyEditorRegistry $propertyEditorRegistry) { $methodFullName = $method->getDeclaringClass()->getName() . '::' . $method->getName(); if (!array_key_exists($methodFullName, self::$methodMetadataMap)) { - self::$methodMetadataMap[$methodFullName] = new HandlerMethodMetadata($method); + self::$methodMetadataMap[$methodFullName] = new HandlerMethodMetadata($method, $propertyEditorRegistry); } return self::$methodMetadataMap[$methodFullName]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |