예제 #1
0
 /**
  * This implements the 'singleton' design pattern
  *
  * @return Conf The one and only instance
  */
 static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new Conf();
     }
     return self::$instance;
 }
예제 #2
0
파일: mvcrouter.php 프로젝트: neel/bong
 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);
 }
예제 #3
0
파일: urlanalyzer.php 프로젝트: neel/bong
 /**
  * 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;
 }
예제 #4
0
파일: test0.php 프로젝트: neel/bong
/**
 * 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"));
var_dump($path->evaluate(":mkt.etc.conf"));
$conf = Conf::instance();
var_dump($conf->evaluate("urlpatterns.sync"));