Esempio n. 1
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $relation = array($entityName => array('fields' => array($linkName . 'Types' => array('type' => 'jsonObject', 'notStorable' => true))));
     $relation = \Fox\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Esempio n. 2
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $foreignEntityName = $this->getForeignEntityName();
     $relation = array($entityName => array('relations' => array($linkName => array('midKeys' => array(lcfirst($entityName) . 'Id', lcfirst($foreignEntityName) . 'Id')))));
     $relation = \Fox\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Esempio n. 3
0
 /**
  * Unite file content to the file
  *
  * @param  string  $name
  * @param  array  $paths
  * @param  boolean $recursively Note: only for first level of sub directory, other levels of sub directories will be ignored
  *
  * @return array
  */
 public function unify($name, $paths, $recursively = false)
 {
     $content = $this->unifySingle($paths['corePath'], $name, $recursively);
     if (!empty($paths['modulePath'])) {
         $customDir = strstr($paths['modulePath'], '{*}', true);
         $moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($customDir, false, '', false);
         foreach ($moduleList as $moduleName) {
             $curPath = str_replace('{*}', $moduleName, $paths['modulePath']);
             $content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
         }
     }
     if (!empty($paths['customPath'])) {
         $content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
     }
     return $content;
 }
Esempio n. 4
0
 /**
  * Unite files content
  *
  * @param array $paths
  * @param bool $isReturnModuleNames - If need to return data with module names
  *
  * @return array
  */
 public function unify(array $paths, $isReturnModuleNames = false)
 {
     $data = $this->loadData($paths['corePath']);
     if (!empty($paths['modulePath'])) {
         $moduleDir = strstr($paths['modulePath'], '{*}', true);
         $moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($moduleDir, false, '', false);
         foreach ($moduleList as $moduleName) {
             $moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']);
             if ($isReturnModuleNames) {
                 if (!isset($data[$moduleName])) {
                     $data[$moduleName] = array();
                 }
                 $data[$moduleName] = Util::merge($data[$moduleName], $this->loadData($moduleFilePath));
                 continue;
             }
             $data = Util::merge($data, $this->loadData($moduleFilePath));
         }
     }
     if (!empty($paths['customPath'])) {
         $data = Util::merge($data, $this->loadData($paths['customPath']));
     }
     return $data;
 }
Esempio n. 5
0
 /**
  * Add all needed block for a field defenition
  *
  * @param string $fieldName
  * @param array $fieldDef
  * @param string $scope
  * @return array
  */
 protected function normalizeDefs($fieldName, array $fieldDef, $scope)
 {
     $fieldDef = $this->prepareFieldDef($fieldName, $fieldDef, $scope);
     $metaFieldDef = $this->getMetadataHelper()->getFieldDefsInFieldMeta($fieldDef);
     if (isset($metaFieldDef)) {
         $fieldDef = Util::merge($metaFieldDef, $fieldDef);
     }
     if (isset($fieldDef['linkDefs'])) {
         $linkDefs = $fieldDef['linkDefs'];
         unset($fieldDef['linkDefs']);
     }
     $defs = array('fields' => array($fieldName => $fieldDef));
     /** Save links for a field. */
     $metaLinkDef = $this->getMetadataHelper()->getLinkDefsInFieldMeta($scope, $fieldDef);
     if (isset($linkDefs) || isset($metaLinkDef)) {
         $linkDefs = Util::merge((array) $metaLinkDef, (array) $linkDefs);
         $defs['links'] = array($fieldName => $linkDefs);
     }
     return $defs;
 }
Esempio n. 6
0
 protected function getInitValues(array $fieldParams)
 {
     $values = array();
     foreach ($this->fieldAccordances as $espoType => $ormType) {
         if (isset($fieldParams[$espoType])) {
             if (is_array($ormType)) {
                 $conditionRes = false;
                 if (!is_array($fieldParams[$espoType])) {
                     $conditionRes = preg_match('/' . $ormType['condition'] . '/i', $fieldParams[$espoType]);
                 }
                 if (!$conditionRes || $conditionRes && $conditionRes === $ormType['conditionEquals']) {
                     $value = is_array($fieldParams[$espoType]) ? json_encode($fieldParams[$espoType]) : $fieldParams[$espoType];
                     $values = Util::merge($values, Util::replaceInArray('{0}', $value, $ormType['value']));
                 }
             } else {
                 $values[$ormType] = $fieldParams[$espoType];
             }
         }
     }
     return $values;
 }
