Example #1
0
File: Factory.php Project: cti/core
 /**
  * @return Application
  */
 function getApplication()
 {
     if (!isset($this->application)) {
         if ($this->generate || !file_exists($this->filename)) {
             $this->manager->get('Cti\\Core\\Application\\Generator');
         }
         $this->application = $this->manager->get('Build\\Application');
     }
     return $this->application;
 }
Example #2
0
File: Web.php Project: cti/core
 /**
  * run web processor
  * @throws \Cti\Core\Exception
  * @throws \Exception
  */
 public function run()
 {
     $mount = array();
     foreach ($this->controllers as $path => $controllerName) {
         $mount[$path] = strlen($path);
     }
     arsort($mount);
     $controller = null;
     foreach (array_keys($mount) as $path) {
         if (strpos($this->location, $path) === 0) {
             $controller = $this->controllers[$path];
             $chain = explode('/', substr($this->location, strlen($path)));
             break;
         }
     }
     if (!$controller) {
         throw new Exception(sprintf("No controller can process url: %s", $this->location));
     }
     $chain = array_values(array_filter($chain, 'strlen'));
     try {
         $slug = count($chain) ? array_shift($chain) : '';
         $method = $this->method . String::convertToCamelCase($slug);
         if (method_exists($controller, $method)) {
             $result = $this->manager->call($controller, $method, array_merge($chain, array('chain' => $chain)));
         } elseif (method_exists($controller, 'processChain')) {
             if ($slug != 'index') {
                 array_unshift($chain, $slug);
             }
             $result = $this->manager->call($controller, 'processChain', array('chain' => $chain));
         } else {
             throw new Exception("Not found", 404);
         }
     } catch (\Exception $e) {
         if (!method_exists($controller, 'processException')) {
             throw $e;
         }
         $result = $this->manager->call($controller, 'processException', array($e, 'exception' => $e));
     }
     echo $result;
 }