Last active
April 23, 2019 11:31
-
-
Save vudaltsov/5bfb22a4f477f2fd714bab6aa9b8246c to your computer and use it in GitHub Desktop.
PHP Money Doctrine XML Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- config/doctrine/money/Currency.orm.xml --> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | |
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | |
<embeddable name="Money\Currency"> | |
<field name="code" length="3"/> | |
</embeddable> | |
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/packages/doctrine.yaml | |
doctrine: | |
# ... | |
orm: | |
# ... | |
mappings: | |
App: | |
# ... | |
Money: | |
is_bundle: false | |
type: xml | |
dir: "%kernel.project_dir%/config/doctrine/money" | |
prefix: Money | |
alias: Money |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- config/doctrine/money/Money.orm.xml --> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | |
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | |
<embeddable name="Money\Money"> | |
<field name="amount"/> | |
<embedded name="currency" class="Money\Currency"/> | |
</embeddable> | |
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Money\Money; | |
/** | |
* @ORM\Entity() | |
*/ | |
class Product | |
{ | |
// ... | |
/** | |
* @ORM\Embedded(Money::class) | |
*/ | |
private $price; | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment