graefe / doctrine-extensions
Collection of useful types and other minor extensions to the Doctrine DBAL and ORM.
Installs: 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/graefe/doctrine-extensions
Requires
- php: >=5.6.0
- doctrine/dbal: ^2.5
- doctrine/orm: ^2.5
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is not auto-updated.
Last update: 2025-09-28 00:08:15 UTC
README
This is a collection of useful types and other minor extensions to the Doctrine DBAL and ORM.
UnixTimeType
UnixTimeType is a custom Doctrine mapping type for time-stamp values represented in unix time, i.e. seconds since Jan 1, 1970.
// Register custom type during boot-strap. \Doctrine\DBAL\Types\Type::addType('unixtime', '\Graefe\Doctrine\Type\UnixTimeType'); ... /** * @ORM\Column(name="created", type="unixtime", nullable=false) */ private $created;
MySqlEnumType
MySqlEnumType is an abstract base class for mapping ENUM types in MySQL.
// Define type. class ShopModeType extends \Graefe\Doctrine\Type\MySqlEnumType { protected function getValues() { return array('b2b','b2c'); } public function getName() { return 'shopmode'; } } ... // Register type during boot-strap. \Doctrine\DBAL\Types\Type::addType('shopmode', 'ShopModeType'); ... /** * @ORM\Column(name="mode", type="shopmode", nullable=false) */ private $mode;
RAND()
The Rand class provides the RAND() function to DQL for selecting random rows. (Caveat: Improper use might cause serious performance problems.)
// Register function. $em->getConfiguration()->addCustomNumericFunction('RAND', '\\Graefe\\Doctrine\\Functions\\Rand'); ... $qb->select('d') ->addSelect('RAND() AS randval') ->from('Dummy', 'd') ->orderBy('randval') ->setMaxResults(1);