/src/Propel/Generator/Builder/Om/ExtensionQueryInheritanceBuilder.php

https://github.com/propelorm/Propel2 · PHP · 152 lines · 52 code · 15 blank · 85 comment · 2 complexity · c7930520d673253ffe35e95a1a2ffb8c MD5 · raw file

  1. <?php
  2. /**
  3. * MIT License. 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. namespace Propel\Generator\Builder\Om;
  8. use Propel\Generator\Exception\BuildException;
  9. use Propel\Generator\Model\Inheritance;
  10. /**
  11. * Generates the empty stub query class for use with single table inheritance.
  12. *
  13. * This class produces the empty stub class that can be customized with
  14. * application business logic, custom behavior, etc.
  15. *
  16. * @author François Zaninotto
  17. */
  18. class ExtensionQueryInheritanceBuilder extends AbstractOMBuilder
  19. {
  20. /**
  21. * The current child "object" we are operating on.
  22. *
  23. * @var \Propel\Generator\Model\Inheritance|null
  24. */
  25. protected $child;
  26. /**
  27. * Returns the name of the current class being built.
  28. *
  29. * @return string
  30. */
  31. public function getUnprefixedClassName(): string
  32. {
  33. return $this->getChild()->getClassName() . 'Query';
  34. }
  35. /**
  36. * Gets the package for the [base] object classes.
  37. *
  38. * @return string|null
  39. */
  40. public function getPackage(): ?string
  41. {
  42. return ($this->getChild()->getPackage() ?: parent::getPackage());
  43. }
  44. /**
  45. * Set the child object that we're operating on currently.
  46. *
  47. * @param \Propel\Generator\Model\Inheritance $child Inheritance
  48. *
  49. * @return void
  50. */
  51. public function setChild(Inheritance $child): void
  52. {
  53. $this->child = $child;
  54. }
  55. /**
  56. * Returns the child object we're operating on currently.
  57. *
  58. * @throws \Propel\Generator\Exception\BuildException
  59. *
  60. * @return \Propel\Generator\Model\Inheritance
  61. */
  62. public function getChild(): Inheritance
  63. {
  64. if (!$this->child) {
  65. throw new BuildException('The MultiExtendObjectBuilder needs to be told which child class to build (via setChild() method) before it can build the stub class.');
  66. }
  67. return $this->child;
  68. }
  69. /**
  70. * Adds class phpdoc comment and opening of class.
  71. *
  72. * @param string $script The script will be modified in this method.
  73. *
  74. * @return void
  75. */
  76. protected function addClassOpen(string &$script): void
  77. {
  78. $table = $this->getTable();
  79. $tableName = $table->getName();
  80. $tableDesc = $table->getDescription();
  81. $baseBuilder = $this->getNewQueryInheritanceBuilder($this->getChild());
  82. $baseClassName = $this->getClassNameFromBuilder($baseBuilder);
  83. if ($this->getBuildProperty('generator.objectModel.addClassLevelComment')) {
  84. $script .= "
  85. /**
  86. * Skeleton subclass for representing a query for one of the subclasses of the '$tableName' table.
  87. *
  88. * $tableDesc
  89. *";
  90. if ($this->getBuildProperty('generator.objectModel.addTimeStamp')) {
  91. $now = strftime('%c');
  92. $script .= "
  93. * This class was autogenerated by Propel " . $this->getBuildProperty('general.version') . " on:
  94. *
  95. * $now
  96. *";
  97. }
  98. $script .= "
  99. * You should add additional methods to this class to meet the
  100. * application requirements. This class will only be generated as
  101. * long as it does not already exist in the output directory.
  102. */";
  103. }
  104. $script .= "
  105. class " . $this->getUnqualifiedClassName() . ' extends ' . $baseClassName . "
  106. {
  107. ";
  108. }
  109. /**
  110. * Specifies the methods that are added as part of the stub object class.
  111. *
  112. * By default there are no methods for the empty stub classes; override this method
  113. * if you want to change that behavior.
  114. *
  115. * @see ObjectBuilder::addClassBody()
  116. *
  117. * @param string $script
  118. *
  119. * @return void
  120. */
  121. protected function addClassBody(string &$script): void
  122. {
  123. }
  124. /**
  125. * Closes class.
  126. *
  127. * @param string $script
  128. *
  129. * @return void
  130. */
  131. protected function addClassClose(string &$script): void
  132. {
  133. $script .= "
  134. }
  135. ";
  136. }
  137. }