Exemple #1
0
 public function importModels(ViewEvent $event)
 {
     $parents = $event->getView()->get('_parents');
     $jsClasses = $this->modelToJsClasses($parents);
     $modelAsJson = $this->modelToJsonData($parents, $event->getView()->get('_models'));
     $template = '';
     if (!empty($jsClasses)) {
         $template = sprintf("\n(function() { \n\t%s })();\n", $jsClasses);
     }
     if (!empty($modelAsJson)) {
         $template .= sprintf("\nMinute.Loader = function(\$scope) { \n\t%s };\n", $modelAsJson);
     }
     $event->setContent($template ? sprintf('<scr' . 'ipt>%s</script>', $template) : '');
 }
 public function importSession(ViewEvent $event)
 {
     if (!$this->database->isConnected()) {
         return;
     }
     /** @var RouteEx $route */
     $view = $event->getView();
     $vars = $view->getVars();
     $route = $view->get('_route');
     $data = $this->getCachedSessionData(false);
     $data['request'] = array_merge(['url' => getenv('REQUEST_URI')], $this->request->getParameters());
     $data['params'] = array_diff_key($route->getDefaults(), array_flip(['controller', 'auth', 'models', '_route']));
     foreach ($vars as $key => $value) {
         if ($key[0] !== '_' && (is_scalar($value) || is_array($value))) {
             $data['vars'][$key] = $value;
         }
     }
     if (!empty($data['site'])) {
         $data['site']['version'] = $this->database->hasRdsAccess() ? 'production' : 'debug';
     }
     $printer = sprintf('<script' . '>Minute.setSessionData(%s)</script>', json_encode($data));
     $event->setContent($printer);
 }