Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
grifart libs
tables
Commits
89617e26
Verified
Commit
89617e26
authored
2 years ago
by
Jiří Pudil
Browse files
Options
Downloads
Patches
Plain Diff
simplify type mapping configuration
parent
ca1c28b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!40
CompositeType: add explicit type cast to support composite values in WHERE clause
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/DI/TablesExtension.php
+14
-14
14 additions, 14 deletions
src/DI/TablesExtension.php
tests/DI/config/types.neon
+1
-3
1 addition, 3 deletions
tests/DI/config/types.neon
with
15 additions
and
17 deletions
src/DI/TablesExtension.php
+
14
−
14
View file @
89617e26
...
...
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace
Grifart\Tables\DI
;
use
Grifart\Tables\Database\Identifier
;
use
Grifart\Tables\Scaffolding\PostgresReflector
;
use
Grifart\Tables\Scaffolding\TablesDefinitions
;
use
Grifart\Tables\TableManager
;
...
...
@@ -13,6 +14,8 @@ use Nette\DI\Definitions\ServiceDefinition;
use
Nette\DI\Definitions\Statement
;
use
Nette\Schema\Expect
;
use
Nette\Schema\Schema
;
use
function
explode
;
use
function
is_int
;
/**
* @property-read \stdClass $config
...
...
@@ -24,13 +27,10 @@ final class TablesExtension extends CompilerExtension
return
Expect
::
structure
([
'typeResolver'
=>
Expect
::
anyOf
(
Expect
::
type
(
Statement
::
class
),
Expect
::
string
())
->
default
(
TypeResolver
::
class
),
'types'
=>
Expect
::
arrayOf
(
Expect
::
anyOf
(
keyType
:
Expect
::
anyOf
(
Expect
::
int
(),
Expect
::
string
()),
valueType
:
Expect
::
anyOf
(
Expect
::
type
(
Statement
::
class
),
Expect
::
string
(),
Expect
::
structure
([
'type'
=>
Expect
::
anyOf
(
Expect
::
type
(
Statement
::
class
),
Expect
::
string
()),
'location'
=>
Expect
::
type
(
Statement
::
class
),
]),
),
)
->
default
([]),
]);
...
...
@@ -53,16 +53,16 @@ final class TablesExtension extends CompilerExtension
->
setType
(
TypeResolver
::
class
)
->
setFactory
(
$this
->
config
->
typeResolver
);
foreach
(
$this
->
config
->
types
as
$typeDefinition
)
{
if
(
$typeDefinition
instanceof
\stdClass
)
{
$type
=
$typeDefinition
->
type
instanceof
Statement
?
$typeDefinition
->
type
:
new
Statement
(
$typeDefinition
->
type
);
$typeResolver
->
addSetup
(
'addResolutionByLocation'
,
[
$typeDefinition
->
location
,
$type
]);
foreach
(
$this
->
config
->
types
as
$key
=>
$type
)
{
$type
=
$type
instanceof
Statement
?
$type
:
new
Statement
(
$type
);
}
elseif
(
\is_string
(
$typeDefinition
))
{
$typeResolver
->
addSetup
(
'addResolutionByTypeName'
,
[
new
Statement
(
$typeDefinition
)]);
}
elseif
(
$typeDefinition
instanceof
Statement
)
{
$typeResolver
->
addSetup
(
'addResolutionByTypeName'
,
[
$typeDefinition
]);
if
(
is_int
(
$key
))
{
$typeResolver
->
addSetup
(
'addResolutionByTypeName'
,
[
$type
]);
}
else
{
$typeResolver
->
addSetup
(
'addResolutionByLocation'
,
[
new
Statement
(
Identifier
::
class
,
explode
(
'.'
,
$key
)),
$type
,
]);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/DI/config/types.neon
+
1
−
3
View file @
89617e26
tables:
types:
- type: Grifart\Tables\Types\IntType::integer()
location: Grifart\Tables\Database\Identifier(public, test, score)
public.test.score: Grifart\Tables\Types\IntType::integer()
- Grifart\Tables\Tests\Fixtures\VersionType
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment