/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php

https://gitlab.com/mario.uriarte/doctrine2.5-tutorial · PHP · 94 lines · 38 code · 10 blank · 46 comment · 1 complexity · 8dfbf222938b462bc4b28736590d0f0f MD5 · raw file

  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, $className = null)
  44. {
  45. return $propertyName;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
  51. {
  52. return $propertyName.'_'.$embeddedColumnName;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function referenceColumnName()
  58. {
  59. return 'id';
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function joinColumnName($propertyName, $className = null)
  65. {
  66. return $propertyName . '_' . $this->referenceColumnName();
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
  72. {
  73. return strtolower($this->classToTableName($sourceEntity) . '_' .
  74. $this->classToTableName($targetEntity));
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function joinKeyColumnName($entityName, $referencedColumnName = null)
  80. {
  81. return strtolower($this->classToTableName($entityName) . '_' .
  82. ($referencedColumnName ?: $this->referenceColumnName()));
  83. }
  84. }