Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.