Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aurimasniekis/doctrine-json-object-type
Doctrine Json Object Type
https://github.com/aurimasniekis/doctrine-json-object-type
Last synced: 3 months ago
JSON representation
Doctrine Json Object Type
- Host: GitHub
- URL: https://github.com/aurimasniekis/doctrine-json-object-type
- Owner: aurimasniekis
- License: mit
- Created: 2017-05-16T10:10:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-16T10:34:18.000Z (over 7 years ago)
- Last Synced: 2024-04-22T17:11:51.365Z (9 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Doctrine Json Object Type
[![Latest Version](https://img.shields.io/github/release/aurimasniekis/doctrine-json-object-type.svg?style=flat-square)](https://github.com/aurimasniekis/doctrine-json-object-type/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/aurimasniekis/doctrine-json-object-type.svg?style=flat-square)](https://travis-ci.org/aurimasniekis/doctrine-json-object-type)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/aurimasniekis/doctrine-json-object-type.svg?style=flat-square)](https://scrutinizer-ci.com/g/aurimasniekis/doctrine-json-object-type)
[![Quality Score](https://img.shields.io/scrutinizer/g/aurimasniekis/doctrine-json-object-type.svg?style=flat-square)](https://scrutinizer-ci.com/g/aurimasniekis/doctrine-json-object-type)
[![Total Downloads](https://img.shields.io/packagist/dt/aurimasniekis/doctrine-json-object-type.svg?style=flat-square)](https://packagist.org/packages/aurimasniekis/doctrine-json-object-type)[![Email](https://img.shields.io/badge/[email protected]?style=flat-square)](mailto:[email protected])
Doctrine Json Object Type provides a ability to serialize/deserialize object which implements JsonObject interface to json and backwards.
## Install
Via Composer
```bash
$ composer require aurimasniekis/doctrine-json-object-type
```## Configuration
Symfony:
```yaml
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
types:
json_object: AurimasNiekis\DoctrineJsonObjectType\JsonObjectType
```Plain Doctrine:
```php
name = $name;
}
public function getName()
{
return $this->name;
}
public static function fromJson(array $data)
{
$inst = new self();
$inst->setName($data['name']);
return $inst;
}
public function jsonSerialize()
{
return [
'name' => $this->getName()
];
}
}
```Entity
```php
id;
}/**
* @return ValueObject
*/
public function getValue()
{
return $this->value;
}/**
* @param ValueObject $value
*/
public function setValue(ValueObject $value)
{
$this->value = $value;
}
}
```Usage
```php
setName('foo_bar');$entity = new Entity();
$entity->setValue($value);$em->persist($entity);
$em->flush(); // INSERT INTO `entity` (`id`, `value`) VALUES (1, '{"name": "foo_bar", "__class": "ValueObject"}');$findResult = $repo->find(1);
/// $findResult->getValue() === $value;
```## Testing
```bash
$ composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
## License
Please see [License File](LICENSE) for more information.