vendredi 1 avril 2016

What pattern am I using to store/retrieve data?

In my Controller I often have a need to write code that stores or retrieves various data, usually from the same data table.

What I usually do is this:

class Controller
{
    function saveAction()
    {
        $data = $this->pattern->retrieve();

        $output = $this->process($data);

        $this->pattern->save($output);
    }
}

class Pattern
{
    function retrieve()
    {
        //in my case using ORM EntityManager
        return $em->find(...);
    }

    function save(array $data)
    {
        $object = $data['object'];
        $em->persist($object);
    }

}

What type of pattern is this?

Aucun commentaire:

Enregistrer un commentaire