1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Mapping\NamingStrategy; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Factory\NamingStrategy; |
8
|
|
|
use function strpos; |
9
|
|
|
use function strrpos; |
10
|
|
|
use function strtolower; |
11
|
|
|
use function substr; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Naming strategy prefixes fields with a table name. |
15
|
|
|
*/ |
16
|
|
|
class TablePrefixNamingStrategy implements NamingStrategy |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function classToTableName($className) |
22
|
|
|
{ |
23
|
|
|
if (strpos($className, '\\') !== false) { |
24
|
|
|
return substr($className, strrpos($className, '\\') + 1); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $className; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function propertyToColumnName($propertyName, $className = null) |
34
|
|
|
{ |
35
|
|
|
return $this->classToTableName($className) . '_' . $propertyName; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null) |
42
|
|
|
{ |
43
|
|
|
return $this->classToTableName($className) . '_' . $propertyName . '_' . $embeddedColumnName; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function referenceColumnName($targetEntity = null) |
50
|
|
|
{ |
51
|
|
|
return $this->classToTableName($targetEntity) . '_' . 'id'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function joinColumnName($propertyName, $className = null) |
58
|
|
|
{ |
59
|
|
|
return $this->classToTableName($className) . '_' . $propertyName . '_id'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) |
66
|
|
|
{ |
67
|
|
|
return strtolower($this->classToTableName($sourceEntity) . '_' . |
68
|
|
|
$this->classToTableName($targetEntity)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function joinKeyColumnName($entityName, $referencedColumnName = null, $joinTableName = null) |
75
|
|
|
{ |
76
|
|
|
return $joinTableName . '_' . strtolower($this->classToTableName($entityName) . '_' . |
77
|
|
|
($referencedColumnName ?: 'id')); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|