Doctrine orm 将数组持久化为实体的原则

Doctrine orm 将数组持久化为实体的原则,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我从API中提取一些数据,这些数据设置在如下数组中: array (size=8) 'name' => string 'Application Name' 'description' => string 'Application Description' 'author' => string 'Author name' 'version' => string '1.0.0' 'ip' => string '127.1.1' 'host'

我从API中提取一些数据,这些数据设置在如下数组中:

array (size=8)
  'name' => string 'Application Name' 
  'description' => string 'Application Description'
  'author' => string 'Author name'
  'version' => string '1.0.0' 
  'ip' => string '127.1.1' 
  'host' => string 'http://www.host.com'
  'image' => string 'http://www.hostc.com/image.png'
  'route' => 
    array 
      1 => 
        array 
          'name' => string 'route'
          'description' => string 'The description of route'
          'route' => string 'http://www.myroute.com/route'
      2 => 
        array 
          'name' => string 'route'
          'description' => string 'The description of route'
          'route' => string 'http://www.myroute.com/route'
      3 => 
        'name' => string 'route'
          'description' => string 'The description of route'
          'route' => string 'http://www.myroute.com/route'
此数组反映我的应用程序实体及其到ApplicationRoute实体的OneToMany连接

我的问题是。有没有一种简单的方法可以将其转换为一个可用的对象并坚持使用该原则

编辑

我的一个有效解决方案是:

我在应用程序实体中创建了一个名为:fromArray的函数

public function fromArray($array)
{
    $this->setName($array['name']);
    $this->setDescription($array['description']);
    $this->setAuthor($array['author']);
    $this->setIp($array['ip']);
    $this->setHost($array['host']);
    $this->setImageUrl($array['image']);

    $routeCollection = new ArrayCollection();

    foreach ( $array['route'] AS $route) {
        $routeObejct = new ApplicationRoutes();
        $routeObejct->setName($route['name']);
        $routeObejct->setDescription($route['description']);
        $routeObejct->setRoute($route['route']);
        $routeCollection[] = $routeObejct;
    }

    $this->setRoute($routeCollection);

    return $this;
}
这样做的工作,但我觉得有一个更好的方法


任何建议,非常感谢

您是否已经有了用于表单的水合器?一个教条主义的对象,或者也许?这些可以单独用于向对象添加水合物/从对象提取数据;