sergiors/taxonomy

Embedded Annotations with JSON

dev-master 2016-05-02 18:12 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:04:36 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

Taxonomy is an easier way implements Value Object and persist them in JSON format. Like Doctrine Embeddables

Motivation

http://www.postgresql.org/docs/9.5/static/datatype-json.html
https://dev.mysql.com/doc/refman/5.7/en/json.html

Install

composer require sergiors/taxonomy "dev-master"

How to use

use Sergiors\Taxonomy\Configuration\Annotation as Taxonomy;

class User
{
    /**
     * @Taxonomy\Embedded(
     *     class="Phone",
     *     column=@Taxonomy\Column(name="phone_metadata")
     * )
     */
    private $phone;

    public function getPhone()
    {
        return $this->phone;
    }

    public function setPhone(Phone $phone)
    {
        $this->phone = $phone;
    }
}

/**
 * @Taxonomy\Embeddable
 */
class Phone
{
    /**
     * @Taxonomy\Index
     */
    private $number;

    /**
     * @Taxonomy\Index(name="actived")
     */
    private $active;

    public function __construct()
    {
        $this->active = false;
    }

    public function getNumber()
    {
        return $this->number;
    }

    public function isActive()
    {
        return $this->active;
    }

    public function setNumber($number)
    {
        $this->number = preg_replace('/\D+/', '', $number);
    }
}

License

MIT