Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Micrus-Doctrine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Avris
Micrus-Doctrine
Commits
faf59f6a
Commit
faf59f6a
authored
Sep 14, 2017
by
Avris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v4.0
parent
d4624b66
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
12 deletions
+75
-12
services.yml
config/services.yml
+13
-10
Doctrine.php
src/Doctrine.php
+2
-2
DoctrineMatchProvider.php
src/DoctrineMatchProvider.php
+60
-0
No files found.
config/services.yml
View file @
faf59f6a
Avris\Micrus\Doctrine\
:
dir
:
'
%MODULE_DIR%/src/'
exclude
:
-
'
#^DoctrineUserProvider$#'
Avris\Micrus\Doctrine\Doctrine
:
params
:
-
'
@config.database'
-
'
%APP_DEBUG%'
-
'
%PROJECT_DIR%/var/cache/{@env}/doctrine'
-
'
#module'
-
'
@Psr\Log\LoggerInterface'
-
'
@?doctrineCache'
arguments
:
$connection
:
'
@config.database'
$proxyDir
:
'
%PROJECT_DIR%/var/cache/{@env}/doctrine'
$cache
:
'
@?doctrineCache'
# TODO userProvider: Avris\Micrus\Doctrine\DoctrineUserProvider
userProvider
:
class
:
Avris\Micrus\Doctrine\DoctrineUserProvider
params
:
[
'
@Avris\Micrus\Doctrine\Doctrine'
]
Doctrine\ORM\EntityManagerInterface
:
resolve
:
'
@Avris\Micrus\Doctrine\Doctrine.entityManager'
src/Doctrine.php
View file @
faf59f6a
...
...
@@ -22,7 +22,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
public
function
__construct
(
Bag
$connection
,
bool
$
d
ebug
,
bool
$
envAppD
ebug
,
string
$proxyDir
,
array
$modules
,
LoggerInterface
$logger
,
...
...
@@ -36,7 +36,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
}
}
$config
=
Setup
::
createAnnotationMetadataConfiguration
(
$dirs
,
$
d
ebug
,
$proxyDir
,
$cache
,
false
);
$config
=
Setup
::
createAnnotationMetadataConfiguration
(
$dirs
,
$
envAppD
ebug
,
$proxyDir
,
$cache
,
false
);
$config
->
setSQLLogger
(
new
DoctrineLogger
(
$logger
));
$this
->
entityManager
=
EntityManager
::
create
(
$connection
->
all
(),
$config
);
...
...
src/Doctrine
Automatch
er.php
→
src/Doctrine
MatchProvid
er.php
View file @
faf59f6a
<?php
namespace
Avris\Micrus\Doctrine
;
use
Avris\Micrus\Controller\Routing\Model\RouteMatch
;
use
Avris\Micrus\Exception\NotFoundException
;
use
Avris\Micrus\Model\MatchProvider
;
use
Doctrine\ORM\EntityManager
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\Mapping\MappingException
;
class
Doctrine
Automatcher
// implements Something
class
Doctrine
MatchProvider
implements
MatchProvider
{
/** @var EntityManager */
private
$em
;
// TODO remove somehow
private
$i
=
0
;
public
function
__construct
(
EntityManagerInterface
$entityManager
)
{
$this
->
em
=
$entityManager
;
}
public
function
supports
(
string
$className
)
public
function
supports
(
\ReflectionParameter
$parameter
)
:
bool
{
if
(
!
$parameter
->
getClass
())
{
return
false
;
}
try
{
$this
->
em
->
getClassMetadata
(
$
className
);
$this
->
em
->
getClassMetadata
(
$
parameter
->
getClass
()
->
getName
()
);
return
true
;
}
catch
(
MappingException
$e
)
{
...
...
@@ -27,21 +36,25 @@ class DoctrineAutomatcher // implements Something
}
}
public
function
fetch
(
string
$className
,
string
$key
,
$value
)
public
function
fetch
(
\ReflectionParameter
$parameter
,
RouteMatch
$routeMatch
)
{
$repo
=
$this
->
em
->
getRepository
(
$
className
);
$repo
=
$this
->
em
->
getRepository
(
$
parameter
->
getClass
()
->
getName
()
);
$object
=
$repo
->
findOneBy
([
$key
=>
$value
]);
$key
=
array_keys
(
$routeMatch
->
getTags
())[
$this
->
i
];
// TODO waaay nicer
$value
=
$routeMatch
->
getTags
()[
$key
];
$entity
=
$repo
->
findOneBy
([
$key
=>
$value
]);
if
(
!
$
object
)
{
if
(
!
$
entity
)
{
throw
new
NotFoundException
(
sprintf
(
'Cannot find an
object
of type "%s" with %s=%s'
,
$
className
,
'Cannot find an
entity
of type "%s" with %s=%s'
,
$
parameter
->
getClass
()
->
getName
()
,
$key
,
$value
));
}
return
$object
;
$this
->
i
++
;
return
$entity
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment