/**
  * @param string $message
  * @param int $code
  * @param int $severity
  * @param string $filename
  * @param int $lineno
  * @param \Exception $previous
  */
 public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
 {
     parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
     try {
         AppKernel::log('error', $this->getMessage(), array('code' => $code, 'exception' => $this));
     } catch (\Exception $e) {
     }
 }
예제 #2
0
 /**
  * @param string $message
  * @param int $code
  * @param \Exception $previous
  */
 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     parent::__construct($message, $code, $previous);
     try {
         AppKernel::log('error', $this->getMessage(), array('code' => $code, 'exception' => $this));
     } catch (\Exception $e) {
     }
 }
 /**
  * Build the global layout with all children contents
  *
  * @param   array   $params     An array of the parameters passed for the view parsing
  * @return  string  Returns the view file content rendering
  */
 public function renderLayout(array $params = array())
 {
     $params = array_merge($this->getParams(), $params);
     $children = array();
     foreach ($this->_children as $name => $item) {
         if (Helper::classImplements($item, AppKernel::getApi('template'))) {
             $children[$name] = $item->render();
         } else {
             $children[$name] = $item;
         }
     }
     $params = array_merge($params, $children);
     $params['children'] = $children;
     return $this->render($this->getView(), $params);
 }
 /**
  * This must allow some shortcuts to access a service
  *
  * @param   string  $name
  * @param   array   $arguments
  * @return  mixed
  */
 public static function __callStatic($name, array $arguments)
 {
     // getNew('name')
     if ($name == 'getNew') {
         $service_name = isset($arguments[0]) ? $arguments[0] : null;
         array_shift($arguments);
         if (!empty($service_name)) {
             return AppKernel::getInstance()->unsetService($service_name)->getService($service_name, $arguments);
         }
         return null;
         // get('name') or getName()
     } elseif (substr($name, 0, 3) == 'get') {
         if (strlen($name) > 3) {
             $service_name = substr($name, 3);
         } else {
             $service_name = isset($arguments[0]) ? $arguments[0] : null;
             array_shift($arguments);
         }
         if (!empty($service_name)) {
             return AppKernel::getInstance()->getService($service_name, $arguments);
         }
         return null;
         // set('name', $obj) or setName($obj)
     } elseif (substr($name, 0, 3) == 'set') {
         if (strlen($name) > 3) {
             $service_name = substr($name, 3);
             $service_callback = isset($arguments[0]) ? $arguments[0] : null;
             $service_overwrite = isset($arguments[1]) ? $arguments[1] : null;
         } else {
             $service_name = isset($arguments[0]) ? $arguments[0] : null;
             $service_callback = isset($arguments[1]) ? $arguments[1] : null;
             $service_overwrite = isset($arguments[2]) ? $arguments[2] : null;
         }
         if (!empty($service_name) && !empty($service_callback)) {
             if (!empty($service_overwrite)) {
                 AppKernel::getInstance()->setService($service_name, $service_callback, $service_overwrite);
             } else {
                 AppKernel::getInstance()->setService($service_name, $service_callback);
             }
         }
     }
     return null;
 }
 /**
  * @param   null|string     $controller
  * @param   null|string     $action
  * @param   array           $arguments
  * @return  string
  * @throws  \MVCFundamental\Exception\InternalServerErrorException
  */
 public function callControllerAction($controller = null, $action = null, array $arguments = array())
 {
     $this->boot();
     $controller_name = $controller;
     if (empty($controller)) {
         $controller = $this->getOption('default_controller_name');
     }
     if (empty($action)) {
         $action = $this->getOption('default_action_name');
     }
     if (!empty($controller)) {
         if (!is_object($controller)) {
             $ctrl = $this->get('locator')->locateController($controller);
             if (!empty($ctrl)) {
                 $controller = new $ctrl();
             } else {
                 throw new InternalServerErrorException(sprintf('Unknown controller "%s"!', $controller_name));
             }
         }
         $arguments = array_merge(Helper::getDefaultEnvParameters(), $arguments);
         $action = $this->get('locator')->locateControllerAction($action, $controller);
         if (!method_exists($controller, $action) || !is_callable(array($controller, $action))) {
             throw new InternalServerErrorException(sprintf('Action "%s" in controller "%s" is not known or not callable!', $action, $controller_name));
         }
         $result = Helper::fetchArguments($action, $arguments, $controller);
         // result as a raw content: a string
         if (is_string($result)) {
             return $result;
             // result as an array like ( view_file , params )
         } elseif (is_array($result)) {
             $view_file = $this->get('template_engine')->getTemplate($result[0]);
             if (!empty($view_file)) {
                 return $this->render($view_file, isset($result[1]) && is_array($result[1]) ? array_merge($arguments, $result[1]) : $arguments);
             }
             // a reponse object
         } elseif (is_object($result) && ($ri = AppKernel::getApi('response')) && $result instanceof $ri) {
             $this->set('response', $result);
         }
     }
     return '';
 }
예제 #6
0
})->addRoute('/hello/{name}', function ($name) use($fctrl) {
    return 'Hello ' . $name;
})->addRoute('/hello/{name}/controller', 'Demo\\DefaultController')->addRoute('/hello/{name}/method', 'mytest')->addRoute('/hello/{name}/view', 'src/templates/test.php')->addRoute('/hello/{name}/myview', 'myview')->addRoute('/hello/{name}/id/{id:\\d+}', 'args')->addRoute('/hello/{name}/id/{id:\\d+}/alt', 'altargs')->addRoute('/hello/{name}/test', array('\\Demo\\TestController', 'test'))->addRoute('/form', 'form')->addRoute('/saveform', 'saveForm', 'post')->addRoute('/error', function () use($fctrl) {
    trigger_error('a user test error ...', E_USER_ERROR);
})->addRoute('/exception', function () use($fctrl) {
    throw new \Exception('a user test exception ...');
})->addRoute('/notfoundexception', function () use($fctrl) {
    throw new \MVCFundamental\Exception\NotFoundException('a user test exception ...');
})->addRoute('/accessforbiddenexception', function () use($fctrl) {
    throw new \MVCFundamental\Exception\AccessForbiddenException('a user test exception ...');
})->addRoute('/servererror', function () use($fctrl) {
    throw new \MVCFundamental\Exception\InternalServerErrorException('a user test exception ...');
})->addRoute('/twoexceptions', function () use($fctrl) {
    throw new \MVCFundamental\Exception\InternalServerErrorException('a user test exception ...', 1, new \MVCFundamental\Exception\Exception('a secondary (previous) exception ...'));
})->addRoute('/debug', function () use($fctrl) {
    \MVCFundamental\Commons\Helper::debug(\MVCFundamental\AppKernel::getInstance());
})->addRoute('/logs', function () use($fctrl) {
    $log_dir = $fctrl->getOption('temp_dir');
    $dh = opendir($log_dir);
    $logs = array();
    $logs[] = 'LOGS DIR : ' . $log_dir;
    while (false !== ($filename = readdir($dh))) {
        if (substr($filename, -4) == '.log') {
            $logs[] = '##### ' . $filename;
            $logs[] = file_get_contents($log_dir . '/' . $filename);
        }
    }
    call_user_func_array(array('MVCFundamental\\Commons\\Helper', 'debug'), $logs);
})->on('event.1', array('Demo\\DefaultController', 'eventHandler'))->addRoute('/test/event2', function () use($fctrl) {
    $fctrl->trigger('event.2');
    return 'Event 2 was triggered';
 /**
  * @param array $arguments
  * @return mixed
  */
 public function getDefaultLayout(array $arguments = array())
 {
     $view = FrontController::getInstance()->getOption('default_layout');
     $class = FrontController::getInstance()->getOption('default_layout_class');
     if (class_exists($class) && Helper::classImplements($class, AppKernel::getApi('layout'))) {
         $layout = new $class($arguments);
         $layout->setLayout($view);
         return $layout;
     }
     return null;
 }