router = $router; $this->settingManager = $settingManager; } /** * @return BSTGenesis|mixed */ public function getBST_public(){ $s = $this->settingManager->get(self::SETTINGS_BST_PUBLIC,null,false,"js_routing"); if(is_null($s)) return $this->buildAndStoreBST_public(); return json_decode($s,true); } public function getBST_private(){ $s = $this->settingManager->get(self::SETTINGS_BST_PRIVATE,null,false,"js_routing"); if(is_null($s)) return $this->buildAndStoreBST_private(); return json_decode($s,true); } public function getBase64JsonBST_public(){ $bst = $this->getBST_public(); return base64_encode(json_encode($bst)); } public function getBase64JsonBST_private(){ $bst = $this->getBST_private(); return base64_encode(json_encode($bst)); } /** * @return BSTGenesis */ public function buildAndStoreBST_public(){ $bst = $this->buildBST(); $bst = json_encode($bst); $this->settingManager->update(self::SETTINGS_BST_PUBLIC,$bst); return json_decode($bst,true); } public function buildAndStoreBST_private(){ $bst = $this->buildBST(false); $bst = json_encode($bst); $this->settingManager->update(self::SETTINGS_BST_PRIVATE,$bst); return json_decode($bst,true); } /** * build and balance the BST * * @param bool $public * @return BSTGenesis */ public function buildBST($public = true){ $router = $this->router; $collection = $router->getRouteCollection(); $allRoutes = $collection->all(); $structure = new BSTGenesis(); foreach ($allRoutes as $k=>$v){ /** * @var Route $v */ if( !str_contains('_profiler',$k) && !str_contains('_wdt',$k) && !str_contains('_twig_error_test',$k) && $v instanceof Route ){ $do = false; if($public && !str_contains('.private',$k) ){ $do = true; } else if (!$public){ $do = true; } $opt= $collection->get($k)->getDefaults(); if(isset($opt['_controller'])) unset($opt['_controller']); if(isset($opt['controller'])) unset($opt['controller']); if($do){ $el = [ "path" => $v->getPath(), "name" => $k, "option" => $opt, ]; $structure->addElement($k,$el); } } } $structure->balance(); return $structure; } }