コード例 #1
0
ファイル: Module.php プロジェクト: artmouse/Umc_Base
 /**
  * init module from data
  *
  * @param array $data
  * @return $this
  */
 public function initFromData(array $data)
 {
     if (isset($data[$this->getEntityCode()])) {
         $this->addData($data[$this->getEntityCode()]);
     }
     $settings = $this->settingsFactory->create();
     if (isset($data[$settings->getEntityCode()])) {
         $settings->setData($data[$settings->getEntityCode()]);
         $this->setSettings($settings);
     }
     $entitiesByIndex = [];
     if (isset($data['entity'])) {
         $entities = $data['entity'];
         if (is_array($entities)) {
             foreach ($entities as $key => $entityData) {
                 if (!$entityData) {
                     continue;
                 }
                 /** @var \Umc\Base\Model\Core\Entity $entity */
                 $entity = $this->entityFactory->create();
                 if (isset($entityData['attributes']) && is_array($entityData['attributes'])) {
                     if (isset($entityData['attributes']['is_name'])) {
                         $isName = $entityData['attributes']['is_name'];
                         unset($entityData['attributes']['is_name']);
                         if (isset($entityData['attributes'][$isName])) {
                             $entityData['attributes'][$isName]['is_name'] = 1;
                         }
                     }
                     foreach ($entityData['attributes'] as $attrKey => $attributeData) {
                         /** @var \Umc\Base\Model\Core\Attribute $attribute */
                         $attribute = $this->attributeFactory->create();
                         $attribute->addData($attributeData);
                         $attribute->setIndex($attrKey);
                         $entity->addAttribute($attribute);
                     }
                 }
                 unset($data['attribute']);
                 $entity->addData($entityData);
                 $entity->setIndex($key);
                 $this->addEntity($entity);
                 $entitiesByIndex[$key] = $entity;
             }
         }
     }
     if (isset($data['relation'])) {
         foreach ($data['relation'] as $index => $values) {
             foreach ($values as $jndex => $type) {
                 if (isset($entitiesByIndex[$index]) && isset($entitiesByIndex[$jndex])) {
                     /** @var \Umc\Base\Model\Core\Relation $relation */
                     $relation = $this->relationFactory->create();
                     $relation->setEntities($entitiesByIndex[$index], $entitiesByIndex[$jndex], $type);
                     $this->addRelation($relation);
                 }
             }
         }
     }
     return $this;
 }
コード例 #2
0
ファイル: Repository.php プロジェクト: redwormik/fakeorm
 /**
  * @param ActiveRow $row
  */
 protected function getEntity($row)
 {
     if (!$row) {
         return $row;
     }
     $id = $row->getSignature(TRUE);
     if (!isset($this->data[$id])) {
         $this->data[$id] = $this->entityFactory->create($this->type, $row, $this);
     }
     return $this->data[$id];
 }
コード例 #3
0
ファイル: Service.php プロジェクト: redwormik/fakeorm
 /**
  * @param mixed $data
  * @return Entity
  */
 public function create($data = NULL)
 {
     $entity = $this->entityFactory->create($this->name);
     return $data === NULL ? $entity : $entity->setData($data);
 }