public function __construct() { $this->project = Fstab::instance()->project(Mempool::instance()->get("bong.project.current")); $this->controller = Mempool::instance()->get("bong.mvc.controller"); $this->method = Mempool::instance()->get("bong.mvc.method"); $this->url = Mempool::instance()->get("bong.url.path"); $this->base = MemPool::instance()->get("bong.url.base"); $this->root = MemPool::instance()->get("bong.url.root"); }
private function directiveToXPath($path, &$projectDir = "", &$controllerName = "", &$methodName = "", &$spiritName = "", &$terminal = "") { $projectName = ""; $branches = explode('.', $path); $nullPos = -1; $i = 0; /** * +controllerName * -methodName * *spiritName * @arbitraryFileName */ $branches = array_map(function ($value) use(&$projectName, &$controllerName, &$methodName, &$spiritName, &$terminal, &$i, &$nullPos) { ++$i; if ($nullPos > -1) { return $value; } if (preg_match("~\\:(\\w+)~", $value, $m) > 0) { $projectName = $m[1]; return "bong:path[@name='project']"; } elseif (preg_match("~^\\+([\\&\\w]+)~", $value, $m) > 0) { $controllerName = $m[1][0] == '&' ? MemPool::instance()->get('bong.mvc.controller') : $m[1]; return "bong:path[@name='controller']"; } elseif (preg_match("~^\\-([\\&\\w]+)~", $value, $m) > 0) { $methodName = $m[1][0] == '&' ? MemPool::instance()->get('bong.mvc.method') : $m[1]; return "bong:path[@name='method']"; } elseif (preg_match("~^\\*([\\&\\w]+)~", $value, $m) > 0) { $spiritName = $m[1]; return "bong:path[@name='spirit']"; } elseif (preg_match("~^\\@([\\&\\w\\S]+)~", $value, $m) > 0) { if ($m[1][0] == '&') { $terminal = in_array($m[1][1], array('c', 'C')) ? MemPool::instance()->get('bong.mvc.controller') : (in_array($m[1][1], array('m', 'M')) ? MemPool::instance()->get('bong.mvc.method') : substr($m[1], 1)); } else { $terminal = $m[1]; } $nullPos = $i - 1; return null; } return "bong:path[@name='{$value}']"; }, $branches); if ($nullPos > -1) { $termExprs = array(); $len = count($branches); for ($i = $nullPos; $i < $len; ++$i) { $termExprs[] = array_pop($branches); } $terminal .= implode('.', array_reverse($termExprs)); } if ($branches[count($branches) - 1] == "bong:path[@name='project']") { $branches[] = "bong:path[@name='self']"; } $projectDir = Fstab::instance()->projectDirectory($projectName); return "//bong:reposetory/" . implode('/', $branches); }
public function generate() { $projectLocation = Fstab::instance()->projectLocation($this->_name); if (!opendir($projectLocation)) { mkdir($projectLocation, 0777); } foreach ($this->_controllers as $controller) { $controller->generate(); } foreach ($this->_spirits as $spirit) { $spirit->generate(); } }
public function select($projectName) { $backend = null; if (Backend::ExistsUnSessioned('explorer.' . $projectName)) { $explorer = Backend::LoadUnSessioned('explorer.' . $projectName); } else { $explorer = Structs\Admin\Project::create($projectName); /*Create From reflection*/ } $this->data->explorer = $explorer; $this->xdo->project = Fstab::instance()->project($projectName); $this->data->project = $explorer; $this->data->controllers = $explorer->controllers(); $this->data->spirits = $explorer->spirits(); //Backend::saveUnSessioned('explorer.'.$projectName, $explorer); }
public function show($projectName) { $this->xdo->project = Fstab::instance()->project($projectName); }
/** * @return Project */ public static final function currentProject() { return Fstab::instance()->project(Runtime::$_currentProject); }
<div class="bong-admin-box" style="height: 250px;width: 700px;"> <?php foreach (Fstab::instance()->projectNames() as $projectName) { ?> <bong:spirit name="ProjectBox" call="show"> <bong:param value="<?php echo $projectName; ?> " /> </bong:spirit> <?php } ?> <bong:spirit name="ProjectBox" call="create" /> <div class="bong-admin-box-header">Showing All Projects listed in <a href="#">Fstab</a></div> <?php /*Dump::r($data->form)*/ /*print_r($data->fsm['f0a61c7e8ce7aee55a5e88f733b5f65a'])*/ /*Dump::r($data->report->errors())*/ ?> </div>
/** * Returns a Suitable ContentRouter Object based upon the URL Pattern * The Caller needs to extract the engine from the Router through the appropiate Getter * the Validate the Engine then Run the Engine * $engine = $router->engine(); * $engine->check(); or $engine->validate(); * $engine->run(); */ public function decide() { $projectName = null; // issue #31 https://github.com/neel/bong/issues/31 $urlparts = strlen(trim($this->url, "/")) ? explode('/', trim($this->url, "/")) : array(); //Slash The Url $reqUrlParts = explode('/', trim($_SERVER['REQUEST_URI'], "/")); $urlroot = '/' . implode('/', array_slice($reqUrlParts, 0, count($reqUrlParts) - count($urlparts))); MemPool::instance()->set("bong.url.root", $urlroot); /** * URL with Default Project: * controllername * controllername/methodname * controllerName.extension/methodName * image.png * The Extension could be anything like dbg, mc, static, sync etc.. * * URL with default / non default Project Name * ~projectName/controllername * ~projectName/controllername/methodname * ~projectName/controllerName.extension/methodName * ~projectName/image.png */ $projectExt = null; if (count($urlparts) && substr_count($urlparts[0], '~') == 1) { $projectName = substr(array_shift($urlparts), 1); if (substr_count($projectName, '.') == 1) { $parts = explode('.', $projectName); $projectName = $parts[0]; $projectExt = $parts[1]; } } elseif (count($urlparts) && substr_count($urlparts[0], '~') > 1) { throw new MalformedUrlException(); } else { $projectName = Fstab::instance()->defaultProjectName(); } if (Fstab::instance()->projectExists($projectName)) { $projectLocation = Fstab::instance()->projectLocation($projectName); if ($projectLocation && is_dir($projectLocation)) { if (is_readable($projectLocation)) { MemPool::instance()->set("bong.project.current", $projectName); Runtime::setCurrentProject($projectName); } else { throw new ProjectDirNotReadableException($projectName . ''); } } else { throw new ProjectDirNotFoundException($projectName . ''); } } else { throw new ProjectNotFoundException($projectName . ''); } $urlbase = '/' . implode('/', array_slice($reqUrlParts, 0, count($reqUrlParts) - count($urlparts))); MemPool::instance()->set("bong.url.base", $urlbase); $urlExtracted = '/' . implode('/', $urlparts); //{ Start FSM Handling /** * Now if invoked /~project.fsm * load the fsm display */ if ($projectExt == 'fsm') { return RouterFactory::produce('FSMRouter'); } //} end FSM Handling $patterns = array('resource.local' => Conf::instance()->evaluate('urlpatterns.resource.local'), 'resource.sys' => Conf::instance()->evaluate('urlpatterns.resource.sys'), 'service.app' => Conf::instance()->evaluate('urlpatterns.service.app'), 'service.spirit' => Conf::instance()->evaluate('urlpatterns.service.spirit')); $type = 'mvc'; //var_dump($urlExtracted); foreach ($patterns as $key => $pattern) { //echo ">> {$urlExtracted} => $pattern\n"; assert('!empty($pattern)' . "/*{$key} => {$pattern}*/"); if (preg_match($pattern, $urlExtracted, $m)) { //echo ">>\tMatched!\n"; $type = $key; break; } } MemPool::instance()->set("bong.router.pattern", $type); /* AbstractContentRouter* */ $router = null; switch ($type) { case 'resource.local': case 'resource.sys': $router = RouterFactory::produce('ResourceRouter'); break; case 'service.app': $router = RouterFactory::produce('AppServiceRouter'); break; case 'service.spirit': $router = RouterFactory::produce('SpiritServiceRouter'); break; case 'mvc': $router = RouterFactory::produce('MVCRouter'); break; } /** * $router = RouterFactory::produce($key); * $router->route(); * -- in Router -- * AbstractContentEngine* $this->engine = $this->engine(); * -- in AbstractContentRouter::engine() -- * return EngineFactory::produce($key); * -- Another Style -- * Factory::Router::produce() * Factory::Engine::produce() */ $router->setProjectName($projectName); $router->buildNavigation($urlparts); $router->prepareEngine(); return $router; }
* e.g. will be / concated with teh root and then executed as absolute. */ MemPool::instance()->set("bong.root", rtrim(getcwd(), "/")); /** * Slash the Url to Get URL Parts. * e.g. exploding it with '/' will extract all URL Parts in an array */ MemPool::instance()->set("bong.url.path", $_SERVER['PATH_INFO']); /** * \required instances * Fstab Project details * Path Path details * Conf Configuration details * URLAnalyzer URL details */ $fstab = Fstab::instance(); print_r($fstab->defaultProjectName()); echo PHP_EOL; print_r($fstab->defaultProject()); print_r($fstab->projectNames()); print_r($fstab->projects()); print_r($fstab->projectExists("bong")); echo PHP_EOL; print_r($fstab->projectLocation("main")); echo PHP_EOL; var_dump($fstab->project("main")->exists()); echo "\n--------------------------\n"; $path = Path::instance(); var_dump($path->evaluate("etc.conf")); var_dump($path->evaluate(":mkt")); var_dump($path->evaluate("project:mkt"));
public function run() { if (Fstab::instance()->projectExists($this->projectName)) { $projectDir = Path::instance()->evaluate(':' . $this->projectName); if (is_dir($projectDir)) { $evPath = $this->navigation->systemResource ? '' : ":{$this->projectName}."; $evPath .= "share."; switch ($this->navigation->resourceType) { case 'img': $evPath .= 'image'; break; case 'css': $evPath .= 'css'; break; case 'js': $evPath .= 'javascript'; break; case 'xslt': $evPath .= 'xslt'; break; case 'scrap': $evPath .= 'scrap'; break; default: } $evPath .= ".@{$this->navigation->estimatedContentName}"; $resourcePath = Path::instance()->evaluate($evPath); if (is_file($resourcePath)) { $mime = mime_content_type($resourcePath); switch ($this->navigation->resourceType) { case 'img': http::contentType($mime); break; case 'css': http::contentType('text/css'); break; case 'js': http::contentType('text/javascript'); break; case 'xslt': http::contentType('text/xml+xslt'); break; case 'scrap': http::contentType('text/plain'); break; default: } switch ($this->navigation->resourceType) { case 'img': $this->responseBuffer = file_get_contents($resourcePath); break; default: ob_start(); require $resourcePath; $this->responseBuffer = ob_get_contents(); ob_end_clean(); } } else { throw new FileNotFoundException($resourcePath ? $resourcePath : 'null <Resource Path Could not be Resolved> '); } } else { throw new ProjectDirNotFoundException($this->projectName); } } else { throw new ProjectNotFoundException($this->projectName); } }