https://github.com/webforge-labs/webforge-doctrine-compiler
Generate your doctrine entities metadata from a simple json file, including the php code for the entity
https://github.com/webforge-labs/webforge-doctrine-compiler
Last synced: 10 months ago
JSON representation
Generate your doctrine entities metadata from a simple json file, including the php code for the entity
- Host: GitHub
- URL: https://github.com/webforge-labs/webforge-doctrine-compiler
- Owner: webforge-labs
- License: mit
- Created: 2013-11-07T07:36:55.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2021-05-04T02:32:16.000Z (over 5 years ago)
- Last Synced: 2025-04-30T21:51:25.484Z (over 1 year ago)
- Language: PHP
- Size: 299 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# webforge-doctrine-compiler
[](https://travis-ci.org/webforge-labs/webforge-doctrine-compiler)
[](https://coveralls.io/r/webforge-labs/webforge-doctrine-compiler?branch=master)
[](https://packagist.org/packages/webforge/doctrine-compiler)
Generate your doctrine entities metadata from a simple json file, including the php code for the entity
## usage
A very basic model (with one entity) could look like this:
```json
{
"namespace": "ACME\\Blog\\Entities",
"entities": [
{
"name": "User",
"properties": {
"id": { "type": "DefaultId" },
"email": { "type": "String" }
}
}
]
}
```
The compiler will create this entity for you:
```php
email = $email;
}
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* @param string Email
* @chainable
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
}
```
You have the option to use this code and just copy n paste it into your (doctrine)-project. Another option is to put the json model into your project and include the compiler as a dev dependency. If someone changes the model, the entities can be recompiled. You just have to cross the generation-gap here:
`CompiledUser.php`
```php
email = $email;
}
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* @param string Email
* @chainable
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
}
```
`User.php`
```php
somethingUserDefined = $somethingUserDefined;
}
}
```
This way your developers should never touch the Compiled** - Entities and always alter the extended classes. This way you're able to easily add new properties to your entities, or change relations between them.
## Installation
The best way to use the doctrine compiler is to install it as a development tool on your machine.
```
composer global require webforge/doctrine-compiler
```
I recommend to put the global composer bin directory (`~/.composer/vendor/bin` or `%APPDATA%\composer\vendor\bin`) in your PATH.
## Running
You can then compile your entities with the binary installed by composer. You have to provide the location of your json model file and the PSR-1 target-directory for your Entities.
```
~/.composer/vendor/bin/webforge-doctrine-compiler orm:compile etc/doctrine/model.json path/to/my/package/src/php
```
This will create the entities within a PSR-1 named directory in src/php
# Known Issues
- OneToMany, self-referencing Assocations are not yet supported
- the primary defaultId with name 'id' is hardcoded on many cases (you are encouraged to use such an id)
# LICENSE
The MIT License (MIT)
Copyright (c) 2015 webforge
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.