/** * Expects an Array with **Exactly** one Argument Thats teh Shared Component's Name * e.g. the Image Name / The CSS Name etc.. * Set's the ContentName via navigation->contentName which will be accessed Via Engine Latter */ public function buildNavigation($path) { $this->navigation->systemResource = MemPool::instance()->get("bong.router.pattern") == 'resource.sys'; $itr = $this->navigation->systemResource ? 3 : 2; $this->navigation->resourceType = $path[$itr - 1]; $path = array_slice($path, $itr); $this->navigation->contentName = implode('/', $path); $extParts = explode('.', array_pop($path)); $ext = count($extParts) >= 2 ? end($extParts) : null; $this->navigation->extension = $ext; $preferedExtension = null; switch ($this->navigation->resourceType) { case 'sys': case 'scrap': $preferedExtension = null; break; case 'img': $preferedExtension = 'png'; break; case 'js': $preferedExtension = 'js'; break; case 'css': $preferedExtension = 'css'; break; case 'xslt': $preferedExtension = 'xsl'; break; default: } $this->navigation->preferedExtension = $preferedExtension; $this->navigation->followSpecifiedExtension = $this->navigation->resourceType == 'img' ? !(!$ext && $preferedExtension) : is_null($preferedExtension) || $ext == $preferedExtension; $this->navigation->estimatedContentName = !$this->navigation->followSpecifiedExtension ? rtrim($this->navigation->contentName, '.') . '.' . $preferedExtension : $this->navigation->contentName; //print_r($this->navigation); }
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"); }
public function buildNavigation($path) { //var_dump($path); //http://localhost/bong/index.php/controllerName/methodName/arg1/arg2/+spiritName/methodName/spiritArg1/spiritArg2/+spiritName2/methodName/args $this->navigation->controllerName = null; $this->navigation->methodName = null; $this->navigation->args = array(); $this->navigation->spirits = array(); $racks = array(); foreach ($path as $i => $urlSection) { if (strlen($urlSection) > 0 && $urlSection[0] == '+') { $racks[] = array(); } $racks[count($racks) == 0 ? count($racks) : count($racks) - 1][] = $urlSection; } foreach ($racks as $i => &$rack) { if ($i == 0) { $this->navigation->controllerName = isset($rack[0]) && !empty($rack[0]) ? $rack[0] : Conf::instance()->evaluate('default.controller'); $this->navigation->methodName = isset($rack[1]) && !empty($rack[1]) ? $rack[1] : Conf::instance()->evaluate('default.method'); for ($i = 2; $i < count($rack); ++$i) { $this->navigation->args[] = $rack[$i]; } } else { if (count($rack) > 1) { //Ignore if no MethodName is provided $spirit = new stdClass(); $spirit->spiritName = substr($rack[0], 1); //remove the + sign $spirit->methodName = $rack[1]; $spirit->args = array(); for ($i = 2; $i < count($rack); ++$i) { $spirit->args[] = $rack[$i]; } $this->navigation->spirits[] = $spirit; } } } if (is_null($this->navigation->controllerName)) { $this->navigation->controllerName = 'default'; } if (is_null($this->navigation->methodName)) { $this->navigation->methodName = 'main'; } MemPool::instance()->set('bong.mvc.controller', $this->navigation->controllerName); MemPool::instance()->set('bong.mvc.method', $this->navigation->methodName); Runtime::loadModule('mvc'); //print_r($this->navigation); }
public function buildNavigation($parts) { $__ = explode('.', $parts[0]); $this->navigation->controllerName = $__[0]; $this->navigation->methodName = null; $this->navigation->controllerExtension = $__[1]; $this->navigation->args = array(); for ($i = 1; $i < count($parts); ++$i) { $part = $parts[$i]; switch ($i) { case 1: //MethodName Comes Now if ($part[0] == '-') { $this->navigation->propertyName = substr($part, 1); //Remove the - sign break; //Property NameShould be the last One } else { $this->navigation->methodName = $part; } break; default: //May be Argument or property Name if ($part[0] == '-') { $this->navigation->propertyName = substr($part, 1); //Remove the - sign break; //Property NameShould be the last One } else { $this->navigation->args[] = $part; } } } MemPool::instance()->set('bong.mvc.controller', $this->navigation->controllerName); MemPool::instance()->set('bong.mvc.method', $this->navigation->methodName); }
$_SERVER['QUERY_STRING'] = @$r_get ? $r_get : parse_url($r_url, PHP_URL_QUERY); $_SERVER['SCRIPT_NAME'] = str_replace('batch.php', 'index.php', $_SERVER['SCRIPT_NAME']); //$_SERVER['PATH_TRANSLATED'] = do bong depend on this parameter ? $_SERVER['PHP_SELF'] = str_replace('batch.php', 'index.php', $r_url); $_SERVER['PATH_INFO'] = '/' . trim(str_replace($installation_base, '', $r_url), "/"); $_GET = parse_url($_SERVER['QUERY_STRING']); unset($_POST['payload']); $_POST = @$r_post; if (count($_POST) > 0) { $_SERVER['REQUEST_METHOD'] = 'POST'; } /** * 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", isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'); Runtime::loadModule('rom'); \ROM\BongCurrentUserData::startSession(); $router = URLAnalyzer::instance()->decide(); \ROM\BongCurrentUserData::instance()->load(); if (!\ROM\BongCurrentUserData::instance()->identical()) { \ROM\BongCurrentUserData::reset(); } $urlReq = new \ROM\UrlRequest(time(), session_id(), $_SERVER['SCRIPT_NAME']); \ROM\BongCurrentUserData::instance()->addUrlRequest($urlReq); Runtime::loadModule('dal'); /*AbstractContentEngine* */ $engine = $router->engine(); $engine->run(); HTTPHeaders::send(); $response = $engine->response();
public static function image($imageName) { return rtrim(MemPool::instance()->get("bong.url.base"), '/') . "/sys/rc/img/{$imageName}"; }
public function dumpStrap() { $this->javascript(MemPool::instance()->get("bong.url.base") . '/sys/rc/js/jquery'); $this->javascript(MemPool::instance()->get("bong.url.base") . '/sys/rc/js/dump'); $this->stylesheet(MemPool::instance()->get("bong.url.base") . '/sys/rc/css/dump'); }
private function controller() { $controllerPath = Path::instance()->currentProject('apps.+&controller.@&controller.php'); if (!$controllerPath || !file_exists($controllerPath)) { throw new ControllerNotFoundException(MemPool::instance()->get('bong.mvc.controller'), $controllerPath); } else { if (is_readable($controllerPath)) { return $controllerPath; } else { throw new ControllerNotReadableException(MemPool::instance()->get('bong.mvc.controller')); } } }
/** * 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; }
public function buildNavigation($parts) { $spiritNamePos = -1; $propertyPos = -1; foreach ($parts as $i => $part) { if ($part[0] == '+') { if ($spiritNamePos != -1) { throw new MalformedUrlException(implode('/', $parts)); } $spiritNamePos = $i; } if ($part[0] == '-') { if ($propertyPos != -1) { throw new MalformedUrlException(implode('/', $parts)); } $propertyPos = $i; } } if ($spiritNamePos == -1) { throw new MalformedUrlException(implode('/', $parts)); } $controllerParts = array_slice($parts, 0, $spiritNamePos); $spiritParts = array_slice($parts, $spiritNamePos, $propertyPos == -1 ? count($parts) : $propertyPos - $spiritNamePos); $propParts = $propertyPos == -1 ? array() : array_slice($parts, $propertyPos); /* print_r($controllerParts); print_r($spiritParts); print_r($propParts); */ $controllerName = null; $controllerMethodName = null; $controllerMethodArgs = array(); if (count($controllerParts) > 0) { $controllerName = $controllerParts[0]; if (strpos($controllerParts[0], ".s") === false) { throw new MalformedUrlException(implode('/', $parts)); } else { $controllerName = substr($controllerParts[0], 0, -2); } $controllerMethodName = null; $controllerMethodArgs = array(); if (count($controllerParts) > 1) { $controllerMethodName = $controllerParts[1]; if (count($controllerParts) > 2) { $controllerMethodArgs = array_slice($controllerParts, 2); } } } $spiritName = $spiritParts[0]; $spiritExtension = "res"; $spiritInstanceId = null; if (strpos($spiritParts[0], ".") === false) { throw new MalformedUrlException(implode('/', $parts)); } else { $spiritName = substr($spiritParts[0], 0, strpos($spiritParts[0], ".")); $spiritExtension = substr($spiritParts[0], strpos($spiritParts[0], ".")); if (strpos($spiritName, ':') !== false) { $spiritInstanceId = substr($spiritName, strpos($spiritName, ":") + 1); $spiritName = substr($spiritName, 0, strpos($spiritName, ":")); } } $spiritMethodName = null; $spiritMethodArgs = array(); if (count($spiritParts) > 1) { $spiritMethodName = $spiritParts[1]; if (count($spiritParts) > 2) { $spiritMethodArgs = array_slice($spiritParts, 2); } } $this->navigation->controllerName = $controllerName; $this->navigation->controllerMethodName = $controllerMethodName; $this->navigation->controllerMethodArgs = $controllerMethodArgs; $this->navigation->spiritName = substr($spiritName, 1); $this->navigation->methodName = $spiritMethodName; $this->navigation->args = $spiritMethodArgs; $this->navigation->spiritExtension = substr($spiritExtension, 1); $this->navigation->spiritInstanceId = $spiritInstanceId; $this->navigation->propertyName = $propertyPos == -1 ? null : substr($propParts[0], 1); Mempool::instance()->set('bong.mvc.controller', $this->navigation->controllerName); MemPool::instance()->set('bong.mvc.method', $this->navigation->controllerMethodName); //print_r($this->navigation); }
require "usr/lib/include/xpathconfig.php"; require "usr/lib/include/path.php"; require "usr/lib/include/conf.php"; require "usr/lib/include/decider.php"; require "usr/lib/include/urlanalyzer.php"; /** * Set the current directoty as Bong Root Directoty. * Furtur Directory Manipulation will be relative to this path. * 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;
/** * Just prepends the Bong Installation Directory Full Path to It * @param string $relativePath */ public static function toAbsolutePath($relativePath) { return rtrim(MemPool::instance()->get("bong.root"), "/") . '/' . ltrim($relativePath, "/"); }
public function csrf_resend() { $installation_path = \MemPool::instance()->get('bong.url.base'); $rand = mt_rand() . time() . ''; $rand_token = trim(str_shuffle($rand), 0); $hash_token = sha1(session_id() . 'bong' . $rand_token); $_COOKIE['bong_csrf_token'] = $hash_token; $_COOKIE['bong_csrf_rand'] = $rand_token; }
private final function uid() { return '0x' . (static::feeder() == SpiritAbstractor::ControllerFeeded ? strtoupper(MemPool::instance()->get('bong.mvc.controller')) : '') . $this->_instanceId; }