Esempio n. 7
0
 /**
  * Get custom table defenition in "application/Fox/Core/Utils/Database/Schema/tables/" and in metadata 'additionalTables'
  *
  * @param  array  $ormMeta
  *
  * @return array
  */
 protected function getCustomTables(array $ormMeta)
 {
     $customTables = array();
     $fileList = $this->getFileManager()->getFileList($this->customTablePath, false, '\\.php$', true);
     foreach ($fileList as $fileName) {
         $fileData = $this->getFileManager()->getPhpContents(array($this->customTablePath, $fileName));
         if (is_array($fileData)) {
             $customTables = Util::merge($customTables, $fileData);
         }
     }
     //get custom tables from metdata 'additionalTables'
     foreach ($ormMeta as $entityName => $entityParams) {
         if (isset($entityParams['additionalTables']) && is_array($entityParams['additionalTables'])) {
             $customTables = Util::merge($customTables, $entityParams['additionalTables']);
         }
     }
     return $customTables;
 }
Esempio n. 8
0
 private function getAllowedAdditionalParams($allowedItemName)
 {
     $linkParams = $this->getLinkParams();
     $foreignLinkParams = $this->getForeignLinkParams();
     $itemLinkParams = isset($linkParams[$allowedItemName]) ? $linkParams[$allowedItemName] : null;
     $itemForeignLinkParams = isset($foreignLinkParams[$allowedItemName]) ? $foreignLinkParams[$allowedItemName] : null;
     $additionalParrams = null;
     if (isset($itemLinkParams) && isset($itemForeignLinkParams)) {
         $additionalParrams = Util::merge($itemLinkParams, $itemForeignLinkParams);
     } else {
         if (isset($itemLinkParams)) {
             $additionalParrams = $itemLinkParams;
         } else {
             if (isset($itemForeignLinkParams)) {
                 $additionalParrams = $itemForeignLinkParams;
             }
         }
     }
     return $additionalParrams;
 }
Esempio n. 9
0
 protected function init($reload = false)
 {
     if ($reload || !file_exists($this->getLangCacheFile()) || !$this->getConfig()->get('useCache')) {
         $fullData = $this->getUnifier()->unify($this->name, $this->paths, true);
         $result = true;
         foreach ($fullData as $i18nName => $i18nData) {
             if ($i18nName != $this->defaultLanguage) {
                 $i18nData = Util::merge($fullData[$this->defaultLanguage], $i18nData);
             }
             $this->data[$i18nName] = $i18nData;
             if ($this->getConfig()->get('useCache')) {
                 $i18nCacheFile = str_replace('{*}', $i18nName, $this->cacheFile);
                 $result &= $this->getFileManager()->putPhpContents($i18nCacheFile, $i18nData);
             }
         }
         if ($result == false) {
             throw new Error('Language::init() - Cannot save data to a cache');
         }
     }
     $currentLanguage = $this->getLanguage();
     if (empty($this->data[$currentLanguage])) {
         $this->data[$currentLanguage] = $this->getFileManager()->getPhpContents($this->getLangCacheFile());
     }
 }
Esempio n. 10
0
 /**
  * Unset some fields and other stuff in metadat
  *
  * @param  string $key1
  * @param  string $key2
  * @param  array | string $unsets Ex. 'fields.name'
  *
  * @return bool
  */
 public function delete($key1, $key2, $unsets)
 {
     if (!is_array($unsets)) {
         $unsets = (array) $unsets;
     }
     $normalizedData = array('__APPEND__');
     $metaUnsetData = array();
     foreach ($unsets as $unsetItem) {
         $normalizedData[] = $unsetItem;
         $metaUnsetData[] = implode('.', array($key1, $key2, $unsetItem));
     }
     $unsetData = array($key1 => array($key2 => $normalizedData));
     $this->deletedData = Util::merge($this->deletedData, $unsetData);
     $this->deletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData);
     $this->meta = Util::unsetInArray($this->getData(), $metaUnsetData);
 }
Esempio n. 11
0
 /**
  * Merge file content and save it to a file
  *
  * @param string | array $path
  * @param string $content JSON string
  * @param bool $isReturnJson
  * @param string | array $removeOptions - List of unset keys from content
  * @param bool $isPhp - Is merge php files
  *
  * @return bool | array
  */
 public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
 {
     if ($isPhp) {
         $fileContent = $this->getPhpContents($path);
     } else {
         $fileContent = $this->getContents($path);
     }
     $fullPath = $this->concatPaths($path);
     if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
         throw new Error('FileManager: Failed to read file [' . $fullPath . '].');
     }
     $savedDataArray = Utils\Json::getArrayData($fileContent);
     $newDataArray = Utils\Json::getArrayData($content);
     if (isset($removeOptions)) {
         $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
         $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
     }
     $data = Utils\Util::merge($savedDataArray, $newDataArray);
     if ($isReturnJson) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
     }
     if ($isPhp) {
         return $this->putPhpContents($path, $data);
     }
     return $this->putContents($path, $data);
 }