示例#1
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new RelationFactory();
     }
     return self::$instance;
 }
示例#2
0
文件: Module.php 项目: nhc/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;
 }
示例#3
0
function install_models(Connection $connection, $package, $models)
{
    $factory = RelationFactory::getInstance();
    $factory->prepareRelations($package, $models);
    $models = $factory->getRelations($connection->getConfig()->getType());
    foreach ($models as $model) {
        if (!install_model($connection, $model)) {
            return false;
        }
    }
    return true;
}
示例#4
0
文件: Model.php 项目: exildev/corvus
 public function weak_entity(RelationFactory &$factory)
 {
     foreach ($this->weaks_entitys as $weak) {
         $factory->prepareRelation($weak);
     }
 }