Skip to content

Commit

Permalink
Merge pull request #948 from markusramsak/patch-1
Browse files Browse the repository at this point in the history
Update DocBlockHelper.php allow different date and time classes
  • Loading branch information
LordSimal committed Nov 1, 2023
2 parents 5f74e55 + 060fc70 commit 18486ac
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/View/Helper/DocBlockHelper.php
Expand Up @@ -5,6 +5,7 @@

use Cake\Collection\Collection;
use Cake\Core\App;
use Cake\Database\TypeFactory;
use Cake\ORM\Association;
use Cake\Utility\Inflector;
use Cake\View\Helper;
Expand Down Expand Up @@ -200,16 +201,34 @@ public function columnTypeToHintType(string $type): ?string
return 'string|resource';

case 'date':
$dbType = TypeFactory::build($type);
if (method_exists($dbType, 'getDateClassName')) {
// allow custom Date class which should extend \Cake\I18n\Date
return '\\' . $dbType->getDateClassName();
}

return '\Cake\I18n\Date';

case 'datetime':
case 'datetimefractional':
case 'timestamp':
case 'timestampfractional':
case 'timestamptimezone':
$dbType = TypeFactory::build($type);
if (method_exists($dbType, 'getDateTimeClassName')) {
// allow custom DateTime class which should extend \Cake\I18n\DateTime
return '\\' . $dbType->getDateTimeClassName();
}

return '\Cake\I18n\DateTime';

case 'time':
$dbType = TypeFactory::build($type);
if (method_exists($dbType, 'getTimeClassName')) {
// allow custom Time class which should extend \Cake\I18n\Time
return '\\' . $dbType->getTimeClassName();
}

return '\Cake\I18n\Time';
}

Expand Down

0 comments on commit 18486ac

Please sign in to comment.