예제 #1
0
 function Execute($layout_override = NULL, $target_override = NULL, $action_override = NULL, $view_override = NULL, $block_override = NULL)
 {
     // try the application block first
     $block = BlockManager::LoadBlockAt(getcwd());
     $appblock = $block;
     if (!is_null($block_override) && $block_override instanceof WaxBlock) {
         // designate a different block as the holder of the necessary files
         $block = $block_override;
     }
     $router = new QueryString();
     $route = $router->Analyze($_SERVER['QUERY_STRING']);
     $context_name = 'Default';
     if (!is_null($target_override)) {
         $context_name = $target_override;
     } else {
         if (isset($route['context']) && !empty($route['context'])) {
             $context_name = $route['context'];
             unset($route['context']);
         }
     }
     $action = 'index';
     if (!is_null($action_override)) {
         $action = $action_override;
     } else {
         if (isset($route['action']) && !empty($route['action'])) {
             $action = $route['action'];
             unset($route['action']);
         }
     }
     $context = $context_name . "Ctx";
     // verify that the controllercontext is in the same block as the views
     if (!file_exists($block->GetBaseDir() . "/contexts/" . $context . ".php")) {
         throw new TargetContextNotFoundException($context);
     } else {
         if (class_exists($context)) {
             $ctrl = new $context();
             if (!$ctrl instanceof ControllerCtx) {
                 throw new InvalidContextException($context);
             }
         } else {
             throw new TargetContextNotFoundException($context);
         }
     }
     $data_for_view = $ctrl->Execute($action, $route);
     $view_ctx = new ViewRenderCtx();
     $viewname = "{$context_name}/{$action}";
     if (!is_null($view_override)) {
         $viewname = $view_override;
     }
     $content_for_layout = $view_ctx->Execute(new View($block, $viewname), $data_for_view);
     $layoutctx = new LayoutRenderCtx();
     $layout = "layout";
     if (!is_null($layout_override)) {
         $layout = $layout_override;
     }
     try {
         return $layoutctx->Execute(new View($block, $layout), $content_for_layout);
     } catch (ViewNotFoundException $vnfe) {
         return $layoutctx->Execute(new View($appblock, $layout), $content_for_layout);
     }
 }
예제 #2
0
파일: WaxBlock.php 프로젝트: laiello/waxphp
 private function loadResources($dir, $include_files = false)
 {
     $dhtml = array("js", "css", "images");
     // creates web-relative path refs
     $php = array("blocks", "include", "roles", "views", "lib", "contexts");
     // creates fs-absolute path refs
     // resource loading loop--
     // determines all javascript, css, and image resources
     // in the current block.
     foreach ($dhtml as $resourcedir) {
         if (is_dir("{$dir}/{$resourcedir}")) {
             foreach (scandir("{$dir}/{$resourcedir}") as $file) {
                 if ($file[0] == '.' || $file[0] == '_') {
                     continue;
                 } else {
                     $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->_blockdir . "/{$resourcedir}/{$file}");
                     $fileparts = explode(".", $file);
                     $title = array_shift($fileparts);
                     $this->_resources[$resourcedir][$title] = $path;
                 }
             }
         }
     }
     // library loading loop--
     // determines all libraries, objects, roles, contexts, etc.
     // that need to be require()'d for this block to work like
     // it should.
     foreach ($php as $resourcedir) {
         if (is_dir("{$dir}/{$resourcedir}")) {
             switch ($resourcedir) {
                 // these are all treated the same --
                 // the only thing that matters is the order,
                 // which is specified in the $php array.
                 case "lib":
                 case "contexts":
                 case "include":
                     require_dir("{$dir}/{$resourcedir}");
                     break;
                 case "views":
                     $this->analyzeViewDir("{$dir}/{$resourcedir}");
                     break;
                     // the idea behind the blocks and roles directories
                     // is pretty much the same
                 // the idea behind the blocks and roles directories
                 // is pretty much the same
                 case "blocks":
                 case "roles":
                     foreach (scandir("{$dir}/{$resourcedir}") as $obj) {
                         if ($obj[0] == '.' || $obj[0] == '_') {
                             continue;
                         }
                         $objname = explode(".", $obj);
                         $key = array_shift($objname);
                         $objval = "{$dir}/{$resourcedir}/{$obj}";
                         if ($resourcedir == "roles") {
                             require_once "{$dir}/{$resourcedir}/{$obj}";
                         } else {
                             $objval = BlockManager::LoadBlockAt("{$dir}/{$resourcedir}/{$obj}");
                         }
                         $this->_resources[$resourcedir][$key] = $objval;
                     }
                     break;
             }
         }
     }
 }
예제 #3
0
파일: wax.php 프로젝트: laiello/waxphp
 static function LoadBlockAt($path)
 {
     return BlockManager::LoadBlockAt($path);
 }