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
b3f40019
Commit
b3f40019
authored
3 years ago
by
Daniel Kurowski
Browse files
Options
Downloads
Patches
Plain Diff
Scaffolding: added buildersForPgTable() as well
parent
1123c386
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Allow customizations on scaffolded objects
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Scaffolding/Builders.php
+58
-0
58 additions, 0 deletions
src/Scaffolding/Builders.php
src/Scaffolding/Scaffolding.php
+55
-32
55 additions, 32 deletions
src/Scaffolding/Scaffolding.php
with
113 additions
and
32 deletions
src/Scaffolding/Builders.php
0 → 100644
+
58
−
0
View file @
b3f40019
<?php
declare
(
strict_types
=
1
);
namespace
Grifart\Tables\Scaffolding
;
use
Grifart\ClassScaffolder\Definition\ClassDefinition
;
use
Grifart\ClassScaffolder\Definition\ClassDefinitionBuilder
;
final
class
Builders
{
private
function
__construct
(
private
ClassDefinitionBuilder
$rowClass
,
private
ClassDefinitionBuilder
$modificationsClass
,
private
ClassDefinitionBuilder
$tableClass
,
)
{}
public
static
function
from
(
ClassDefinitionBuilder
$rowClass
,
ClassDefinitionBuilder
$modificationsClass
,
ClassDefinitionBuilder
$tableClass
,
):
self
{
return
new
self
(
$rowClass
,
$modificationsClass
,
$tableClass
,
);
}
public
function
row
():
ClassDefinitionBuilder
{
return
$this
->
rowClass
;
}
public
function
modifications
():
ClassDefinitionBuilder
{
return
$this
->
modificationsClass
;
}
public
function
table
():
ClassDefinitionBuilder
{
return
$this
->
tableClass
;
}
/**
* @return ClassDefinition[]
*/
public
function
buildAll
():
array
{
return
[
$this
->
rowClass
->
build
(),
$this
->
modificationsClass
->
build
(),
$this
->
tableClass
->
build
(),
];
}
}
This diff is collapsed.
Click to expand it.
src/Scaffolding/Scaffolding.php
+
55
−
32
View file @
b3f40019
...
@@ -16,10 +16,12 @@ use function Grifart\ClassScaffolder\Definition\Types\resolve;
...
@@ -16,10 +16,12 @@ use function Grifart\ClassScaffolder\Definition\Types\resolve;
final
class
Scaffolding
final
class
Scaffolding
{
{
private
static
function
location
(
string
$schema
,
string
$table
,
string
$column
):
string
{
private
static
function
location
(
string
$schema
,
string
$table
,
string
$column
):
string
{
return
"
$schema
.
$table
.
$column
"
;
return
"
$schema
.
$table
.
$column
"
;
}
}
/**
/**
* @return ClassDefinition[]
* @return ClassDefinition[]
*/
*/
...
@@ -32,8 +34,32 @@ final class Scaffolding
...
@@ -32,8 +34,32 @@ final class Scaffolding
string
$modificationClass
,
string
$modificationClass
,
string
$tableClass
,
string
$tableClass
,
string
$primaryKeyClass
string
$primaryKeyClass
):
array
{
):
array
{
return
self
::
buildersForPgTable
(
$pgReflector
,
$mapper
,
$schema
,
$table
,
$rowClass
,
$modificationClass
,
$tableClass
,
$primaryKeyClass
,
)
->
buildAll
();
}
public
static
function
buildersForPgTable
(
PostgresReflector
$pgReflector
,
TypeMapper
$mapper
,
string
$schema
,
string
$table
,
string
$rowClass
,
string
$modificationClass
,
string
$tableClass
,
string
$primaryKeyClass
):
Builders
{
$columnsNativeTypes
=
$pgReflector
->
retrieveColumnInfo
(
$schema
,
$table
);
$columnsNativeTypes
=
$pgReflector
->
retrieveColumnInfo
(
$schema
,
$table
);
if
(
\count
(
$columnsNativeTypes
)
===
0
)
{
if
(
\count
(
$columnsNativeTypes
)
===
0
)
{
throw
new
\LogicException
(
'No columns found for given configuration. Does referenced table exist?'
);
throw
new
\LogicException
(
'No columns found for given configuration. Does referenced table exist?'
);
...
@@ -56,36 +82,33 @@ final class Scaffolding
...
@@ -56,36 +82,33 @@ final class Scaffolding
return
$builder
;
return
$builder
;
};
};
return
[
// row class
// row class
$addTableFields
(
new
ClassDefinitionBuilder
(
$rowClass
))
$row
=
$addTableFields
(
new
ClassDefinitionBuilder
(
$rowClass
))
->
implement
(
Row
::
class
)
->
implement
(
Row
::
class
)
->
decorate
(
new
PropertiesDecorator
())
->
decorate
(
new
PropertiesDecorator
())
->
decorate
(
new
InitializingConstructorDecorator
())
->
decorate
(
new
InitializingConstructorDecorator
())
->
decorate
(
new
GettersDecorator
())
->
decorate
(
new
GettersDecorator
())
->
decorate
(
new
PrivateConstructorDecorator
())
->
decorate
(
new
PrivateConstructorDecorator
())
->
decorate
(
new
ReconstituteConstructorDecorator
())
->
decorate
(
new
ReconstituteConstructorDecorator
());
->
build
(),
// row modification class
// row modification class
$modifications
=
$addTableFields
(
new
ClassDefinitionBuilder
(
$modificationClass
))
$addTableFields
(
new
ClassDefinitionBuilder
(
$modificationClass
))
->
decorate
(
new
ModificationsDecorator
(
$tableClass
,
$primaryKeyClass
));
->
decorate
(
new
ModificationsDecorator
(
$tableClass
,
$primaryKeyClass
))
->
build
(),
// table class
$table
=
(
new
ClassDefinitionBuilder
(
$tableClass
))
// table class
->
decorate
(
new
TableDecorator
(
(
new
ClassDefinitionBuilder
(
$tableClass
))
$schema
,
->
decorate
(
new
TableDecorator
(
$table
,
$schema
,
$primaryKeyClass
,
$table
,
$rowClass
,
$primaryKeyClass
,
$modificationClass
,
$rowClass
,
$columnsNativeTypes
,
$modificationClass
,
$columnsPhpTypes
,
$columnsNativeTypes
,
));
$columnsPhpTypes
,
))
return
Builders
::
from
(
$row
,
$modifications
,
$table
);
->
build
(),
];
}
}
}
}
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