aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Doctrine
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-10-24 15:28:02 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-11-07 14:15:33 +0100
commitbd0f3d32c9ccb8f7a1409edb960b909a5e6a096d (patch)
tree80b891432be989e7dbfa2817f0f965e67690ebe5 /src/Wallabag/CoreBundle/Doctrine
parent54a2241e136ccf90c659b5699af4489b6e4d2da1 (diff)
downloadwallabag-bd0f3d32c9ccb8f7a1409edb960b909a5e6a096d.tar.gz
wallabag-bd0f3d32c9ccb8f7a1409edb960b909a5e6a096d.tar.zst
wallabag-bd0f3d32c9ccb8f7a1409edb960b909a5e6a096d.zip
Quoted entity to avoid reserved keyword
Should fix #1498
Diffstat (limited to 'src/Wallabag/CoreBundle/Doctrine')
-rw-r--r--src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
deleted file mode 100644
index 509348db..00000000
--- a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
+++ /dev/null
@@ -1,83 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Doctrine\Mapping;
4
5use Doctrine\ORM\Mapping\NamingStrategy;
6
7/**
8 * Puts a prefix to each table.
9 *
10 * Solution from :
11 * - http://stackoverflow.com/a/23860613/569101
12 * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
13 */
14class PrefixedNamingStrategy implements NamingStrategy
15{
16 protected $prefix = '';
17
18 public function __construct($prefix)
19 {
20 $this->prefix = (string) $prefix;
21 }
22
23 /**
24 * {@inheritdoc}
25 */
26 public function classToTableName($className)
27 {
28 return strtolower($this->prefix.substr($className, strrpos($className, '\\') + 1));
29 }
30
31 /**
32 * {@inheritdoc}
33 */
34 public function propertyToColumnName($propertyName, $className = null)
35 {
36 return $propertyName;
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 public function referenceColumnName()
43 {
44 return 'id';
45 }
46
47 /**
48 * {@inheritdoc}
49 */
50 public function joinColumnName($propertyName)
51 {
52 return $propertyName.'_'.$this->referenceColumnName();
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
59 {
60 // for join table we don't want to have both table concatenated AND prefixed
61 // we just want the whole table to prefixed once
62 // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag"
63 $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1);
64
65 return strtolower($this->classToTableName($sourceEntity).'_'.$target);
66 }
67
68 /**
69 * {@inheritdoc}
70 */
71 public function joinKeyColumnName($entityName, $referencedColumnName = null)
72 {
73 return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName()));
74 }
75
76 /**
77 * {@inheritdoc}
78 */
79 public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
80 {
81 return $propertyName.'_'.$embeddedColumnName;
82 }
83}