. */ namespace Doctrine\ORM; use Doctrine\Common\Util\Inflector; /** * The default NamingStrategy * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 2.3 * @author Fabio B. Silva */ class UnderscoreNamingStrategy implements NamingStrategy { const CASE_LOWER = 'lower'; const CASE_UPPER = 'upper'; /** * @var string */ private $case; /** * @param string $case */ public function __construct($case = self::CASE_LOWER) { $this->case = $case; } /** * @return string */ public function getCase() { return $this->case; } /** * @param string $case */ public function setCase($case) { $this->case = $case; } /** * {@inheritdoc} */ public function classToTableName($className) { if (strpos($className, '\\') !== false) { $className = substr($className, strrpos($className, '\\') + 1); } return $this->underscore($className); } /** * {@inheritdoc} */ public function propertyToColumnName($propertyName) { return $this->underscore($propertyName); } /** * {@inheritdoc} */ public function referenceColumnName() { return $this->case == self::CASE_UPPER ? 'ID' : 'id'; } /** * {@inheritdoc} */ public function joinColumnName($propertyName) { return $this->underscore($propertyName) . '_' . $this->referenceColumnName(); } /** * {@inheritdoc} */ public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) { return $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity); } /** * {@inheritdoc} */ public function joinKeyColumnName($entityName, $referencedColumnName = null) { return $this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName()); } /** * @param string $string * @return string */ private function underscore($string) { $string = Inflector::tableize($string); if ($this->case == self::CASE_UPPER) { return strtoupper($string); } return $string; } }