Skip to content
Snippets Groups Projects
Commit fecc4835 authored by Jiří Pudil's avatar Jiří Pudil
Browse files

Merge branch 'map-complex-types' into 'master'

Allow mapping complex types

See merge request !4
parents 75c850bb e02c86f0
No related branches found
Tags 0.2.0
1 merge request!4Allow mapping complex types
Pipeline #28362 passed
......@@ -12,17 +12,6 @@ stages:
- composer run verify
test.verify.php72:
<<: *test-verify-template
image: grifart/php7.2-with-gulp-and-all-php-modules
test.verify.php73:
<<: *test-verify-template
image: grifart/php7.3-with-gulp-and-all-php-modules
test.verify.php74:
<<: *test-verify-template
image: grifart/php7.4-with-gulp-and-all-php-modules
......@@ -22,20 +22,17 @@
"require": {
"php": "^7.2",
"nette/utils": "^3.0.1",
"dibi/dibi": "^4.0.2"
"php": "^7.4",
"dibi/dibi": "^4.0.2",
"grifart/class-scaffolder": "^0.2.0",
"nette/utils": "^3.0.1"
},
"require-dev": {
"nette/tester": "^2.3",
"grifart/class-scaffolder": "^0.1.3",
"grifart/phpstan-oneline": "^0.2.2",
"phpstan/phpstan": "^0.11.17"
},
"suggest": {
"grifart/class-scaffolder": "⚠️ Install grifart/class-scaffolder as your `-dev` dependency to generate table definitions from your DB automatically."
},
"autoload": {
......
......@@ -93,10 +93,10 @@ final class ModificationsDecorator implements ClassDecorator
$docCommentType = $type->getDocCommentType($namespace);
$modifier->addComment(\sprintf(
'@param $%s %s%s',
$fieldName,
'@param %s $%s%s',
$docCommentType,
$type->hasComment() ? ' ' . $type->getComment($namespace) : ''
$fieldName,
$type->hasComment() ? ' ' . $type->getComment($namespace) : '',
));
}
}
......
......@@ -2,11 +2,13 @@
namespace Grifart\Tables;
use Grifart\ClassScaffolder\Definition\Types\Type;
final class TypeMapper
{
/**
* @var (callable(string $typeName, string $location): ?string)[]
* @var (callable(string $typeName, string $location): (string|Type|null))[]
*/
private $matchers = [];
......@@ -17,7 +19,7 @@ final class TypeMapper
/**
* @param (callable(string $typeName, string $location): ?string) $typeMatcher
* @param (callable(string $typeName, string $location): (string|Type|null)) $typeMatcher
* @param (callable(mixed $value, string $typeName): mixed) $mapper
*
* TODO: isn't it too general? Or just map db-type name to php type and back?
......@@ -46,7 +48,10 @@ final class TypeMapper
return !\is_object($value) ? \gettype($value) : \get_class($value);
}
public function mapType(string $location, string $typeName): string
/**
* @return string|Type
*/
public function mapType(string $location, string $typeName)
{
foreach($this->matchers as $idx => $matcher) {
if ( ($translatingType = $matcher($typeName, $location)) !== NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment