DefaultNamingStrategy.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Mapping;
  20. /**
  21. * The default NamingStrategy
  22. *
  23. *
  24. * @link www.doctrine-project.org
  25. * @since 2.3
  26. * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
  27. */
  28. class DefaultNamingStrategy implements NamingStrategy
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function classToTableName($className)
  34. {
  35. if (strpos($className, '\\') !== false) {
  36. return substr($className, strrpos($className, '\\') + 1);
  37. }
  38. return $className;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function propertyToColumnName($propertyName)
  44. {
  45. return $propertyName;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function referenceColumnName()
  51. {
  52. return 'id';
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function joinColumnName($propertyName)
  58. {
  59. return $propertyName . '_' . $this->referenceColumnName();
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
  65. {
  66. return strtolower($this->classToTableName($sourceEntity) . '_' .
  67. $this->classToTableName($targetEntity));
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function joinKeyColumnName($entityName, $referencedColumnName = null)
  73. {
  74. return strtolower($this->classToTableName($entityName) . '_' .
  75. ($referencedColumnName ?: $this->referenceColumnName()));
  76. }
  77. }