M
M
magary42016-03-07 14:05:09
symfony
magary4, 2016-03-07 14:05:09

How to define constants for Entity?

I have a doctrine entity class defined in my project

use Doctrine\ORM\Mapping as ORM;

/**
 * Filter
 *
 * @ORM\Table(name="")
 * @ORM\Entity
 */
class Filter
{

one of the fields is an integer how can I define constants to set $filter->field = Filter::TYPE_BLA in the
$filter->field = Filter::TYPE_BLA code
can these constants be defined in the entity class itself or is a separate class made for this?
after, when I do a fetch and select all the rows from the database to return this case through the API, our API has such a thing
... :
        class: некий класс
        tags:
            - { name: ezpublish_rest.output.value_object_visitor, type: здесь нужно указать какого типа класс }

but I get an array from the database, so I had to create another pseudo-class
class Collection {

    public $items;

}

to shove results from the database into the item and return it
I don’t like this empty class, can you suggest a more beautiful solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2016-03-07
@index0h

You can use the approach: ValueObject. This is a class with a constructor and one getter. All he can do is contain 1 value.
In an entity, you write a setter with type hinting on VO. At the same time, in the entity field, write the value from vo. In the getter, you create a new VO instance based on the value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question