Skip to content

Commit c2e3d3e

Browse files
committed
Propel generation fixes
1 parent b9bdf26 commit c2e3d3e

File tree

7 files changed

+128
-99
lines changed

7 files changed

+128
-99
lines changed

lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5BasicObjectBuilder.php

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,13 @@ protected function addColumnAttributes(&$script) {
247247

248248
$table = $this->getTable();
249249

250-
foreach ($table->getColumns() as $col) {
250+
/** @var Column $col */
251+
foreach ($table->getColumns() as $col) {
251252

252-
$cptype = $col->getPhpNative();
253+
$extra = ($col->isNotNull() && !$col->isLazyLoad()) || $col->getPhpNative() === PropelTypes::BOOLEAN_NATIVE_TYPE ? '' : '|null';
254+
$optional = ($col->isNotNull() && !$col->isLazyLoad()) || $col->getPhpNative() === PropelTypes::BOOLEAN_NATIVE_TYPE ? '' : '?';
255+
256+
$cptype = $col->getPhpNative();
253257
$clo=strtolower($col->getName());
254258
$defVal = "";
255259
if (($val = $col->getPhpDefaultValue()) !== null) {
@@ -262,9 +266,9 @@ protected function addColumnAttributes(&$script) {
262266
263267
/**
264268
* The value for the $clo field.
265-
* @var $cptype
269+
* @var $cptype$extra
266270
*/
267-
protected \$" . $clo . $defVal . ";
271+
protected ". $optional.$cptype ." \$" . $clo . $defVal . ";
268272
";
269273

270274
if ($col->isLazyLoad()) {
@@ -350,7 +354,7 @@ protected function addTemporalAccessor(&$script, $col)
350354
* @throws PropelException - if unable to convert the date/time to timestamp.
351355
*/
352356
public function get$cfc(\$format = ".var_export($defaultfmt, true)."";
353-
if ($col->isLazyLoad()) $script .= ", \$con = null";
357+
if ($col->isLazyLoad()) $script .= ", Connection \$con = null";
354358
$script .= ")
355359
{
356360
";
@@ -395,14 +399,19 @@ protected function addGenericAccessor(&$script, $col)
395399
$cfc=$col->getPhpName();
396400
$clo=strtolower($col->getName());
397401

402+
$extra = '';
403+
if (!$col->isNotNull() && !in_array($col->getPhpNative(), [PropelTypes::BOOLEAN])) {
404+
$extra = "|null";
405+
}
406+
398407
$script .= "
399408
/**
400409
* Get the [$clo] column value.
401410
* ".$col->getDescription()."
402-
* @return ".$col->getPhpNative(). $col->isNotNull() ? "" : "|null
411+
* @return ".$col->getPhpNative().$extra ."
403412
*/
404413
public function get$cfc(";
405-
if ($col->isLazyLoad()) $script .= "\$con = null";
414+
if ($col->isLazyLoad()) $script .= "Connection \$con = null";
406415
$script .= ")
407416
{
408417
";
@@ -413,8 +422,27 @@ public function get$cfc(";
413422
}
414423
";
415424
}
425+
426+
switch ($col->getPhpNative()) {
427+
case PropelTypes::BOOLEAN_NATIVE_TYPE:
428+
$typeCast = '(bool)';
429+
break;
430+
case PropelTypes::INTEGER_NATIVE_TYPE:
431+
if ($col->isNotNull()) {
432+
$typeCast = '(int)';
433+
}
434+
break;
435+
case PropelTypes::CHAR_NATIVE_TYPE:
436+
if ($col->isNotNull()) {
437+
$typeCast = '(string)';
438+
}
439+
break;
440+
default:
441+
$typeCast = '';
442+
}
443+
416444
$script .= "
417-
return \$this->$clo;
445+
return $typeCast \$this->$clo;
418446
}
419447
";
420448
}
@@ -442,7 +470,7 @@ protected function addLazyLoader(&$script, $col)
442470
* @return void
443471
* @throws PropelException - any underlying error will be wrapped and re-thrown.
444472
*/
445-
protected function load$cfc(\$con = null)
473+
protected function load$cfc(Connection \$con = null)
446474
{
447475
\$c = \$this->buildPkeyCriteria();
448476
\$c->addSelectColumn(".$this->getColumnConstant($col).");
@@ -871,13 +899,13 @@ public function getByPosition(\$pos)
871899
$script .= "
872900
case $i:
873901
return \$this->get$cfc();
874-
break;";
902+
";
875903
$i++;
876904
} /* foreach */
877905
$script .= "
878906
default:
879907
return null;
880-
break;
908+
881909
} // switch()
882910
}
883911
";
@@ -982,13 +1010,13 @@ protected function addDelete(&$script)
9821010
/**
9831011
* Removes this object from datastore and sets delete attribute.
9841012
*
985-
* @param Connection \$con
1013+
* @param Connection|null \$con
9861014
* @return void
9871015
* @throws PropelException
9881016
* @see BaseObject::setDeleted()
9891017
* @see BaseObject::isDeleted()
9901018
*/
991-
public function delete(\$con = null)
1019+
public function delete(Connection \$con = null)
9921020
{
9931021
if (\$this->isDeleted()) {
9941022
throw new PropelException(\"This object has already been deleted.\");
@@ -1045,11 +1073,11 @@ protected function addSave(&$script)
10451073
*
10461074
* If the object is new, it inserts it; otherwise an update is performed.
10471075
*
1048-
* @param Connection \$con
1076+
* @param Connection|null \$con
10491077
* @return int The number of rows affected by this insert/update operation (for non-complex OM this will be at most 1).
10501078
* @throws PropelException
10511079
*/
1052-
public function save(\$con = null)
1080+
public function save(Connection \$con = null)
10531081
{
10541082
\$affectedRows = 0; // initialize var to track total num of affected rows
10551083

lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5BasicPeerBuilder.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ protected function addDoCount(&$script)
528528
*
529529
* @param Criteria \$criteria
530530
* @param boolean \$distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
531-
* @param Connection \$con
531+
* @param Connection|null \$con
532532
* @return int Number of matching rows.
533533
* @throws PropelException
534534
* @throws SQLException
535535
*/
536-
public static function doCount(Criteria \$criteria, \$distinct = false, \$con = null)
536+
public static function doCount(Criteria \$criteria, bool bool \$distinct = false, Connection \$con = null)
537537
{
538538
// we're going to modify criteria, so copy it first
539539
\$criteria = clone \$criteria;
@@ -573,12 +573,12 @@ protected function addDoSelectOne(&$script)
573573
* Method to select one object from the DB.
574574
*
575575
* @param Criteria \$criteria object used to create the SELECT statement.
576-
* @param Connection \$con
576+
* @param Connection|null \$con
577577
* @return ".$this->getTable()->getPhpName()."|null
578578
* @throws PropelException
579579
* @throws SQLException
580580
*/
581-
public static function doSelectOne(Criteria \$criteria, \$con = null)
581+
public static function doSelectOne(Criteria \$criteria, Connection \$con = null)
582582
{
583583
\$critcopy = clone \$criteria;
584584
\$critcopy->setLimit(1);
@@ -602,12 +602,12 @@ protected function addDoSelect(&$script)
602602
* Method to do selects.
603603
*
604604
* @param Criteria \$criteria The Criteria object used to build the SELECT statement.
605-
* @param Connection \$con
605+
* @param Connection|null \$con
606606
* @return {$className}[] Array of selected Objects
607607
* @throws PropelException
608608
* @throws SQLException
609609
*/
610-
public static function doSelect(Criteria \$criteria, \$con = null)
610+
public static function doSelect(Criteria \$criteria, Connection \$con = null)
611611
{
612612
return ".$this->getPeerClassname()."::populateObjects(".$this->getPeerClassname()."::doSelectRS(\$criteria, \$con));
613613
}";
@@ -629,13 +629,13 @@ protected function addDoSelectRS(&$script)
629629
* (instead of an array of objects).
630630
*
631631
* @param Criteria \$criteria The Criteria object used to build the SELECT statement.
632-
* @param Connection \$con the connection to use
632+
* @param Connection|null \$con the connection to use
633633
* @throws PropelException Any exceptions caught during processing will be
634634
* rethrown wrapped into a PropelException.
635635
* @return ResultSet The resultset object with numerically-indexed fields.
636636
* @see ".$this->basePeerClassname."::doSelect()
637637
*/
638-
public static function doSelectRS(Criteria \$criteria, \$con = null)
638+
public static function doSelectRS(Criteria \$criteria, Connection \$con = null)
639639
{
640640
if (\$con === null) {
641641
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -841,12 +841,12 @@ protected function addDoInsert(&$script)
841841
* Method perform an INSERT on the database, given a ".$table->getPhpName()." or Criteria object.
842842
*
843843
* @param mixed \$values Criteria or ".$table->getPhpName()." object containing data that is used to create the INSERT statement.
844-
* @param Connection \$con the connection to use
844+
* @param Connection|null \$con the connection to use
845845
* @return mixed The new primary key.
846846
* @throws PropelException Any exceptions caught during processing will be
847847
* rethrown wrapped into a PropelException.
848848
*/
849-
public static function doInsert(\$values, \$con = null)
849+
public static function doInsert(\$values, Connection \$con = null)
850850
{
851851
if (\$con === null) {
852852
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -900,12 +900,12 @@ protected function addDoUpdate(&$script)
900900
* Method perform an UPDATE on the database, given a ".$table->getPhpName()." or Criteria object.
901901
*
902902
* @param mixed \$values Criteria or ".$table->getPhpName()." object containing data that is used to create the UPDATE statement.
903-
* @param Connection \$con The connection to use (specify Connection object to exert more control over transactions).
903+
* @param Connection|null \$con The connection to use (specify Connection object to exert more control over transactions).
904904
* @return int The number of affected rows (if supported by underlying database driver).
905905
* @throws PropelException Any exceptions caught during processing will be
906906
* rethrown wrapped into a PropelException.
907907
*/
908-
public static function doUpdate(\$values, \$con = null)
908+
public static function doUpdate(\$values, Connection \$con = null)
909909
{
910910
if (\$con === null) {
911911
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -950,11 +950,11 @@ protected function addDoDeleteAll(&$script)
950950
/**
951951
* Method to DELETE all rows from the ".$table->getName()." table.
952952
*
953-
* @param Connection \$con
953+
* @param Connection|null \$con
954954
* @return int The number of affected rows (if supported by underlying database driver).
955955
* @throws PropelException
956956
*/
957-
public static function doDeleteAll(\$con = null)
957+
public static function doDeleteAll(Connection \$con = null)
958958
{
959959
if (\$con === null) {
960960
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -997,13 +997,13 @@ protected function addDoDelete(&$script)
997997
*
998998
* @param mixed \$values Criteria or ".$table->getPhpName()." object or primary key or array of primary keys
999999
* which is used to create the DELETE statement
1000-
* @param Connection \$con the connection to use
1000+
* @param Connection|null \$con the connection to use
10011001
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
10021002
* if supported by native driver or if emulated using Propel.
10031003
* @throws PropelException Any exceptions caught during processing will be
10041004
* rethrown wrapped into a PropelException.
10051005
*/
1006-
public static function doDelete(\$values, \$con = null)
1006+
public static function doDelete(\$values, Connection \$con = null)
10071007
{
10081008
if (\$con === null) {
10091009
\$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME);
@@ -1113,7 +1113,7 @@ protected function addDoOnDeleteCascade(&$script)
11131113
* This method should be used within a transaction if possible.
11141114
*
11151115
* @param Criteria \$criteria
1116-
* @param Connection \$con
1116+
* @param Connection|null \$con
11171117
* @return int The number of affected rows (if supported by underlying database driver).
11181118
*/
11191119
protected static function doOnDeleteCascade(Criteria \$criteria, Connection \$con)
@@ -1196,7 +1196,7 @@ protected function addDoOnDeleteSetNull(&$script)
11961196
* This method should be used within a transaction if possible.
11971197
*
11981198
* @param Criteria \$criteria
1199-
* @param Connection \$con
1199+
* @param Connection|null \$con
12001200
* @return void
12011201
*/
12021202
protected static function doOnDeleteSetNull(Criteria \$criteria, Connection \$con)
@@ -1331,12 +1331,12 @@ protected function addRetrieveByPK_SinglePK(&$script)
13311331
* Retrieve a single object by pkey.
13321332
*
13331333
* @param mixed \$pk the primary key.
1334-
* @param Connection \$con the connection to use
1334+
* @param Connection|null \$con the connection to use
13351335
* @return $className|null
13361336
* @throws PropelException
13371337
* @throws SQLException
13381338
*/
1339-
public static function ".$this->getRetrieveMethodName()."(\$pk, \$con = null)
1339+
public static function ".$this->getRetrieveMethodName()."(\$pk, Connection \$con = null)
13401340
{
13411341
if (\$con === null) {
13421342
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -1383,12 +1383,12 @@ protected function addRetrieveByPKs_SinglePK(&$script)
13831383
* Retrieve multiple objects by pkey.
13841384
*
13851385
* @param array \$pks List of primary keys
1386-
* @param Connection \$con the connection to use
1386+
* @param Connection|null \$con the connection to use
13871387
* @return {$className}[]
13881388
* @throws PropelException
13891389
* @throws SQLException
13901390
*/
1391-
public static function ".$this->getRetrieveMethodName()."s(\$pks, \$con = null)
1391+
public static function ".$this->getRetrieveMethodName()."s(\$pks, Connection \$con = null)
13921392
{
13931393
if (\$con === null) {
13941394
\$con = Propel::getConnection(self::DATABASE_NAME);
@@ -1449,7 +1449,7 @@ protected function addRetrieveByPK_MultiPK(&$script)
14491449
";
14501450
}
14511451
$script .= "
1452-
* @param Connection \$con
1452+
* @param Connection|null \$con
14531453
* @return ".$table->getPhpName()."
14541454
*/
14551455
public static function ".$this->getRetrieveMethodName()."(";
@@ -1458,7 +1458,7 @@ public static function ".$this->getRetrieveMethodName()."(";
14581458
$clo = strtolower($col->getName());
14591459
$script .= ($co++ ? "," : "") . " $".$clo;
14601460
} /* foreach */
1461-
$script .= ", \$con = null) {
1461+
$script .= ", Connection \$con = null) {
14621462
if (\$con === null) {
14631463
\$con = Propel::getConnection(self::DATABASE_NAME);
14641464
}

0 commit comments

Comments
 (0)