Пример #1
0
 /**
  * @param   string $name
  * @return  mixed
  */
 public function locateTemplate($name)
 {
     if (empty($name)) {
         return null;
     }
     if (file_exists($name)) {
         return realpath($name);
     }
     // a user defined locator
     $locator = FrontController::getInstance()->getOption('view_file_locator');
     if (!is_null($locator) && is_callable($locator)) {
         $result = call_user_func($locator, $name);
         if (!empty($result) && file_exists($result)) {
             return $result;
         }
     }
     // in package's resources
     $f = __DIR__ . '/../Resources/templates/' . $name;
     if (file_exists($f)) {
         return realpath($f);
     }
     return null;
 }
Пример #2
0
} else {
    die("SPL autoloader '{$splloader}' not found!'");
}
$classLoader = new SplClassLoader("Demo", __DIR__ . '/src/', SplClassLoader::FAIL_GRACEFULLY);
$classLoader->register();
// ----------------------------------
// FrontController usage
// ----------------------------------
/**
 * @TODOS
 * - security
 * - multiple templates / actions rendering in one page
 */
// front controller creation
$fctrl = \MVCFundamental\FrontController::getInstance(array('mode' => 'dev', 'default_controller_name' => '\\Demo\\DefaultController', 'controller_locator' => function ($name) {
    $class = '\\Demo\\' . ucfirst($name) . 'Controller';
    return class_exists($class) ? $class : null;
}));
// load some predefined settings
$helper = new \Demo\TestHelper();
// test a log message
\MVCFundamental\AppKernel::log('info', 'Test log for request ' . $fctrl->get('request')->getUri());
// routing definitions
$fctrl->addRoute('/', function () use($fctrl) {
    $req = $fctrl->get('request')->getUrl();
    return $fctrl->get('template_engine')->renderDefault(<<<MESAGE
<p><strong>Welcome in the demo!</strong> You will find below various routes to test the package.</p>
<p>To learn how these routes are defined and a quick "how-to", have a look in the source code of file <code>demo/index.php</code>.</p>
<p>To get last source updates or report a bug, see <a href="http://github.com/atelierspierrot/mvc-fundamental">the "atelierspierrot/mvc-fundamental" repository</a>.</p>
<p>Calls of various routes and callbacks:</p>
<ul>
    <li><a href="{$req}hello">/hello</a> : simple closure callback with no argument</li>
 /**
  * @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;
 }
 /**
  * Search a view file in the current file system
  *
  * @param   string  $name   The file path to search
  * @return  string  The path of the file found
  */
 public function getTemplate($name)
 {
     return FrontController::get('template_engine')->getTemplate($name);
 }
 /**
  * @param \Exception $e
  * @param int $type
  * @return string
  */
 protected function _getProductionErrorMessage(\Exception $e, $type = 500)
 {
     $content = '<p>' . FrontController::getInstance()->getOption($type . '_error_info') . '</p>';
     if (FrontController::getInstance()->isMode('dev')) {
         $content .= '<blockquote>' . $e->getMessage() . '</blockquote>';
     }
     return $content;
 }
Пример #6
0
 /**
  * @param   string  $name
  * @param   string  $view
  * @param   array   $params
  * @return  $this
  */
 public function setChild($name, $view, array $params = array())
 {
     $this->_children[$name] = FrontController::get('template_engine')->getNewTemplate($view, $params);
     return $this;
 }
 public function formAction()
 {
     $content = FrontController::get('template_engine')->renderTemplate(self::$views_dir . 'form.php');
     return FrontController::get('template_engine')->renderDefault($content);
 }
Пример #8
0
 /**
  * Get the default environment vars to load in views and calling controller's actions
  * @return array
  */
 public static function getDefaultEnvParameters()
 {
     return array('app' => FrontController::getInstance(), 'template_engine' => FrontController::get('template_engine'), 'request' => FrontController::get('request'), 'response' => FrontController::get('response'), 'data' => FrontController::get('request')->getArguments());
 }
 public function __construct()
 {
     FrontController::getInstance()->on('event.2', array('Demo\\DefaultController', 'eventHandler'))->on('event.1', array('Demo\\TestController', 'eventHandler'));
 }