Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-mlc
kohinos
Commits
f4514d2c
Commit
f4514d2c
authored
Apr 13, 2019
by
Julien Jorry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TablePrefix => set env variable DATABASE_PREFIX if you want to use database prefix
parent
d2baec74
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletions
+47
-1
services.yaml
config/services.yaml
+8
-1
TablePrefix.php
src/Doctrine/TablePrefix.php
+39
-0
No files found.
config/services.yaml
View file @
f4514d2c
...
@@ -52,7 +52,7 @@ services:
...
@@ -52,7 +52,7 @@ services:
# this creates a service per class whose id is the fully-qualified class name
# this creates a service per class whose id is the fully-qualified class name
App\
:
App\
:
resource
:
'
../src/*'
resource
:
'
../src/*'
exclude
:
'
../src/{DependencyInjection,Factory,Listener,Entity,Migrations,Tests,Twig,Kernel.php}'
exclude
:
'
../src/{DependencyInjection,Factory,
Doctrine,
Listener,Entity,Migrations,Tests,Twig,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
# as action arguments even if you don't extend any base controller class
...
@@ -63,6 +63,13 @@ services:
...
@@ -63,6 +63,13 @@ services:
# add more service definitions when explicit configuration is needed
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
# please note that last definitions always *replace* previous ones
# Définition du prefix pour les tables
App\Doctrine\TablePrefix
:
arguments
:
$prefix
:
'
%env(string:DATABASE_PREFIX)%'
tags
:
-
{
name
:
doctrine.event_subscriber
,
connection
:
default
}
# cache doctrine for bazinga geocoder
# cache doctrine for bazinga geocoder
mlc_cache_adapter
:
mlc_cache_adapter
:
class
:
Doctrine\Common\Cache\ApcCache
class
:
Doctrine\Common\Cache\ApcCache
...
...
src/Doctrine/TablePrefix.php
0 → 100644
View file @
f4514d2c
<?php
namespace
App\Doctrine
;
use
Doctrine\Common\EventSubscriber
;
use
\Doctrine\ORM\Event\LoadClassMetadataEventArgs
;
class
TablePrefix
implements
EventSubscriber
{
protected
$prefix
=
''
;
public
function
__construct
(
$prefix
)
{
$this
->
prefix
=
(
string
)
$prefix
;
}
public
function
getSubscribedEvents
()
{
return
[
'loadClassMetadata'
];
}
public
function
loadClassMetadata
(
LoadClassMetadataEventArgs
$eventArgs
)
{
$classMetadata
=
$eventArgs
->
getClassMetadata
();
if
(
!
$classMetadata
->
isInheritanceTypeSingleTable
()
||
$classMetadata
->
getName
()
===
$classMetadata
->
rootEntityName
)
{
$classMetadata
->
setPrimaryTable
([
'name'
=>
$this
->
prefix
.
$classMetadata
->
getTableName
()
]);
}
foreach
(
$classMetadata
->
getAssociationMappings
()
as
$fieldName
=>
$mapping
)
{
if
(
$mapping
[
'type'
]
==
\Doctrine\ORM\Mapping\ClassMetadataInfo
::
MANY_TO_MANY
&&
$mapping
[
'isOwningSide'
])
{
$mappedTableName
=
$mapping
[
'joinTable'
][
'name'
];
$classMetadata
->
associationMappings
[
$fieldName
][
'joinTable'
][
'name'
]
=
$this
->
prefix
.
$mappedTableName
;
}
}
}
}
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