/**
  * 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);
 }
 /**
  * @param   \MVCFundamental\Interfaces\FrontControllerInterface $app
  * @return  void
  * @throws  \MVCFundamental\Exception\ErrorException
  */
 public static function boot(FrontControllerInterface $app)
 {
     // stores the FrontController
     self::setFrontController($app);
     // define internal handlers
     set_exception_handler(array(__CLASS__, 'handleException'));
     register_shutdown_function(array(__CLASS__, 'handleShutdown'));
     if (self::getFrontController()->getOption('convert_error_to_exception') == true) {
         set_error_handler(array(__CLASS__, 'handleError'));
     }
     // the required temporary directory
     $tmp_dir = self::getFrontController()->getOption('temp_dir');
     if (empty($tmp_dir) || !file_exists($tmp_dir) && !@DirectoryHelper::create($tmp_dir) || !is_dir($tmp_dir) || !is_writable($tmp_dir)) {
         $tmp_dir = DirectoryHelper::slashDirname(sys_get_temp_dir()) . 'mvc-fundamental';
         if (!@DirectoryHelper::ensureExists($tmp_dir)) {
             throw new ErrorException(sprintf('The "%s" temporary directory can not be created or is not writable (and a default one could not be taken)!', $tmp_dir));
         }
         self::getFrontController()->setOption('temp_dir', $tmp_dir);
     }
     // the application logger
     if (self::getFrontController()->getOption('minimum_log_level') == null) {
         self::getFrontController()->setOption('log_level', self::getFrontController()->isMode('production') ? Logger::WARNING : Logger::DEBUG);
     }
     $logger_options = array('duplicate_errors' => false, 'directory' => self::getFrontController()->getOption('temp_dir'), 'minimum_log_level' => self::getFrontController()->getOption('log_level'));
     $logger_class = self::getFrontController()->getOption('app_logger');
     if (!class_exists($logger_class) || !Helper::classImplements($logger_class, self::getApi('logger'))) {
         throw new ErrorException(sprintf('A logger must exist and implement the "%s" interface (for class "%s")!', self::getApi('logger'), $logger_class));
     }
     self::set('logger', new $logger_class($logger_options));
     // load services
     foreach (self::getFrontController()->getOptions() as $var => $val) {
         if (array_key_exists($var, self::$_api)) {
             self::set($var, self::apiFactory($var, $val));
         }
         if (array_key_exists($var, self::$_constructors)) {
             $cls_index = self::$_constructors[$var];
             self::getInstance()->setProvider($var, function ($app, $name, array $arguments = array()) use($val, $cls_index) {
                 return $app::apiFactory($cls_index, $val, $arguments);
             });
         }
     }
     self::get('event_manager')->setEventClass(self::getFrontController()->getOption('event_item'));
 }
 /**
  * @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;
 }