3 namespace Wallabag\CoreBundle\Doctrine\Mapping
;
5 use Doctrine\ORM\Mapping\NamingStrategy
;
8 * Puts a prefix to each table.
11 * - http://stackoverflow.com/a/23860613/569101
12 * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
14 class PrefixedNamingStrategy
implements NamingStrategy
16 protected $prefix = '';
18 public function __construct($prefix)
20 $this->prefix
= (string) $prefix;
26 public function classToTableName($className)
28 return strtolower($this->prefix
.substr($className, strrpos($className, '\\') +
1));
34 public function propertyToColumnName($propertyName, $className = null)
42 public function referenceColumnName()
50 public function joinColumnName($propertyName)
52 return $propertyName.'_'.$this->referenceColumnName();
58 public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
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);
65 return strtolower($this->classToTableName($sourceEntity).'_'.$target);
71 public function joinKeyColumnName($entityName, $referencedColumnName = null)
73 return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName()));
79 public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
81 return $propertyName.'_'.$embeddedColumnName;