public static function getBaseChain()
 {
     if (!self::$chain) {
         self::$chain = parent::getBaseChain();
         self::$chain = StructUtils::insertBefore(self::$chain, 'app', 'solarfield/lightship-php', ['namespace' => __NAMESPACE__, 'path' => __DIR__]);
     }
     return self::$chain;
 }
 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);
     }
 }
 public static function getInitialRoute()
 {
     $route = null;
     $input = new TerminalInput();
     $input->importFromGlobals();
     $input = StructUtils::toArray($input);
     $route = StructUtils::get($input, '--module');
     return $route;
 }
 protected function onCreateJsonData(CreateJsonDataEvent $aEvt)
 {
     $model = $this->getModel();
     $rules = $this->getDataRules()->toArray();
     foreach ($rules as $k) {
         $s = StructUtils::scout($model, $k);
         if ($s[0]) {
             $aEvt->getJsonData()->set($k, $s[1]);
         }
     }
 }
 private function resolvePluginDependencies_step($plugin)
 {
     $plugins = $this->getPlugins();
     //if plugin is Lightship-compatible
     if ($plugin instanceof ControllerPlugin) {
         foreach ($plugin->getManifest()->getAsArray('dependencies.plugins') as $dep) {
             if (StructUtils::search($plugins->getRegistrations(), 'componentCode', $dep['code']) === false) {
                 if ($depPlugin = $plugins->register($dep['code'])) {
                     $this->resolvePluginDependencies_step($depPlugin);
                 }
             }
         }
     }
 }
 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;
 }
 private function buildMaps()
 {
     $list = $this->loadStubPages();
     foreach ($list as &$page) {
         //restructure any child pages in the index, to the top level
         if (array_key_exists('childPages', $page)) {
             foreach ($page['childPages'] as $childPage) {
                 $childPage['_parentPageCode'] = $page['code'];
                 array_push($list, $childPage);
             }
             unset($page['childPages']);
         }
         //default some basic properties
         $page = array_replace(['code' => null, 'title' => null, 'slug' => null, 'module' => null, '_parentPageCode' => null], $page);
     }
     unset($page);
     //generate the lookup and tree
     $lookup = StructUtils::delegate($list, 'code');
     $tree = StructUtils::tree($list, 'code', '_parentPageCode', 'childPages', 'parentPage');
     foreach ($lookup as &$page) {
         unset($page['_parentPageCode']);
         //generate url
         $url = '';
         $tempPage = $page;
         do {
             if ($tempPage['slug']) {
                 $url = $tempPage['slug'] . '/' . $url;
             }
         } while (($tempPage = $tempPage['parentPage']) != null);
         $page['url'] = '/' . $url;
         //normalize item
         $page = $this->normalizeStubPage($page);
     }
     unset($page);
     $this->pagesLookup =& $lookup;
     $this->pagesTree =& $tree;
 }
 /**
  * Converts an object to an array according to specific criteria.
  * @param mixed $aThing An array or an object which implements ToArrayInterface.
  * @param bool $aDeep If true, conversion is done recursively.
  * @return array The array created from the object.
  * @throws Exception if the object cannot be converted to an array.
  */
 public static function toArray($aThing, $aDeep = false)
 {
     if (is_array($aThing)) {
         $arr = $aThing;
     } else {
         if (is_object($aThing) && $aThing instanceof ToArrayInterface) {
             $arr = $aThing->toArray();
         } else {
             throw new Exception("Could not convert to array: '" . (is_object($aThing) ? get_class($aThing) : $aThing) . "'");
         }
     }
     if ($aDeep) {
         foreach ($arr as $k => $v) {
             if (is_null($v) || is_scalar($v)) {
                 $arr[$k] = $v;
             } else {
                 $arr[$k] = StructUtils::toArray($v, $aDeep);
             }
         }
     }
     return $arr;
 }
 public function mergeReverse($aData)
 {
     $incomingData = StructUtils::toArray($aData, true);
     $this->data = StructUtils::merge($incomingData, $this->data);
 }
 public function mergeReverse($aData)
 {
     $this->data = StructUtils::merge(StructUtils::toArray($aData), $this->data);
 }