diff --git a/composer.json b/composer.json index f236319..d7f3a3c 100644 --- a/composer.json +++ b/composer.json @@ -45,6 +45,8 @@ "doctrine/orm" : "~2.5", + "phpdocumentor/reflection-docblock": "^5.0", + "nette/di" : "~3.0", "nette/utils" : "~3.0" }, diff --git a/src/IPub/DoctrineCrud/Mapping/EntityMapper.php b/src/IPub/DoctrineCrud/Mapping/EntityMapper.php index f8734e5..d453688 100644 --- a/src/IPub/DoctrineCrud/Mapping/EntityMapper.php +++ b/src/IPub/DoctrineCrud/Mapping/EntityMapper.php @@ -16,6 +16,8 @@ namespace IPub\DoctrineCrud\Mapping; +use phpDocumentor; + use ReflectionClass; use ReflectionException; use ReflectionMethod; @@ -222,7 +224,6 @@ public function fillEntity(Utils\ArrayHash $values, Entities\IEntity $entity, bo } else { $varAnnotation = $this->parseAnnotation($propertyReflection, 'var'); - $varAnnotation = $varAnnotation ? (is_array($varAnnotation) ? (count($varAnnotation) ? end($varAnnotation) : NULL) : $varAnnotation) : NULL; $className = NULL; @@ -269,7 +270,6 @@ public function fillEntity(Utils\ArrayHash $values, Entities\IEntity $entity, bo } else { $varAnnotation = $this->parseAnnotation($propertyReflection, 'var'); - $varAnnotation = $varAnnotation ? (is_array($varAnnotation) ? (count($varAnnotation) ? end($varAnnotation) : NULL) : $varAnnotation) : NULL; $className = $varAnnotation; @@ -412,24 +412,19 @@ private function findAttributeName(Entities\IEntity $entity, string $className) * @param Reflector $ref * @param string $name * - * @return array|NULL + * @return string|NULL */ - private function parseAnnotation(Reflector $ref, string $name) : ?array + private function parseAnnotation(Reflector $ref, string $name) : ?string { - if (!preg_match_all('#[\s*]@' . preg_quote($name, '#') . '(?:\(\s*([^)]*)\s*\)|\s|$)#', (string) $ref->getDocComment(), $m)) { - return NULL; - } - - static $tokens = ['true' => TRUE, 'false' => FALSE, 'null' => NULL]; - - $res = []; + $factory = phpDocumentor\Reflection\DocBlockFactory::createInstance(); + $docblock = $factory->create($ref->getDocComment()); - foreach ($m[1] as $s) { - foreach (preg_split('#\s*,\s*#', $s, -1, PREG_SPLIT_NO_EMPTY) ?: ['true'] as $item) { - $res[] = array_key_exists($tmp = strtolower($item), $tokens) ? $tokens[$tmp] : $item; + foreach ($docblock->getTags() as $tag) { + if ($tag->getName() === $name) { + return trim((string) $tag); } } - return $res; + return NULL; } } diff --git a/tests/php.ini-unix b/tests/php.ini-unix index cdcc67b..071d34d 100644 --- a/tests/php.ini-unix +++ b/tests/php.ini-unix @@ -1,8 +1,11 @@ -extension = xdebug.so -extension = json.so extension = pdo.so extension = pdo_sqlite.so extension = sqlite.so +extension = iconv.so +extension = tokenizer.so +extension = json.so +extension = ctype.so +extension = xdebug.so [xdebug] xdebug.enable = On diff --git a/tests/php.ini-win b/tests/php.ini-win index f5c89d0..650293d 100644 --- a/tests/php.ini-win +++ b/tests/php.ini-win @@ -1,7 +1,10 @@ [PHP] extension_dir = "./ext" -extension = php_xdebug.dll -extension = php_json.dll extension = php_pdo.dll extension = php_pdo_sqlite.dll -extension = php_sqlite..dll +extension = php_sqlite.dll +extension = iconv.dll +extension = tokenizer.dll +extension = json.dll +extension = ctype.dll +extension = xdebug.dll