Ejemplo n.º 1
0
 protected function render($template, array $params = [], $layout = 'layout')
 {
     $params = array_merge($params, ['user' => $this->getUser(), 'request' => $this->getRequest()]);
     $params['title'] = isset($params['title']) ? $params['title'] : 'Posts';
     $view = new View($template, $params, $layout);
     $contents = $view->render();
     $response = new Response($contents);
     return $response;
 }
Ejemplo n.º 2
0
 protected function initServices()
 {
     $servicesConfig = $this->config->getSection('services');
     $servicesConfig = $servicesConfig ? $servicesConfig : [];
     $this->components = [];
     foreach ($servicesConfig as $componentId => $componentConfig) {
         $this->validateConfigComponentClass($componentConfig);
         $component = null;
         $componentClass = $componentConfig['class'];
         unset($componentConfig['class']);
         if (isset($componentConfig['params'])) {
             $component = new $componentClass($componentConfig['params']);
             unset($componentConfig['params']);
         } else {
             $component = new $componentClass();
         }
         foreach ($componentConfig as $name => $value) {
             if (property_exists($component, $name)) {
                 $component->{$name} = $value;
             } else {
                 if (method_exists($component, 'set' . ucfirst($name))) {
                     $component->{'set' . ucfirst($name)}($value);
                 } else {
                     throw new SystemException('Class "' . $componentClass . '" has no property "' . $name . '" or method "' . 'set' . ucfirst($name) . '"');
                 }
             }
         }
         $this->components[$componentId] = $component;
     }
     Model::init($this->getComponent('db'));
     View::setTemplateDirectory($this->config->getParameter('templatePath'));
 }