-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from szymach/mapping
Translatable mapping drivers
- Loading branch information
Showing
19 changed files
with
803 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
filter: | ||
excluded_paths: [vendor/*, tests/*, bin/*] | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
|
||
tools: | ||
php_cpd: true | ||
php_pdepend: | ||
excluded_dirs: [vendor] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Translatable - Translatable behavioral extension for Doctrine 2 | ||
|
||
## XML config example | ||
|
||
Entity: | ||
|
||
```php | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Entity | ||
|
||
class User | ||
{ | ||
/** | ||
* @var integer | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* Acme\DemoBundle\UserTranslation[] | ||
*/ | ||
public $translations; | ||
} | ||
``` | ||
|
||
XML for the entity: | ||
```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 | ||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" | ||
xmlns:fsi="http://fsi.pl/schemas/orm/doctrine-extensions-mapping"> | ||
|
||
<entity name="Acme\DemoBundle\Entity\User" | ||
repository-class="FSi\DoctrineExtensions\Translatable\Entity\Repository\TranslatableRepository" | ||
> | ||
<id name="id" type="integer" column="id"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
<one-to-many field="translations" target-entity="Acme\DemoBundle\Entity\UserTranslation" mapped-by="user" index-by="locale" /> | ||
|
||
<fsi:translatable-locale field="locale" /><!-- "field" is required to point at which property the mapping points --> | ||
<fsi:translatable-field field="name" mappedBy="translations" /> | ||
</entity> | ||
|
||
</doctrine-mapping> | ||
``` | ||
|
||
Translation: | ||
|
||
```php | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Entity | ||
|
||
class UserTranslation | ||
{ | ||
/** | ||
* @var integer | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var Acme\DemoBundle\User | ||
*/ | ||
public $page; | ||
} | ||
``` | ||
|
||
XML for the translation: | ||
```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 | ||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" | ||
xmlns:fsi="http://fsi.pl/schemas/orm/doctrine-extensions-mapping"> | ||
|
||
<entity name="Acme\DemoBundle\Entity\UserTranslation"> | ||
<id name="id" type="integer" column="id"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
|
||
<field type="string" name="content" length="255"/> | ||
<field type="string" name="locale" length="2"> | ||
<fsi:translatable-locale /><!-- No value needed, field name is used as locale property identifier --> | ||
</field> | ||
|
||
<many-to-one field="user" target-entity="cme\DemoBundle\Entity\User" inversed-by="translations" /> | ||
</entity> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Translatable - Translatable behavioral extension for Doctrine 2 | ||
|
||
## YAML config example | ||
|
||
Translated entity: | ||
|
||
```php | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Entity | ||
|
||
class User | ||
{ | ||
/** | ||
* @var integer | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var \Acme\DemoBundle\Entity\UserTranslation[] | ||
*/ | ||
public $translations; | ||
} | ||
``` | ||
|
||
Translated entity's mapping: | ||
```yaml | ||
Acme\DemoBundle\Entity\User: | ||
type: entity | ||
id: | ||
id: | ||
type: integer | ||
generator: | ||
strategy: AUTO | ||
fsi: | ||
translatable: | ||
locale: | ||
field: locale # required, since there is no field to assign to | ||
fields: | ||
name: | ||
mappedBy: translations | ||
targetField: name | ||
oneToMany: | ||
translations: | ||
targetEntity: Acme\DemoBundle\Entity\UserTranslation | ||
mappedBy: user | ||
cascade: ["persist", "remove"] | ||
indexBy: locale | ||
``` | ||
Translation entity: | ||
```php | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Entity | ||
|
||
class UserTranslation | ||
{ | ||
/** | ||
* @var integer | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var \Acme\DemoBundle\Entity\User | ||
*/ | ||
public $user; | ||
} | ||
``` | ||
|
||
Translation entity's mapping: | ||
```yaml | ||
Acme\DemoBundle\Entity\UserTranslation: | ||
type: entity | ||
id: | ||
id: | ||
type: integer | ||
generator: | ||
strategy: AUTO | ||
fields: | ||
locale: | ||
type: string | ||
length: 2 | ||
fsi: | ||
translatable: | ||
locale: ~ # No value is needed here, field name is assigned as locale parameter identifier | ||
name: | ||
type: string | ||
length: 255 | ||
manyToOne: | ||
user: | ||
targetEntity: Acme\DemoBundle\Entity\User | ||
inversedBy: translations | ||
``` | ||
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
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
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
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
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
Oops, something went wrong.