Пример #1
0
 /**
  * Create the table entries from the registry annotation
  *
  * @param $registry
  * @param $classAnnotation
  * @param $oldRegistryEntry
  * @return $this
  */
 private function createEntities($registry, $classAnnotation, $oldRegistryEntry = null)
 {
     if (count($classAnnotation->entity)) {
         foreach ($classAnnotation->entity as $className => $entries) {
             if ($oldRegistryEntry !== null && isset($classAnnotation->updateEntity[$className])) {
                 foreach ($classAnnotation->updateEntity[$className] as $entryData) {
                     $entry = $this->getEntity($className, $entryData);
                     if ($entry) {
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $data = $this->getEntityDataForUpdate($entryData, $classAnnotation->entity[$className]);
                         $entry->updateEntity($data);
                     }
                 }
             } elseif ($oldRegistryEntry === null) {
                 foreach ($entries as $entryData) {
                     $entryDataWithSubEntries = $this->getSubEntries($entryData, $registry);
                     if ($this->getEntity($className, $entryDataWithSubEntries) === null) {
                         $entry = new $className();
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $entry->updateEntity($entryDataWithSubEntries);
                     }
                 }
             }
         }
     }
     if (count($classAnnotation->config)) {
         foreach ($classAnnotation->config as $configName => $data) {
             $className = '\\Fraym\\Registry\\Entity\\Config';
             $data['name'] = $configName;
             $data['registry'] = $registry;
             $entity = $this->db->getRepository($className)->findOneByName($configName);
             if ($entity === null) {
                 $entry = new $className();
                 $entry->updateEntity($data);
             }
         }
     }
     if (count($classAnnotation->translation)) {
         foreach ($classAnnotation->translation as $translation) {
             $defaultValue = $translation[0];
             $key = isset($translation[1]) ? $translation[1] : $defaultValue;
             $locale = isset($translation[2]) ? $translation[2] : 'en_US';
             $this->translation->createTranslation($key, $defaultValue, $this->locale->getLocale()->locale, $locale);
         }
     }
     return $this;
 }