Skip to content

Commit a667ed7

Browse files
author
Codeliner
committed
Add global doctrine configuration
1 parent 1863762 commit a667ed7

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

config/autoload/global.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,19 @@
88
*
99
*/
1010
return array(
11-
11+
'service_manager' => array(
12+
'invokables' => array(
13+
'Doctrine\ORM\Mapping\UnderscoreNamingStrategy' => 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy',
14+
),
15+
'aliases' => array(
16+
'entitymanager' => 'doctrine.entitymanager.orm_default',
17+
),
18+
),
19+
'doctrine' => array(
20+
'configuration' => array(
21+
'orm_default' => array(
22+
'naming_strategy' => 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy'
23+
),
24+
),
25+
),
1226
);

module/Application/config/module.config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
'orm_default' => array(
100100
//Define custom doctrine types to map the ddd value objects
101101
'types' => array(
102-
'uid' => 'Application\Infrastructure\Type\UID',
102+
'uid' => 'Application\Infrastructure\Type\UID',
103+
'trackingid' => 'Application\Infrastructure\Type\TrackingId',
103104
),
104105
),
105106
),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample package.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
namespace Application\Infrastrucure\Type;
10+
11+
use Doctrine\DBAL\Types\TextType;
12+
use Doctrine\DBAL\Platforms\AbstractPlatform;
13+
use Doctrine\DBAL\Types\ConversionException;
14+
use Application\Domain\Model\Cargo\TrackingId as DomainTrackingId;
15+
/**
16+
* Custom Doctrine Type UID
17+
*
18+
* @author Alexander Miertsch <[email protected]>
19+
*/
20+
class TrackingId extends TextType
21+
{
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
public function convertToPHPValue($value, AbstractPlatform $platform)
26+
{
27+
return new DomainTrackingId($value);
28+
}
29+
30+
/**
31+
* {@inheritDoc}
32+
*/
33+
public function convertToDatabaseValue($value, AbstractPlatform $platform)
34+
{
35+
if (!$value instanceof DomainTrackingId) {
36+
throw ConversionException::conversionFailed($value, $this->getName());
37+
}
38+
39+
return $value->toString();
40+
}
41+
}

0 commit comments

Comments
 (0)