PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/propel/propel1/generator/lib/builder/om/ClassTools.php

https://gitlab.com/Isaki/le331.fr
PHP | 142 lines | 118 code | 3 blank | 21 comment | 1 complexity | e7c63f546ff02a2f6c0eb924b747d86b MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * Tools to support class & package inclusion and referencing.
  11. *
  12. * @author Hans Lellelid <hans@xmpl.org>
  13. * @version $Revision$
  14. * @package propel.generator.builder.om
  15. */
  16. class ClassTools
  17. {
  18. /**
  19. * Gets just classname, given a dot-path to class.
  20. *
  21. * @param string $qualifiedName
  22. *
  23. * @return string
  24. */
  25. public static function classname($qualifiedName)
  26. {
  27. if (false !== $pos = strrpos($qualifiedName, '.')) {
  28. return substr($qualifiedName, $pos + 1); // start just after '.'
  29. } elseif (false !== $pos = strrpos($qualifiedName, '\\')) {
  30. return substr($qualifiedName, $pos + 1);
  31. } else {
  32. return $qualifiedName; // there is no '.' in the qualified name
  33. }
  34. }
  35. /**
  36. * Gets the path to be used in include()/require() statement.
  37. *
  38. * Supports multiple function signatures:
  39. *
  40. * (1) getFilePath($dotPathClass);
  41. * (2) getFilePath($dotPathPrefix, $className);
  42. * (3) getFilePath($dotPathPrefix, $className, $extension);
  43. *
  44. * @param string $path dot-path to class or to package prefix.
  45. * @param string $classname class name
  46. * @param string $extension The extension to use on the file.
  47. *
  48. * @return string The constructed file path.
  49. */
  50. public static function getFilePath($path, $classname = null, $extension = '.php')
  51. {
  52. $path = strtr(ltrim($path, '.'), '.', '/');
  53. return self::createFilePath($path, $classname, $extension);
  54. }
  55. /**
  56. * This method replaces the `getFilePath()` method in OMBuilder as we consider `$path` as
  57. * a real path instead of a dot-notation value. `$path` is generated by the `getPackagePath()`
  58. * method.
  59. *
  60. * @param string $path path to class or to package prefix.
  61. * @param string $classname class name
  62. * @param string $extension The extension to use on the file.
  63. *
  64. * @return string The constructed file path.
  65. */
  66. public static function createFilePath($path, $classname = null, $extension = '.php')
  67. {
  68. if ($classname !== null) {
  69. if ($path !== '') {
  70. $path .= '/';
  71. }
  72. return $path . $classname . $extension;
  73. } else {
  74. return $path . $extension;
  75. }
  76. }
  77. /**
  78. * Gets the basePeer path if specified for table/db.
  79. * If not, will return 'propel.util.BasePeer'
  80. *
  81. * @return string
  82. */
  83. public static function getBasePeer(Table $table)
  84. {
  85. $class = $table->getBasePeer();
  86. if ($class === null) {
  87. $class = "propel.util.BasePeer";
  88. }
  89. return $class;
  90. }
  91. /**
  92. * Gets the baseClass path if specified for table/db.
  93. * If not, will return 'propel.om.BaseObject'
  94. *
  95. * @return string
  96. */
  97. public static function getBaseClass(Table $table)
  98. {
  99. $class = $table->getBaseClass();
  100. if ($class === null) {
  101. $class = "propel.om.BaseObject";
  102. }
  103. return $class;
  104. }
  105. /**
  106. * Gets the interface path if specified for table.
  107. * If not, will return 'propel.om.Persistent'.
  108. *
  109. * @return string
  110. */
  111. public static function getInterface(Table $table)
  112. {
  113. $interface = $table->getInterface();
  114. if ($interface === null && !$table->isReadOnly()) {
  115. $interface = "propel.om.Persistent";
  116. }
  117. return $interface;
  118. }
  119. /**
  120. * Gets a list of PHP reserved words.
  121. *
  122. * @return array string[]
  123. */
  124. public static function getPhpReservedWords()
  125. {
  126. return array('and', 'or', 'xor', 'exception', '__FILE__', '__LINE__', 'array', 'as', 'break', 'case', 'class', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'for', 'foreach', 'function', 'global', 'if', 'include', 'include_once', 'isset', 'list', 'new', 'print', 'require', 'require_once', 'return', 'static', 'switch', 'unset', 'use', 'var', 'while', '__FUNCTION__', '__CLASS__', '__METHOD__', 'final', 'php_user_filter', 'interface', 'implements', 'extends', 'public', 'protected', 'private', 'abstract', 'clone', 'try', 'catch', 'throw', 'this', 'namespace', 'yield');
  127. }
  128. }