/gulliver/thirdparty/propel-generator/classes/propel/engine/builder/om/ClassTools.php

https://bitbucket.org/ferOnti/processmaker · PHP · 107 lines · 43 code · 7 blank · 57 comment · 9 complexity · 0e8fb2c5a91a81e2318536c017179237 MD5 · raw file

  1. <?php
  2. /*
  3. * $Id: ClassTools.php 536 2007-01-10 14:30:38Z heltem $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://propel.phpdb.org>.
  20. */
  21. /**
  22. * Tools to support class & package inclusion and referencing.
  23. *
  24. * @author Hans Lellelid <hans@xmpl.org>
  25. * @version $Revision: 536 $
  26. * @package propel.engine.builder.om
  27. */
  28. class ClassTools {
  29. /**
  30. * Gets just classname, given a dot-path to class.
  31. * @param string $qualifiedName
  32. * @return string
  33. */
  34. public static function classname($qualifiedName)
  35. {
  36. $pos = strrpos($qualifiedName, '.');
  37. if ($pos === false) {
  38. return $qualifiedName; // there is no '.' in the qualifed name
  39. } else {
  40. return substr($qualifiedName, $pos + 1); // start just after '.'
  41. }
  42. }
  43. /**
  44. * Gets the path to be used in include()/require() statement.
  45. *
  46. * Supports two function signatures:
  47. * (1) getFilePath($dotPathClass);
  48. * (2) getFilePath($dotPathPrefix, $className);
  49. *
  50. * @param string $path dot-path to class or to package prefix.
  51. * @param string $classname class name
  52. * @return string
  53. */
  54. public static function getFilePath($path, $classname = null, $extension = '.php')
  55. {
  56. $path = strtr(ltrim($path, '.'), '.', '/');
  57. if ($classname !== null) {
  58. if ($path !== "") { $path .= '/'; }
  59. return $path . $classname . $extension;
  60. } else {
  61. return $path . $extension;
  62. }
  63. }
  64. /**
  65. * Gets the basePeer path if specified for table/db.
  66. * If not, will return 'propel.util.BasePeer'
  67. * @return string
  68. */
  69. public static function getBasePeer(Table $table) {
  70. $class = $table->getBasePeer();
  71. if ($class === null) {
  72. $class = "propel.util.BasePeer";
  73. }
  74. return $class;
  75. }
  76. /**
  77. * Gets the baseClass path if specified for table/db.
  78. * If not, will return 'propel.om.BaseObject'
  79. * @return string
  80. */
  81. public static function getBaseClass(Table $table) {
  82. $class = $table->getBaseClass();
  83. if ($class === null) {
  84. $class = "propel.om.BaseObject";
  85. }
  86. return $class;
  87. }
  88. /**
  89. * Gets the interface path if specified for table.
  90. * If not, will return 'propel.om.Persistent'.
  91. * @return string
  92. */
  93. public static function getInterface(Table $table) {
  94. $interface = $table->getInterface();
  95. if ($interface === null && !$table->isReadOnly()) {
  96. $interface = "propel.om.Persistent";
  97. }
  98. return $interface;
  99. }
  100. }