PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/propel/generator/lib/builder/om/PHP5ObjectBuilder.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 5550 lines | 3375 code | 526 blank | 1649 comment | 396 complexity | 7ded4b9b240204e5f107edf31b0b2cf0 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause

Large files files are truncated, but you can click here to view the full 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. require_once dirname(__FILE__) . '/ObjectBuilder.php';
  10. /**
  11. * Generates a PHP5 base Object class for user object model (OM).
  12. *
  13. * This class produces the base object class (e.g. BaseMyTable) which contains all
  14. * the custom-built accessor and setter methods.
  15. *
  16. * @author Hans Lellelid <hans@xmpl.org>
  17. * @package propel.generator.builder.om
  18. */
  19. class PHP5ObjectBuilder extends ObjectBuilder
  20. {
  21. /**
  22. * Gets the package for the [base] object classes.
  23. * @return string
  24. */
  25. public function getPackage()
  26. {
  27. return parent::getPackage() . ".om";
  28. }
  29. public function getNamespace()
  30. {
  31. if ($namespace = parent::getNamespace()) {
  32. if ($this->getGeneratorConfig() && $omns = $this->getGeneratorConfig()->getBuildProperty('namespaceOm')) {
  33. return $namespace . '\\' . $omns;
  34. } else {
  35. return $namespace;
  36. }
  37. }
  38. }
  39. /**
  40. * Returns default key type. if not presented in configuration default will be 'TYPE_PHPNAME'
  41. * @return string
  42. */
  43. public function getDefaultKeyType()
  44. {
  45. $defaultKeyType = $this->getBuildProperty('defaultKeyType') ? $this->getBuildProperty('defaultKeyType') : 'phpName';
  46. return "TYPE_".strtoupper($defaultKeyType);
  47. }
  48. /**
  49. * Returns the name of the current class being built.
  50. * @return string
  51. */
  52. public function getUnprefixedClassname()
  53. {
  54. return $this->getBuildProperty('basePrefix') . $this->getStubObjectBuilder()->getUnprefixedClassname();
  55. }
  56. /**
  57. * Validates the current table to make sure that it won't
  58. * result in generated code that will not parse.
  59. *
  60. * This method may emit warnings for code which may cause problems
  61. * and will throw exceptions for errors that will definitely cause
  62. * problems.
  63. */
  64. protected function validateModel()
  65. {
  66. parent::validateModel();
  67. $table = $this->getTable();
  68. // Check to see whether any generated foreign key names
  69. // will conflict with column names.
  70. $colPhpNames = array();
  71. $fkPhpNames = array();
  72. foreach ($table->getColumns() as $col) {
  73. $colPhpNames[] = $col->getPhpName();
  74. }
  75. foreach ($table->getForeignKeys() as $fk) {
  76. $fkPhpNames[] = $this->getFKPhpNameAffix($fk, $plural = false);
  77. }
  78. $intersect = array_intersect($colPhpNames, $fkPhpNames);
  79. if (!empty($intersect)) {
  80. throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with foreign key names (" . implode(", ", $intersect) . ")");
  81. }
  82. // Check foreign keys to see if there are any foreign keys that
  83. // are also matched with an inversed referencing foreign key
  84. // (this is currently unsupported behavior)
  85. // see: http://propel.phpdb.org/trac/ticket/549
  86. foreach ($table->getForeignKeys() as $fk) {
  87. if ($fk->isMatchedByInverseFK()) {
  88. throw new EngineException("The 1:1 relationship expressed by foreign key " . $fk->getName() . " is defined in both directions; Propel does not currently support this (if you must have both foreign key constraints, consider adding this constraint with a custom SQL file.)" );
  89. }
  90. }
  91. }
  92. /**
  93. * Returns the appropriate formatter (from platform) for a date/time column.
  94. * @param Column $col
  95. * @return string
  96. */
  97. protected function getTemporalFormatter(Column $col)
  98. {
  99. $fmt = null;
  100. if ($col->getType() === PropelTypes::DATE) {
  101. $fmt = $this->getPlatform()->getDateFormatter();
  102. } elseif ($col->getType() === PropelTypes::TIME) {
  103. $fmt = $this->getPlatform()->getTimeFormatter();
  104. } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
  105. $fmt = $this->getPlatform()->getTimestampFormatter();
  106. }
  107. return $fmt;
  108. }
  109. /**
  110. * Returns the type-casted and stringified default value for the specified Column.
  111. * This only works for scalar default values currently.
  112. * @return string The default value or 'NULL' if there is none.
  113. * @throws EngineException
  114. */
  115. protected function getDefaultValueString(Column $col)
  116. {
  117. $defaultValue = var_export(null, true);
  118. $val = $col->getPhpDefaultValue();
  119. if ($val === null) {
  120. return $defaultValue;
  121. }
  122. if ($col->isTemporalType()) {
  123. $fmt = $this->getTemporalFormatter($col);
  124. try {
  125. if (!($this->getPlatform() instanceof MysqlPlatform &&
  126. ($val === '0000-00-00 00:00:00' || $val === '0000-00-00'))) {
  127. // while technically this is not a default value of NULL,
  128. // this seems to be closest in meaning.
  129. $defDt = new DateTime($val);
  130. $defaultValue = var_export($defDt->format($fmt), true);
  131. }
  132. } catch (Exception $x) {
  133. // prevent endless loop when timezone is undefined
  134. date_default_timezone_set('America/Los_Angeles');
  135. throw new EngineException(sprintf('Unable to parse default temporal value "%s" for column "%s"', $col->getDefaultValueString(), $col->getFullyQualifiedName()), $x);
  136. }
  137. } elseif ($col->isEnumType()) {
  138. $valueSet = $col->getValueSet();
  139. if (!in_array($val, $valueSet)) {
  140. throw new EngineException(sprintf('Default Value "%s" is not among the enumerated values', $val));
  141. }
  142. $defaultValue = array_search($val, $valueSet);
  143. } elseif ($col->isPhpPrimitiveType()) {
  144. settype($val, $col->getPhpType());
  145. $defaultValue = var_export($val, true);
  146. } elseif ($col->isPhpObjectType()) {
  147. $defaultValue = 'new '.$col->getPhpType().'(' . var_export($val, true) . ')';
  148. } elseif ($col->isPhpArrayType()) {
  149. $defaultValue = var_export($val, true);
  150. } else {
  151. throw new EngineException("Cannot get default value string for " . $col->getFullyQualifiedName());
  152. }
  153. return $defaultValue;
  154. }
  155. /**
  156. * Adds the include() statements for files that this class depends on or utilizes.
  157. * @param string &$script The script will be modified in this method.
  158. */
  159. protected function addIncludes(&$script)
  160. {
  161. } // addIncludes()
  162. /**
  163. * Adds class phpdoc comment and openning of class.
  164. * @param string &$script The script will be modified in this method.
  165. */
  166. protected function addClassOpen(&$script)
  167. {
  168. $table = $this->getTable();
  169. $tableName = $table->getName();
  170. $tableDesc = $table->getDescription();
  171. $interface = $this->getInterface();
  172. $parentClass = $this->getBehaviorContent('parentClass');
  173. $parentClass = (null !== $parentClass) ? $parentClass : ClassTools::classname($this->getBaseClass());
  174. $script .= "
  175. /**
  176. * Base class that represents a row from the '$tableName' table.
  177. *
  178. * $tableDesc
  179. *";
  180. if ($this->getBuildProperty('addTimeStamp')) {
  181. $now = strftime('%c');
  182. $script .= "
  183. * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
  184. *
  185. * $now
  186. *";
  187. }
  188. $script .= "
  189. * @package propel.generator.".$this->getPackage()."
  190. */
  191. abstract class ".$this->getClassname()." extends ".$parentClass." ";
  192. if ($interface = $this->getTable()->getInterface()) {
  193. $script .= "implements " . ClassTools::classname($interface);
  194. if ($interface !== ClassTools::classname($interface)) {
  195. $this->declareClass($interface);
  196. } else {
  197. $this->declareClassFromBuilder($this->getInterfaceBuilder());
  198. }
  199. } elseif ($interface = ClassTools::getInterface($table)) {
  200. $script .= "implements " . ClassTools::classname($interface);
  201. }
  202. $script .= "
  203. {
  204. ";
  205. }
  206. /**
  207. * Specifies the methods that are added as part of the basic OM class.
  208. * This can be overridden by subclasses that wish to add more methods.
  209. * @see ObjectBuilder::addClassBody()
  210. */
  211. protected function addClassBody(&$script)
  212. {
  213. $this->declareClassFromBuilder($this->getStubObjectBuilder());
  214. $this->declareClassFromBuilder($this->getStubPeerBuilder());
  215. $this->declareClassFromBuilder($this->getStubQueryBuilder());
  216. $this->declareClasses('Propel', 'PropelException', 'PDO', 'PropelPDO', 'Criteria', 'BaseObject', 'Persistent', 'BasePeer', 'PropelCollection', 'PropelObjectCollection', 'Exception');
  217. $table = $this->getTable();
  218. if (!$table->isAlias()) {
  219. $this->addConstants($script);
  220. $this->addAttributes($script);
  221. }
  222. if ($table->hasCrossForeignKeys()) {
  223. foreach ($table->getCrossFks() as $fkList) {
  224. list($refFK, $crossFK) = $fkList;
  225. $fkName = $this->getFKPhpNameAffix($crossFK, $plural = true);
  226. $this->addScheduledForDeletionAttribute($script, $fkName);
  227. }
  228. }
  229. foreach ($table->getReferrers() as $refFK) {
  230. $fkName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
  231. $this->addScheduledForDeletionAttribute($script, $fkName);
  232. }
  233. if ($this->hasDefaultValues()) {
  234. $this->addApplyDefaultValues($script);
  235. $this->addConstructor($script);
  236. }
  237. $this->addColumnAccessorMethods($script);
  238. $this->addColumnMutatorMethods($script);
  239. $this->addHasOnlyDefaultValues($script);
  240. $this->addHydrate($script);
  241. $this->addEnsureConsistency($script);
  242. if (!$table->isReadOnly()) {
  243. $this->addManipulationMethods($script);
  244. }
  245. if ($this->isAddValidateMethod()) {
  246. $this->addValidationMethods($script);
  247. }
  248. if ($this->isAddGenericAccessors()) {
  249. $this->addGetByName($script);
  250. $this->addGetByPosition($script);
  251. $this->addToArray($script);
  252. }
  253. if ($this->isAddGenericMutators()) {
  254. $this->addSetByName($script);
  255. $this->addSetByPosition($script);
  256. $this->addFromArray($script);
  257. }
  258. $this->addBuildCriteria($script);
  259. $this->addBuildPkeyCriteria($script);
  260. $this->addGetPrimaryKey($script);
  261. $this->addSetPrimaryKey($script);
  262. $this->addIsPrimaryKeyNull($script);
  263. $this->addCopy($script);
  264. if (!$table->isAlias()) {
  265. $this->addGetPeer($script);
  266. }
  267. $this->addFKMethods($script);
  268. $this->addRefFKMethods($script);
  269. $this->addCrossFKMethods($script);
  270. $this->addClear($script);
  271. $this->addClearAllReferences($script);
  272. $this->addPrimaryString($script);
  273. $this->addIsAlreadyInSave($script);
  274. // apply behaviors
  275. $this->applyBehaviorModifier('objectMethods', $script, " ");
  276. $this->addMagicCall($script);
  277. }
  278. /**
  279. * Closes class.
  280. * @param string &$script The script will be modified in this method.
  281. */
  282. protected function addClassClose(&$script)
  283. {
  284. $script .= "
  285. } // " . $this->getClassname() . "
  286. ";
  287. $this->applyBehaviorModifier('objectFilter', $script, "");
  288. }
  289. /**
  290. * Adds any constants to the class.
  291. * @param string &$script The script will be modified in this method.
  292. */
  293. protected function addConstants(&$script)
  294. {
  295. $script .= "
  296. /**
  297. * Peer class name
  298. */
  299. const PEER = '" . addslashes($this->getStubPeerBuilder()->getFullyQualifiedClassname()) . "';
  300. ";
  301. }
  302. /**
  303. * Adds class attributes.
  304. * @param string &$script The script will be modified in this method.
  305. */
  306. protected function addAttributes(&$script)
  307. {
  308. $table = $this->getTable();
  309. $script .= "
  310. /**
  311. * The Peer class.
  312. * Instance provides a convenient way of calling static methods on a class
  313. * that calling code may not be able to identify.
  314. * @var ".$this->getPeerClassname()."
  315. */
  316. protected static \$peer;
  317. /**
  318. * The flag var to prevent infinit loop in deep copy
  319. * @var boolean
  320. */
  321. protected \$startCopy = false;
  322. ";
  323. if (!$table->isAlias()) {
  324. $this->addColumnAttributes($script);
  325. }
  326. foreach ($table->getForeignKeys() as $fk) {
  327. $this->addFKAttributes($script, $fk);
  328. }
  329. foreach ($table->getReferrers() as $refFK) {
  330. $this->addRefFKAttributes($script, $refFK);
  331. }
  332. // many-to-many relationships
  333. foreach ($table->getCrossFks() as $fkList) {
  334. $crossFK = $fkList[1];
  335. $this->addCrossFKAttributes($script, $crossFK);
  336. }
  337. $this->addAlreadyInSaveAttribute($script);
  338. $this->addAlreadyInValidationAttribute($script);
  339. // apply behaviors
  340. $this->applyBehaviorModifier('objectAttributes', $script, " ");
  341. }
  342. /**
  343. * Adds variables that store column values.
  344. * @param string &$script The script will be modified in this method.
  345. * @see addColumnNameConstants()
  346. */
  347. protected function addColumnAttributes(&$script)
  348. {
  349. $table = $this->getTable();
  350. foreach ($table->getColumns() as $col) {
  351. $this->addColumnAttributeComment($script, $col);
  352. $this->addColumnAttributeDeclaration($script, $col);
  353. if ($col->isLazyLoad() ) {
  354. $this->addColumnAttributeLoaderComment($script, $col);
  355. $this->addColumnAttributeLoaderDeclaration($script, $col);
  356. }
  357. if ($col->getType() == PropelTypes::OBJECT || $col->getType() == PropelTypes::PHP_ARRAY) {
  358. $this->addColumnAttributeUnserializedComment($script, $col);
  359. $this->addColumnAttributeUnserializedDeclaration($script, $col);
  360. }
  361. }
  362. }
  363. /**
  364. * Add comment about the attribute (variable) that stores column values
  365. * @param string &$script The script will be modified in this method.
  366. * @param Column $col
  367. **/
  368. protected function addColumnAttributeComment(&$script, Column $col)
  369. {
  370. $cptype = $col->getPhpType();
  371. $clo = strtolower($col->getName());
  372. $script .= "
  373. /**
  374. * The value for the $clo field.";
  375. if ($col->getDefaultValue()) {
  376. if ($col->getDefaultValue()->isExpression()) {
  377. $script .= "
  378. * Note: this column has a database default value of: (expression) ".$col->getDefaultValue()->getValue();
  379. } else {
  380. $script .= "
  381. * Note: this column has a database default value of: ". $this->getDefaultValueString($col);
  382. }
  383. }
  384. $script .= "
  385. * @var $cptype
  386. */";
  387. }
  388. /**
  389. * Adds the declaration of a column value storage attribute
  390. * @param string &$script The script will be modified in this method.
  391. * @param Column $col
  392. **/
  393. protected function addColumnAttributeDeclaration(&$script, Column $col)
  394. {
  395. $clo = strtolower($col->getName());
  396. $script .= "
  397. protected \$" . $clo . ";
  398. ";
  399. }
  400. /**
  401. * Adds the comment about the attribute keeping track if an attribute value has been loaded
  402. * @param string &$script The script will be modified in this method.
  403. * @param Column $col
  404. **/
  405. protected function addColumnAttributeLoaderComment(&$script, Column $col)
  406. {
  407. $clo = strtolower($col->getName());
  408. $script .= "
  409. /**
  410. * Whether the lazy-loaded \$$clo value has been loaded from database.
  411. * This is necessary to avoid repeated lookups if \$$clo column is NULL in the db.
  412. * @var boolean
  413. */";
  414. }
  415. /**
  416. * Adds the declaration of the attribute keeping track of an attribute's loaded state
  417. * @param string &$script The script will be modified in this method.
  418. * @param Column $col
  419. **/
  420. protected function addColumnAttributeLoaderDeclaration(&$script, Column $col)
  421. {
  422. $clo = strtolower($col->getName());
  423. $script .= "
  424. protected \$".$clo."_isLoaded = false;
  425. ";
  426. }
  427. /**
  428. * Adds the comment about the serialized attribute
  429. * @param string &$script The script will be modified in this method.
  430. * @param Column $col
  431. **/
  432. protected function addColumnAttributeUnserializedComment(&$script, Column $col)
  433. {
  434. $clo = strtolower($col->getName());
  435. $script .= "
  436. /**
  437. * The unserialized \$$clo value - i.e. the persisted object.
  438. * This is necessary to avoid repeated calls to unserialize() at runtime.
  439. * @var object
  440. */";
  441. }
  442. /**
  443. * Adds the declaration of the serialized attribute
  444. * @param string &$script The script will be modified in this method.
  445. * @param Column $col
  446. **/
  447. protected function addColumnAttributeUnserializedDeclaration(&$script, Column $col)
  448. {
  449. $clo = strtolower($col->getName()) . "_unserialized";
  450. $script .= "
  451. protected \$" . $clo . ";
  452. ";
  453. }
  454. /**
  455. * Adds the getPeer() method.
  456. * This is a convenient, non introspective way of getting the Peer class for a particular object.
  457. * @param string &$script The script will be modified in this method.
  458. */
  459. protected function addGetPeer(&$script)
  460. {
  461. $this->addGetPeerComment($script);
  462. $this->addGetPeerFunctionOpen($script);
  463. $this->addGetPeerFunctionBody($script);
  464. $this->addGetPeerFunctionClose($script);
  465. }
  466. /**
  467. * Add the comment for the getPeer method
  468. * @param string &$script The script will be modified in this method.
  469. **/
  470. protected function addGetPeerComment(&$script)
  471. {
  472. $script .= "
  473. /**
  474. * Returns a peer instance associated with this om.
  475. *
  476. * Since Peer classes are not to have any instance attributes, this method returns the
  477. * same instance for all member of this class. The method could therefore
  478. * be static, but this would prevent one from overriding the behavior.
  479. *
  480. * @return ".$this->getPeerClassname()."
  481. */";
  482. }
  483. /**
  484. * Adds the function declaration (function opening) for the getPeer method
  485. * @param string &$script The script will be modified in this method.
  486. **/
  487. protected function addGetPeerFunctionOpen(&$script)
  488. {
  489. $script .= "
  490. public function getPeer()
  491. {";
  492. }
  493. /**
  494. * Adds the body of the getPeer method
  495. * @param string &$script The script will be modified in this method.
  496. **/
  497. protected function addGetPeerFunctionBody(&$script)
  498. {
  499. $script .= "
  500. if (self::\$peer === null) {
  501. " . $this->buildObjectInstanceCreationCode('self::$peer', $this->getPeerClassname()) . "
  502. }
  503. return self::\$peer;";
  504. }
  505. /**
  506. * Add the function close for the getPeer method
  507. * Note: this is just a } and the body ends with a return statement, so it's quite useless. But it's here anyway for consisency, cause there's a close function for all functions and in some other instances, they are useful
  508. * @param string &$script The script will be modified in this method.
  509. **/
  510. protected function addGetPeerFunctionClose(&$script)
  511. {
  512. $script .= "
  513. }
  514. ";
  515. }
  516. /**
  517. * Adds the constructor for this object.
  518. * @param string &$script The script will be modified in this method.
  519. * @see addConstructor()
  520. */
  521. protected function addConstructor(&$script)
  522. {
  523. $this->addConstructorComment($script);
  524. $this->addConstructorOpen($script);
  525. $this->addConstructorBody($script);
  526. $this->addConstructorClose($script);
  527. }
  528. /**
  529. * Adds the comment for the constructor
  530. * @param string &$script The script will be modified in this method.
  531. **/
  532. protected function addConstructorComment(&$script)
  533. {
  534. $script .= "
  535. /**
  536. * Initializes internal state of ".$this->getClassname()." object.
  537. * @see applyDefaults()
  538. */";
  539. }
  540. /**
  541. * Adds the function declaration for the constructor
  542. * @param string &$script The script will be modified in this method.
  543. **/
  544. protected function addConstructorOpen(&$script)
  545. {
  546. $script .= "
  547. public function __construct()
  548. {";
  549. }
  550. /**
  551. * Adds the function body for the constructor
  552. * @param string &$script The script will be modified in this method.
  553. **/
  554. protected function addConstructorBody(&$script)
  555. {
  556. $script .= "
  557. parent::__construct();
  558. \$this->applyDefaultValues();";
  559. }
  560. /**
  561. * Adds the function close for the constructor
  562. * @param string &$script The script will be modified in this method.
  563. **/
  564. protected function addConstructorClose(&$script)
  565. {
  566. $script .= "
  567. }
  568. ";
  569. }
  570. /**
  571. * Adds the applyDefaults() method, which is called from the constructor.
  572. * @param string &$script The script will be modified in this method.
  573. * @see addConstructor()
  574. */
  575. protected function addApplyDefaultValues(&$script)
  576. {
  577. $this->addApplyDefaultValuesComment($script);
  578. $this->addApplyDefaultValuesOpen($script);
  579. $this->addApplyDefaultValuesBody($script);
  580. $this->addApplyDefaultValuesClose($script);
  581. }
  582. /**
  583. * Adds the comment for the applyDefaults method
  584. * @param string &$script The script will be modified in this method.
  585. * @see addApplyDefaultValues()
  586. **/
  587. protected function addApplyDefaultValuesComment(&$script)
  588. {
  589. $script .= "
  590. /**
  591. * Applies default values to this object.
  592. * This method should be called from the object's constructor (or
  593. * equivalent initialization method).
  594. * @see __construct()
  595. */";
  596. }
  597. /**
  598. * Adds the function declaration for the applyDefaults method
  599. * @param string &$script The script will be modified in this method.
  600. * @see addApplyDefaultValues()
  601. **/
  602. protected function addApplyDefaultValuesOpen(&$script)
  603. {
  604. $script .= "
  605. public function applyDefaultValues()
  606. {";
  607. }
  608. /**
  609. * Adds the function body of the applyDefault method
  610. * @param string &$script The script will be modified in this method.
  611. * @see addApplyDefaultValues()
  612. **/
  613. protected function addApplyDefaultValuesBody(&$script)
  614. {
  615. $table = $this->getTable();
  616. // FIXME - Apply support for PHP default expressions here
  617. // see: http://propel.phpdb.org/trac/ticket/378
  618. $colsWithDefaults = array();
  619. foreach ($table->getColumns() as $col) {
  620. $def = $col->getDefaultValue();
  621. if ($def !== null && !$def->isExpression()) {
  622. $colsWithDefaults[] = $col;
  623. }
  624. }
  625. $colconsts = array();
  626. foreach ($colsWithDefaults as $col) {
  627. $clo = strtolower($col->getName());
  628. $defaultValue = $this->getDefaultValueString($col);
  629. $script .= "
  630. \$this->".$clo." = $defaultValue;";
  631. }
  632. }
  633. /**
  634. * Adds the function close for the applyDefaults method
  635. * @param string &$script The script will be modified in this method.
  636. * @see addApplyDefaultValues()
  637. **/
  638. protected function addApplyDefaultValuesClose(&$script)
  639. {
  640. $script .= "
  641. }
  642. ";
  643. }
  644. // --------------------------------------------------------------
  645. //
  646. // A C C E S S O R M E T H O D S
  647. //
  648. // --------------------------------------------------------------
  649. /**
  650. * Adds a date/time/timestamp getter method.
  651. * @param string &$script The script will be modified in this method.
  652. * @param Column $col The current column.
  653. * @see parent::addColumnAccessors()
  654. */
  655. protected function addTemporalAccessor(&$script, Column $col)
  656. {
  657. $this->addTemporalAccessorComment($script, $col);
  658. $this->addTemporalAccessorOpen($script, $col);
  659. $this->addTemporalAccessorBody($script, $col);
  660. $this->addTemporalAccessorClose($script, $col);
  661. } // addTemporalAccessor
  662. /**
  663. * Adds the comment for a temporal accessor
  664. * @param string &$script The script will be modified in this method.
  665. * @param Column $col The current column.
  666. * @see addTemporalAccessor
  667. **/
  668. public function addTemporalAccessorComment(&$script, Column $col)
  669. {
  670. $clo = strtolower($col->getName());
  671. $useDateTime = $this->getBuildProperty('useDateTimeClass');
  672. $dateTimeClass = $this->getBuildProperty('dateTimeClass');
  673. if (!$dateTimeClass) {
  674. $dateTimeClass = 'DateTime';
  675. }
  676. $handleMysqlDate = false;
  677. if ($this->getPlatform() instanceof MysqlPlatform) {
  678. if ($col->getType() === PropelTypes::TIMESTAMP) {
  679. $handleMysqlDate = true;
  680. $mysqlInvalidDateString = '0000-00-00 00:00:00';
  681. } elseif ($col->getType() === PropelTypes::DATE) {
  682. $handleMysqlDate = true;
  683. $mysqlInvalidDateString = '0000-00-00';
  684. }
  685. // 00:00:00 is a valid time, so no need to check for that.
  686. }
  687. $script .= "
  688. /**
  689. * Get the [optionally formatted] temporal [$clo] column value.
  690. * ".$col->getDescription();
  691. if (!$useDateTime) {
  692. $script .= "
  693. * This accessor only only work with unix epoch dates. Consider enabling the propel.useDateTimeClass
  694. * option in order to avoid converstions to integers (which are limited in the dates they can express).";
  695. }
  696. $script .= "
  697. *
  698. * @param string \$format The date/time format string (either date()-style or strftime()-style).
  699. * If format is NULL, then the raw ".($useDateTime ? 'DateTime object' : 'unix timestamp integer')." will be returned.";
  700. if ($useDateTime) {
  701. $script .= "
  702. * @return mixed Formatted date/time value as string or $dateTimeClass object (if format is NULL), NULL if column is NULL" .($handleMysqlDate ? ', and 0 if column value is ' . $mysqlInvalidDateString : '');
  703. } else {
  704. $script .= "
  705. * @return mixed Formatted date/time value as string or (integer) unix timestamp (if format is NULL), NULL if column is NULL".($handleMysqlDate ? ', and 0 if column value is ' . $mysqlInvalidDateString : '');
  706. }
  707. $script .= "
  708. * @throws PropelException - if unable to parse/validate the date/time value.
  709. */";
  710. }
  711. /**
  712. * Adds the function declaration for a temporal accessor
  713. * @param string &$script The script will be modified in this method.
  714. * @param Column $col The current column.
  715. * @see addTemporalAccessor
  716. **/
  717. public function addTemporalAccessorOpen(&$script, Column $col)
  718. {
  719. $cfc = $col->getPhpName();
  720. $defaultfmt = null;
  721. $visibility = $col->getAccessorVisibility();
  722. // Default date/time formatter strings are specified in build.properties
  723. if ($col->getType() === PropelTypes::DATE) {
  724. $defaultfmt = $this->getBuildProperty('defaultDateFormat');
  725. } elseif ($col->getType() === PropelTypes::TIME) {
  726. $defaultfmt = $this->getBuildProperty('defaultTimeFormat');
  727. } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
  728. $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
  729. }
  730. if (empty($defaultfmt)) { $defaultfmt = null; }
  731. $script .= "
  732. ".$visibility." function get$cfc(\$format = ".var_export($defaultfmt, true)."";
  733. if ($col->isLazyLoad()) $script .= ", \$con = null";
  734. $script .= ")
  735. {";
  736. }
  737. protected function getAccessorLazyLoadSnippet(Column $col)
  738. {
  739. if ($col->isLazyLoad()) {
  740. $clo = strtolower($col->getName());
  741. $defaultValueString = 'null';
  742. $def = $col->getDefaultValue();
  743. if ($def !== null && !$def->isExpression()) {
  744. $defaultValueString = $this->getDefaultValueString($col);
  745. }
  746. return "
  747. if (!\$this->{$clo}_isLoaded && \$this->{$clo} === {$defaultValueString} && !\$this->isNew()) {
  748. \$this->load{$col->getPhpName()}(\$con);
  749. }
  750. ";
  751. }
  752. }
  753. /**
  754. * Adds the body of the temporal accessor
  755. * @param string &$script The script will be modified in this method.
  756. * @param Column $col The current column.
  757. * @see addTemporalAccessor
  758. **/
  759. protected function addTemporalAccessorBody(&$script, Column $col)
  760. {
  761. $cfc = $col->getPhpName();
  762. $clo = strtolower($col->getName());
  763. $useDateTime = $this->getBuildProperty('useDateTimeClass');
  764. $dateTimeClass = $this->getBuildProperty('dateTimeClass');
  765. if (!$dateTimeClass) {
  766. $dateTimeClass = 'DateTime';
  767. }
  768. $this->declareClasses($dateTimeClass);
  769. $defaultfmt = null;
  770. // Default date/time formatter strings are specified in build.properties
  771. if ($col->getType() === PropelTypes::DATE) {
  772. $defaultfmt = $this->getBuildProperty('defaultDateFormat');
  773. } elseif ($col->getType() === PropelTypes::TIME) {
  774. $defaultfmt = $this->getBuildProperty('defaultTimeFormat');
  775. } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
  776. $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
  777. }
  778. if (empty($defaultfmt)) { $defaultfmt = null; }
  779. $handleMysqlDate = false;
  780. if ($this->getPlatform() instanceof MysqlPlatform) {
  781. if ($col->getType() === PropelTypes::TIMESTAMP) {
  782. $handleMysqlDate = true;
  783. $mysqlInvalidDateString = '0000-00-00 00:00:00';
  784. } elseif ($col->getType() === PropelTypes::DATE) {
  785. $handleMysqlDate = true;
  786. $mysqlInvalidDateString = '0000-00-00';
  787. }
  788. // 00:00:00 is a valid time, so no need to check for that.
  789. }
  790. if ($col->isLazyLoad()) {
  791. $script .= $this->getAccessorLazyLoadSnippet($col);
  792. }
  793. $script .= "
  794. if (\$this->$clo === null) {
  795. return null;
  796. }
  797. ";
  798. if ($handleMysqlDate) {
  799. $script .= "
  800. if (\$this->$clo === '$mysqlInvalidDateString') {
  801. // while technically this is not a default value of NULL,
  802. // this seems to be closest in meaning.
  803. return null;
  804. } else {
  805. try {
  806. \$dt = new $dateTimeClass(\$this->$clo);
  807. } catch (Exception \$x) {
  808. throw new PropelException(\"Internally stored date/time/timestamp value could not be converted to $dateTimeClass: \" . var_export(\$this->$clo, true), \$x);
  809. }
  810. }
  811. ";
  812. } else {
  813. $script .= "
  814. try {
  815. \$dt = new $dateTimeClass(\$this->$clo);
  816. } catch (Exception \$x) {
  817. throw new PropelException(\"Internally stored date/time/timestamp value could not be converted to $dateTimeClass: \" . var_export(\$this->$clo, true), \$x);
  818. }
  819. ";
  820. } // if handleMyqlDate
  821. $script .= "
  822. if (\$format === null) {";
  823. if ($useDateTime) {
  824. $script .= "
  825. // Because propel.useDateTimeClass is TRUE, we return a $dateTimeClass object.
  826. return \$dt;";
  827. } else {
  828. $script .= "
  829. // We cast here to maintain BC in API; obviously we will lose data if we're dealing with pre-/post-epoch dates.
  830. return (int) \$dt->format('U');";
  831. }
  832. $script .= "
  833. } elseif (strpos(\$format, '%') !== false) {
  834. return strftime(\$format, \$dt->format('U'));
  835. } else {
  836. return \$dt->format(\$format);
  837. }";
  838. }
  839. /**
  840. * Adds the body of the temporal accessor
  841. * @param string &$script The script will be modified in this method.
  842. * @param Column $col The current column.
  843. * @see addTemporalAccessorClose
  844. **/
  845. protected function addTemporalAccessorClose(&$script, Column $col)
  846. {
  847. $script .= "
  848. }
  849. ";
  850. }
  851. /**
  852. * Adds an object getter method.
  853. * @param string &$script The script will be modified in this method.
  854. * @param Column $col The current column.
  855. * @see parent::addColumnAccessors()
  856. */
  857. protected function addObjectAccessor(&$script, Column $col)
  858. {
  859. $this->addDefaultAccessorComment($script, $col);
  860. $this->addDefaultAccessorOpen($script, $col);
  861. $this->addObjectAccessorBody($script, $col);
  862. $this->addDefaultAccessorClose($script, $col);
  863. }
  864. /**
  865. * Adds the function body for an object accessor method
  866. * @param string &$script The script will be modified in this method.
  867. * @param Column $col The current column.
  868. * @see addDefaultAccessor()
  869. **/
  870. protected function addObjectAccessorBody(&$script, Column $col)
  871. {
  872. $cfc = $col->getPhpName();
  873. $clo = strtolower($col->getName());
  874. $cloUnserialized = $clo.'_unserialized';
  875. if ($col->isLazyLoad()) {
  876. $script .= $this->getAccessorLazyLoadSnippet($col);
  877. }
  878. $script .= "
  879. if (null == \$this->$cloUnserialized && null !== \$this->$clo) {
  880. \$this->$cloUnserialized = unserialize(\$this->$clo);
  881. }
  882. return \$this->$cloUnserialized;";
  883. }
  884. /**
  885. * Adds an array getter method.
  886. * @param string &$script The script will be modified in this method.
  887. * @param Column $col The current column.
  888. * @see parent::addColumnAccessors()
  889. */
  890. protected function addArrayAccessor(&$script, Column $col)
  891. {
  892. $this->addDefaultAccessorComment($script, $col);
  893. $this->addDefaultAccessorOpen($script, $col);
  894. $this->addArrayAccessorBody($script, $col);
  895. $this->addDefaultAccessorClose($script, $col);
  896. }
  897. /**
  898. * Adds the function body for an array accessor method
  899. * @param string &$script The script will be modified in this method.
  900. * @param Column $col The current column.
  901. * @see addDefaultAccessor()
  902. **/
  903. protected function addArrayAccessorBody(&$script, Column $col)
  904. {
  905. $cfc = $col->getPhpName();
  906. $clo = strtolower($col->getName());
  907. $cloUnserialized = $clo.'_unserialized';
  908. if ($col->isLazyLoad()) {
  909. $script .= $this->getAccessorLazyLoadSnippet($col);
  910. }
  911. $script .= "
  912. if (null === \$this->$cloUnserialized) {
  913. \$this->$cloUnserialized = array();
  914. }
  915. if (!\$this->$cloUnserialized && null !== \$this->$clo) {
  916. \$$cloUnserialized = substr(\$this->$clo, 2, -2);
  917. \$this->$cloUnserialized = \$$cloUnserialized ? explode(' | ', \$$cloUnserialized) : array();
  918. }
  919. return \$this->$cloUnserialized;";
  920. }
  921. /**
  922. * Adds an enum getter method.
  923. * @param string &$script The script will be modified in this method.
  924. * @param Column $col The current column.
  925. * @see parent::addColumnAccessors()
  926. */
  927. protected function addEnumAccessor(&$script, Column $col)
  928. {
  929. $clo = strtolower($col->getName());
  930. $script .= "
  931. /**
  932. * Get the [$clo] column value.
  933. * ".$col->getDescription();
  934. if ($col->isLazyLoad()) {
  935. $script .= "
  936. * @param PropelPDO \$con An optional PropelPDO connection to use for fetching this lazy-loaded column.";
  937. }
  938. $script .= "
  939. * @return ".$col->getPhpType()."
  940. * @throws PropelException - if the stored enum key is unknown.
  941. */";
  942. $this->addDefaultAccessorOpen($script, $col);
  943. $this->addEnumAccessorBody($script, $col);
  944. $this->addDefaultAccessorClose($script, $col);
  945. }
  946. /**
  947. * Adds the function body for an enum accessor method
  948. * @param string &$script The script will be modified in this method.
  949. * @param Column $col The current column.
  950. * @see addDefaultAccessor()
  951. **/
  952. protected function addEnumAccessorBody(&$script, Column $col)
  953. {
  954. $cfc = $col->getPhpName();
  955. $clo = strtolower($col->getName());
  956. if ($col->isLazyLoad()) {
  957. $script .= $this->getAccessorLazyLoadSnippet($col);
  958. }
  959. $script .= "
  960. if (null === \$this->$clo) {
  961. return null;
  962. }
  963. \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . ");
  964. if (!isset(\$valueSet[\$this->$clo])) {
  965. throw new PropelException('Unknown stored enum key: ' . \$this->$clo);
  966. }
  967. return \$valueSet[\$this->$clo];";
  968. }
  969. /**
  970. * Adds a tester method for an array column.
  971. * @param string &$script The script will be modified in this method.
  972. * @param Column $col The current column.
  973. */
  974. protected function addHasArrayElement(&$script, Column $col)
  975. {
  976. $clo = strtolower($col->getName());
  977. $cfc = $col->getPhpName();
  978. $visibility = $col->getAccessorVisibility();
  979. $singularPhpName = rtrim($cfc, 's');
  980. $script .= "
  981. /**
  982. * Test the presence of a value in the [$clo] array column value.
  983. * @param mixed \$value
  984. * ".$col->getDescription();
  985. if ($col->isLazyLoad()) {
  986. $script .= "
  987. * @param PropelPDO \$con An optional PropelPDO connection to use for fetching this lazy-loaded column.";
  988. }
  989. $script .= "
  990. * @return boolean
  991. */
  992. $visibility function has$singularPhpName(\$value";
  993. if ($col->isLazyLoad()) $script .= ", PropelPDO \$con = null";
  994. $script .= ")
  995. {
  996. return in_array(\$value, \$this->get$cfc(";
  997. if ($col->isLazyLoad()) $script .= "\$con";
  998. $script .= "));
  999. } // has$singularPhpName()
  1000. ";
  1001. }
  1002. /**
  1003. * Adds a normal (non-temporal) getter method.
  1004. * @param string &$script The script will be modified in this method.
  1005. * @param Column $col The current column.
  1006. * @see parent::addColumnAccessors()
  1007. */
  1008. protected function addDefaultAccessor(&$script, Column $col)
  1009. {
  1010. $this->addDefaultAccessorComment($script, $col);
  1011. $this->addDefaultAccessorOpen($script, $col);
  1012. $this->addDefaultAccessorBody($script, $col);
  1013. $this->addDefaultAccessorClose($script, $col);
  1014. }
  1015. /**
  1016. * Add the comment for a default accessor method (a getter)
  1017. * @param string &$script The script will be modified in this method.
  1018. * @param Column $col The current column.
  1019. * @see addDefaultAccessor()
  1020. **/
  1021. public function addDefaultAccessorComment(&$script, Column $col)
  1022. {
  1023. $clo=strtolower($col->getName());
  1024. $script .= "
  1025. /**
  1026. * Get the [$clo] column value.
  1027. * ".$col->getDescription();
  1028. if ($col->isLazyLoad()) {
  1029. $script .= "
  1030. * @param PropelPDO \$con An optional PropelPDO connection to use for fetching this lazy-loaded column.";
  1031. }
  1032. $script .= "
  1033. * @return ".$col->getPhpType()."
  1034. */";
  1035. }
  1036. /**
  1037. * Adds the function declaration for a default accessor
  1038. * @param string &$script The script will be modified in this method.
  1039. * @param Column $col The current column.
  1040. * @see addDefaultAccessor()
  1041. **/
  1042. public function addDefaultAccessorOpen(&$script, Column $col)
  1043. {
  1044. $cfc = $col->getPhpName();
  1045. $visibility = $col->getAccessorVisibility();
  1046. $script .= "
  1047. ".$visibility." function get$cfc(";
  1048. if ($col->isLazyLoad()) $script .= "PropelPDO \$con = null";
  1049. $script .= ")
  1050. {";
  1051. }
  1052. /**
  1053. * Adds the function body for a default accessor method
  1054. * @param string &$script The script will be modified in this method.
  1055. * @param Column $col The current column.
  1056. * @see addDefaultAccessor()
  1057. **/
  1058. protected function addDefaultAccessorBody(&$script, Column $col)
  1059. {
  1060. $cfc = $col->getPhpName();
  1061. $clo = strtolower($col->getName());
  1062. if ($col->isLazyLoad()) {
  1063. $script .= $this->getAccessorLazyLoadSnippet($col);
  1064. }
  1065. $script .= "
  1066. return \$this->$clo;";
  1067. }
  1068. /**
  1069. * Adds the function close for a default accessor method
  1070. * @param string &$script The script will be modified in this method.
  1071. * @param Column $col The current column.
  1072. * @see addDefaultAccessor()
  1073. **/
  1074. protected function addDefaultAccessorClose(&$script, Column $col)
  1075. {
  1076. $script .= "
  1077. }
  1078. ";
  1079. }
  1080. /**
  1081. * Adds the lazy loader method.
  1082. * @param string &$script The script will be modified in this method.
  1083. * @param Column $col The current column.
  1084. * @see parent::addColumnAccessors()
  1085. */
  1086. protected function addLazyLoader(&$script, Column $col)
  1087. {
  1088. $this->addLazyLoaderComment($script, $col);
  1089. $this->addLazyLoaderOpen($script, $col);
  1090. $this->addLazyLoaderBody($script, $col);
  1091. $this->addLazyLoaderClose($script, $col);
  1092. }
  1093. /**
  1094. * Adds the comment for the lazy loader method
  1095. * @param string &$script The script will be modified in this method.
  1096. * @param Column $col The current column.
  1097. * @see addLazyLoader()
  1098. **/
  1099. protected function addLazyLoaderComment(&$script, Column $col)
  1100. {
  1101. $clo = strtolower($col->getName());
  1102. $script .= "
  1103. /**
  1104. * Load the value for the lazy-loaded [$clo] column.
  1105. *
  1106. * This method performs an additional query to return the value for
  1107. * the [$clo] column, since it is not populated by
  1108. * the hydrate() method.
  1109. *
  1110. * @param PropelPDO \$con (optional) The PropelPDO connection to use.
  1111. * @return void
  1112. * @throws PropelException - any underlying error will be wrapped and re-thrown.
  1113. */";
  1114. }
  1115. /**
  1116. * Adds the function declaration for the lazy loader method
  1117. * @param string &$script The script will be modified in this method.
  1118. * @param Column $col The current column.
  1119. * @see addLazyLoader()
  1120. **/
  1121. protected function addLazyLoaderOpen(&$script, Column $col)
  1122. {
  1123. $cfc = $col->getPhpName();
  1124. $script .= "
  1125. protected function load$cfc(PropelPDO \$con = null)
  1126. {";
  1127. }
  1128. /**
  1129. * Adds the function body for the lazy loader method
  1130. * @param string &$script The script will be modified in this method.
  1131. * @param Column $col The current column.
  1132. * @see addLazyLoader()
  1133. **/
  1134. protected function addLazyLoaderBody(&$script, Column $col)
  1135. {
  1136. $platform = $this->getPlatform();
  1137. $clo = strtolower($col->getName());
  1138. // pdo_sqlsrv driver requires the use of PDOStatement::bindColumn() or a hex string will be returned
  1139. if ($col->getType() === PropelTypes::BLOB && $platform instanceof SqlsrvPlatform) {
  1140. $script .= "
  1141. \$c = \$this->buildPkeyCriteria();
  1142. \$c->addSelectColumn(".$this->getColumnConstant($col).");
  1143. try {
  1144. \$row = array(0 => null);
  1145. \$stmt = ".$this->getPeerClassname()."::doSelectStmt(\$c, \$con);
  1146. \$stmt->bindColumn(1, \$row[0], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
  1147. \$stmt->fetch(PDO::FETCH_BOUND);
  1148. \$stmt->closeCursor();";
  1149. } else {
  1150. $script .= "
  1151. \$c = \$this->buildPkeyCriteria();
  1152. \$c->addSelectColumn(".$this->getColumnConstant($col).");
  1153. try {
  1154. \$stmt = ".$this->getPeerClassname()."::doSelectStmt(\$c, \$con);
  1155. \$row = \$stmt->fetch(PDO::FETCH_NUM);
  1156. \$stmt->closeCursor();";
  1157. }
  1158. if ($col->getType() === PropelTypes::CLOB && $platform instanceof OraclePlatform) {
  1159. // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string...
  1160. $script .= "
  1161. \$this->$clo = stream_get_contents(\$row[0]);";
  1162. } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) {
  1163. $script .= "
  1164. if (\$row[0] !== null) {
  1165. \$this->$clo = fopen('php://memory', 'r+');
  1166. fwrite(\$this->$clo, \$row[0]);
  1167. rewind(\$this->$clo);
  1168. } else {
  1169. \$this->$clo = null;
  1170. }";
  1171. } elseif ($col->isPhpPrimitiveType()) {
  1172. $script .= "
  1173. \$this->$clo = (\$row[0] !== null) ? (".$col->getPhpType().") \$row[0] : null;";
  1174. } elseif ($col->isPhpObjectType()) {
  1175. $script .= "
  1176. \$this->$clo = (\$row[0] !== null) ? new ".$col->getPhpType()."(\$row[0]) : null;";
  1177. } else {
  1178. $script .= "
  1179. \$this->$clo = \$row[0];";
  1180. }
  1181. $script .= "
  1182. \$this->".$clo."_isLoaded = true;
  1183. } catch (Exception \$e) {
  1184. throw new PropelException(\"Error loading value for [$clo] column on demand.\", \$e);
  1185. }";
  1186. }
  1187. /**
  1188. * Adds the function close for the lazy loader
  1189. * @param string &$script The script will be modified in this method.
  1190. * @param Column $col The current column.
  1191. * @see addLazyLoader()
  1192. **/
  1193. protected function addLazyLoaderClose(&$script, Column $col)
  1194. {
  1195. $script .= "
  1196. }";
  1197. } // addLazyLoader()
  1198. // --------------------------------------------------------------
  1199. //
  1200. // M U T A T O R M E T H O D S
  1201. //
  1202. // --------------------------------------------------------------
  1203. /**
  1204. * Adds the open of the mutator (setter) method for a column.
  1205. * @param string &$script The script will be modified in this method.
  1206. * @param Column $col The current column.
  1207. */
  1208. protected function addMutatorOpen(&$script, Column $col)
  1209. {
  1210. $this->addMutatorComment($script, $col);
  1211. $this->addMutatorOpenOpen($script, $col);
  1212. $this->addMutatorOpenBody($script, $col);
  1213. }
  1214. /**
  1215. * Adds the comment for a mutator
  1216. * @param string &$script The script will be modified in this method.
  1217. * @param Column $col The current column.
  1218. * @see addMutatorOpen()
  1219. **/
  1220. public function addMutatorComment(&$script, Column $col)
  1221. {
  1222. $clo = strtolower($col->getName());
  1223. $script .= "
  1224. /**
  1225. * Set the value of [$clo] column.
  1226. * ".$col->getDescription()."
  1227. * @param ".$col->getPhpType()." \$v new value
  1228. * @return ".$this->getObjectClassname()." The current object (for fluent API support)
  1229. */";
  1230. }
  1231. /**
  1232. * Adds the mutator function declaration
  1233. * @param string &$script The script will be modified in this method.
  1234. * @param Column $col The current column.
  1235. * @see addMutatorOpen()
  1236. **/
  1237. public function addMutatorOpenOpen(&$script, Column $col)
  1238. {
  1239. $cfc = $col->getPhpName();
  1240. $visibility = $col->getMutatorVisibility();
  1241. $script .= "
  1242. ".$visibility." function set$cfc(\$v)
  1243. {";
  1244. }
  1245. /**
  1246. * Adds the mutator open body part
  1247. * @param string &$script The script will be modified in this method.
  1248. * @param Column $col The current column.
  1249. * @see addMutatorOpen()
  1250. **/
  1251. protected function addMutatorOpenBody(&$script, Column $col)
  1252. {
  1253. $clo = strtolower($col->getName());
  1254. $cfc = $col->getPhpName();
  1255. if ($col->isLazyLoad()) {
  1256. $script .= "
  1257. // explicitly set the is-loaded flag to true for this lazy load col;
  1258. // it doesn't matter if the value is actually set or not (logic below) as
  1259. // any attempt to set the value means that no db lookup should be performed
  1260. // when the get$cfc() method is called.
  1261. \$this->".$clo."_isLoaded = true;
  1262. ";
  1263. }
  1264. }
  1265. /**
  1266. * Adds the close of the mutator (setter) method for a column.
  1267. *
  1268. * @param string &$script The script will be modified in this method.
  1269. * @param Column $col The current column.
  1270. */
  1271. protected function addMutatorClose(&$script, Column $col)
  1272. {
  1273. $this->addMutatorCloseBody($script, $col);
  1274. $this->addMutatorCloseClose($script, $col);
  1275. }
  1276. /**
  1277. * Adds the body of the close part of a mutator
  1278. * @param string &$script The script will be modified in this method.
  1279. * @param Column $col The current column.
  1280. * @see addMutatorClose()
  1281. **/
  1282. protected function addMutatorCloseBody(&$script, Column $col)
  1283. {
  1284. $table = $this->getTable();
  1285. $cfc = $col->getPhpName();
  1286. $clo = strtolower($col->getName());
  1287. if ($col->isForeignKey()) {
  1288. foreach ($col->getForeignKeys() as $fk) {
  1289. $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
  1290. $colFK = $tblFK->getColumn($fk->getMappedForeignColumn($col->getName()));
  1291. $varName = $this->getFKVarName($fk);
  1292. $script .= "
  1293. if (\$this->$varName !== null && \$this->".$varName."->get".$colFK->getPhpName()."() !== \$v) {
  1294. \$this->$varName = null;
  1295. }
  1296. ";
  1297. } // foreach fk
  1298. } /* if col is for…

Large files files are truncated, but you can click here to view the full file