Пример #1
0
 public function importFromGlobals()
 {
     $globals = [$_GET, $_POST, $_FILES];
     foreach ($globals as $global) {
         $globalData = $this->normalize($global);
         $globalData = StructUtils::unflatten($globalData, '_');
         $this->data = StructUtils::merge($this->data, $globalData);
     }
 }
 protected function loadFullPage($aCode)
 {
     $fullPage = null;
     $pagesDirPath = $this->getPagesDirectoryFilePath();
     if (preg_match('/^[a-z\\-_]+$/i', $aCode) !== 1) {
         throw new Exception("Invalid page code: '" . $aCode . "'.");
     }
     $fullPage = $this->getStubPage($aCode);
     $indexFilePath = $pagesDirPath . '/pages/' . $aCode . '/details.php';
     if (file_exists($indexFilePath)) {
         $details = (function () use($indexFilePath) {
             return require $indexFilePath;
         })();
         $fullPage = StructUtils::merge($fullPage, $details['page']);
     }
     return $fullPage;
 }
Пример #3
0
 /**
  * Recursively merges $aArray2 into $aArray1 according to specific criteria.
  * Associative arrays are recursively merged.
  * Vector arrays are replaced, not merged or appended to.
  * @param $aArray1 array Array to merge into.
  * @param $aArray2 array Array to merge from.
  * @return array The new merged array.
  * @throws Exception if a vector & associative array would be merged.
  */
 public static function merge($aArray1, $aArray2)
 {
     $v1 = StructUtils::isVector($aArray1);
     $v2 = StructUtils::isVector($aArray2);
     if (($v1 && !$v2 || $v2 && !$v1) && count($aArray1) > 0 && count($aArray2) > 0) {
         throw new Exception("Cannot merge associative array with vector array.");
     }
     //if $aArray2 is a vector, replace aArray1 with aArray2
     if ($v2) {
         $arr = $aArray2;
     } else {
         $arr = $aArray1;
         foreach ($aArray2 as $k => $v) {
             if (array_key_exists($k, $arr) && is_array($arr[$k]) && is_array($v)) {
                 $arr[$k] = StructUtils::merge($arr[$k], $v);
             } else {
                 $arr[$k] = $v;
             }
         }
     }
     return $arr;
 }
Пример #4
0
 public function mergeReverse($aData)
 {
     $incomingData = StructUtils::toArray($aData, true);
     $this->data = StructUtils::merge($incomingData, $this->data);
 }
Пример #5
0
 public function mergeReverse($aData)
 {
     $this->data = StructUtils::merge(StructUtils::toArray($aData), $this->data);
 }