本文整理汇总了PHP中Espo\Core\Utils\Util::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::merge方法的具体用法?PHP Util::merge怎么用?PHP Util::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Espo\Core\Utils\Util
的用法示例。
在下文中一共展示了Util::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
protected function load($linkName, $entityName)
{
$parentRelation = parent::load($linkName, $entityName);
$relation = array($entityName => array('fields' => array($linkName . 'Types' => array('type' => 'jsonObject', 'notStorable' => true))));
$relation = \Espo\Core\Utils\Util::merge($parentRelation, $relation);
return $relation;
}
示例2: load
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 = \Espo\Core\Utils\Util::merge($parentRelation, $relation);
return $relation;
}
示例3: unify
/**
* 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;
}
示例4: unify
/**
* Unite file content to the file
*
* @param [type] $name [description]
* @param [type] $paths [description]
* @param boolean $recursively Note: only for first level of sub directory, other levels of sub directories will be ignored
* @param [type] $mergeLevel - merge level, see Espo\Core\Utils\Util::merge()
*
* @return array
*/
public function unify($name, $paths, $recursively = false, $mergeLevel = null, $mergeKeyName = null)
{
$content = $this->unifySingle($paths['corePath'], $name, $recursively);
if (!empty($paths['modulePath'])) {
$customDir = strstr($paths['modulePath'], '{*}', true);
$dirList = $this->getFileManager()->getFileList($customDir, false, '', 'dir');
foreach ($dirList as $dirName) {
$curPath = str_replace('{*}', $dirName, $paths['modulePath']);
$content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $dirName), $mergeLevel, $mergeKeyName);
}
}
if (!empty($paths['customPath'])) {
$content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively), $mergeLevel, $mergeKeyName);
}
return $content;
}
示例5: unify
/**
* 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;
}
示例6: delete
/**
* 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);
}
示例7: getCustomTables
/**
* Get custom table defenition in "application/Espo/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;
}
示例8: normalizeDefs
/**
* Add all needed block for a field defenition
*
* @param string $fieldName
* @param array $fieldDefs
* @param string $scope
* @return array
*/
protected function normalizeDefs($fieldName, array $fieldDefs, $scope)
{
$fieldDefs = $this->prepareFieldDefs($fieldName, $fieldDefs, $scope);
$metaFieldDefs = $this->getMetadataHelper()->getFieldDefsInFieldMeta($fieldDefs);
if (isset($metaFieldDefs)) {
$fieldDefs = Util::merge($metaFieldDefs, $fieldDefs);
}
if (isset($fieldDefs['linkDefs'])) {
$linkDefs = $fieldDefs['linkDefs'];
unset($fieldDefs['linkDefs']);
}
$defs = array('fields' => array($fieldName => $fieldDefs));
/** Save links for a field. */
$metaLinkDefs = $this->getMetadataHelper()->getLinkDefsInFieldMeta($scope, $fieldDefs);
if (isset($linkDefs) || isset($metaLinkDefs)) {
$linkDefs = Util::merge((array) $metaLinkDefs, (array) $linkDefs);
$defs['links'] = array($fieldName => $linkDefs);
}
return $defs;
}
示例9: getInitValues
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;
}
示例10: mergeContents
/**
* Merge file content and save it to a file
*
* @param string | array $path
* @param string $content JSON string
* @param bool $isJSON
* @param string | array $mergeOptions
* @param string | array $removeOptions - List of unset keys from content
* @param bool $isReturn - Is result to be returned or stored
*
* @return bool | array
*/
public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null, $removeOptions = null, $isReturn = false)
{
$fileContent = $this->getContents($path);
$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, $mergeOptions);
if ($isJSON) {
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
}
if ($isReturn) {
return $data;
}
return $this->putContents($path, $data);
}
示例11: unifyGetContents
/**
* Helpful method for get content from files for unite Files
*
* @param string | array $paths
* @param string | array() $defaults - It can be a string like ["metadata","layouts"] OR an array with default values
*
* @return array
*/
protected function unifyGetContents($paths, $defaults)
{
$fileContent = $this->getFileManager()->getContents($paths);
$decoded = Utils\Json::getArrayData($fileContent);
if (empty($decoded) && !is_array($decoded)) {
$GLOBALS['log']->emergency('Syntax error or empty file - ' . Utils\Util::concatPath($folderPath, $fileName));
} else {
//Default values
if (is_string($defaults) && !empty($defaults)) {
$defType = $defaults;
unset($defaults);
$name = $this->getFileManager()->getFileName($fileName, '.json');
$defaults = $this->loadDefaultValues($name, $defType);
}
$mergedValues = Utils\Util::merge($defaults, $decoded);
//END: Default values
return $mergedValues;
}
return array();
}
示例12: getCustomTables
protected function getCustomTables()
{
$customTables = array();
$fileList = $this->getFileManager()->getFileList($this->customTablePath, false, '\\.php$', 'file');
foreach ($fileList as $fileName) {
$fileData = $this->getFileManager()->getContents(array($this->customTablePath, $fileName));
if (is_array($fileData)) {
$customTables = Util::merge($customTables, $fileData);
}
}
return $customTables;
}
示例13: mergeContentsPHP
/**
* Merge PHP content and save it to a file
*
* @param string | array $path
* @param string $content
* @param bool $onlyFirstLevel - Merge only first level. Ex. current: array('test'=>array('item1', 'item2')). $content= array('test'=>array('item1'),). Result will be array('test'=>array('item1')).
*
* @return bool
*/
public function mergeContentsPHP($path, $content, $onlyFirstLevel = false, $mergeOptions = null)
{
$fileContent = $this->getContents($path);
$savedDataArray = Utils\Json::getArrayData($fileContent);
$newDataArray = Utils\Json::getArrayData($content);
if ($onlyFirstLevel) {
foreach ($newDataArray as $key => $val) {
$setVal = is_array($val) ? array() : '';
$savedDataArray[$key] = $setVal;
}
}
$data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
return $this->putContentsPHP($path, $data);
}
示例14: mergeContents
/**
* 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);
}
示例15: normalizeDefs
/**
* 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)
{
if (isset($fieldDef['name'])) {
unset($fieldDef['name']);
}
if (isset($fieldDef['linkDefs'])) {
$linkDefs = $fieldDef['linkDefs'];
unset($fieldDef['linkDefs']);
}
foreach ($fieldDef as $defName => $defValue) {
if (!isset($defValue) || is_string($defValue) && $defValue == '') {
unset($fieldDef[$defName]);
}
}
$metaFieldDef = $this->getMetadataUtils()->getFieldDefsInFieldMeta($fieldDef);
if (isset($metaFieldDef)) {
$fieldDef = Util::merge($metaFieldDef, $fieldDef);
}
$defs = array('fields' => array($fieldName => $fieldDef));
/** Save links for a field. */
$metaLinkDef = $this->getMetadataUtils()->getLinkDefsInFieldMeta($scope, $fieldDef);
if (isset($linkDefs) || isset($metaLinkDef)) {
$linkDefs = Util::merge((array) $metaLinkDef, (array) $linkDefs);
$defs['links'] = array($fieldName => $linkDefs);
}
return $defs;
}