public function run(DataContainerInterface $applicationData)
 {
     $dataContainerKey = 'request';
     $controllerKey = 'ctrl';
     $actionKey = 'act';
     $basePath = $applicationData->get('config')->get('viewDispatcherPath', '.');
     $controller = $applicationData->get($dataContainerKey)->get($controllerKey);
     $action = $applicationData->get($dataContainerKey)->get($actionKey);
     if (empty($controller) || empty($action)) {
         throw new ApplicationLayerException($this);
     }
     //data for the view
     $data = $applicationData->get('vars');
     $scriptName = ucfirst($controller) . ucfirst($action);
     $fileName = $basePath . '/' . ucfirst($controller) . '/' . $scriptName . '.php';
     if (!file_exists($fileName)) {
         throw new ApplicationLayerException($this, "Cannot find view file : {$fileName}");
     }
     ob_start();
     require $fileName;
     $content = ob_get_clean();
     $fileName = $basePath . '/layout.php';
     if (!file_exists($fileName)) {
         throw new ApplicationLayerException($this, "Cannot find layout file : {$fileName}");
     }
     require $fileName;
 }
Ejemplo n.º 2
0
 /**
  * Get a value by the key of this object
  *
  * @param string $key The key of the value
  * @return mixed The value
  */
 public function get($key)
 {
     try {
         return $this->container->get($key);
     } catch (AccessException $e) {
         throw new AccessException('"' . $key . '" doesn\'t exist in Relationship.');
     }
 }
 public function run(DataContainerInterface $applicationData)
 {
     $dao = new ArticleDaoFileSystem('blog/content/');
     $list = new ArticleList();
     $dao->loadAll($list);
     $hash = $applicationData->get('request')->get('article');
     $applicationData->get('vars')->set('article', $list->getByHash($hash));
 }
Ejemplo n.º 4
0
 /**
  * Get a value by the key of this object
  *
  * @param string $key The key of the value
  * @return mixed The value
  */
 public function get($key)
 {
     try {
         return $this->container->get($key);
     } catch (AccessException $e) {
         throw new AccessException('"' . $key . '" doesn\'t exist in this jsonapi object.');
     }
 }
 public function run(DataContainerInterface $applicationData)
 {
     if (!file_exists($this->filename)) {
         throw new ApplicationLayerException($this, 'Cannot found file ' . $this->filename);
     }
     include $this->filename;
     if (!isset(${$this->varInFile}) || !is_array(${$this->varInFile})) {
         throw new ApplicationLayerException($this, 'The variable <' . $this->varInFile . '> is null or not an array.');
     }
     $applicationData->set($this->key, new DataContainerArrayAdapter(${$this->varInFile}));
 }
 public function run(DataContainerInterface $applicationData)
 {
     $dataContainerKey = 'request';
     $controllerKey = 'ctrl';
     $actionKey = 'act';
     $this->basePath = $applicationData->get('config')->get('controllerDispatcherPath', '.');
     $controller = $applicationData->get($dataContainerKey)->get($controllerKey);
     $action = $applicationData->get($dataContainerKey)->get($actionKey);
     if (empty($controller) || empty($action)) {
         throw new ApplicationLayerException($this, "Controller (<{$controllerKey}>) and/or action (<{$action}>) is not set in dataContainer (<{$dataContainerKey}>).");
     }
     $this->currentApplicationData = $applicationData;
     $this->getControllerInstance($controller, $action)->run($applicationData);
 }
Ejemplo n.º 7
0
 /**
  * Set a link
  *
  * @param string $name The Name
  * @param string $link The Link
  *
  * @return self
  */
 protected function set($name, $link)
 {
     // Pagination: Keys MUST either be omitted or have a null value to indicate that a particular link is unavailable.
     if (!is_null($link)) {
         $this->container->set($name, strval($link));
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Set a link
  *
  * @param string $name The Name
  * @param string|object $link The Link
  *
  * @return self
  */
 protected function set($name, $link)
 {
     if ($name === 'meta') {
         $this->container->set($name, $this->manager->getFactory()->make('Meta', [$link, $this->manager]));
         return $this;
     }
     // from spec: an object ("link object") which can contain the following members:
     // - href: a string containing the link's URL.
     if ($name === 'href' or !is_object($link)) {
         if (!is_string($link)) {
             throw new ValidationException('Link has to be an object or string, "' . gettype($link) . '" given.');
         }
         $this->container->set($name, strval($link));
         return $this;
     }
     // Now $link can only be an object
     // Create Link object if needed
     if (!$link instanceof LinkInterface) {
         $this->container->set($name, $this->manager->getFactory()->make('Link', [$link, $this->manager]));
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Set a link
  *
  * @param string $name The name of the link
  * @param string $link The link
  * @return self
  */
 private function setLink($name, $link)
 {
     if (!is_string($link) and !is_object($link)) {
         throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
     }
     if (is_string($link)) {
         $this->container->set($name, strval($link));
         return $this;
     }
     // Now $link can only be an object
     $link_object = $this->manager->getFactory()->make('Link', [$this->manager, $this]);
     $link_object->parse($link);
     $this->container->set($name, $link_object);
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * Set a link
  *
  * @param string $name The Name
  * @param string|object $link The Link
  *
  * @return self
  */
 protected function set($name, $link)
 {
     if ($name === 'meta') {
         $meta = $this->manager->getFactory()->make('Meta', [$this->manager, $this]);
         $meta->parse($link);
         $this->container->set($name, $meta);
         return $this;
     }
     // every link must be an URL
     if (!is_string($link)) {
         throw new ValidationException('Every link attribute has to be a string, "' . gettype($link) . '" given.');
     }
     $this->container->set($name, strval($link));
     return $this;
 }
Ejemplo n.º 11
0
 /**
  * Set a link
  *
  * @param string $name The Name
  * @param string|object $link The Link
  *
  * @return self
  */
 protected function set($name, $link)
 {
     // from spec: aA link MUST be represented as either:
     // - a string containing the link's URL.
     // - an object ("link object") which can contain the following members:
     if (!is_object($link) and !is_string($link)) {
         throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
     }
     if (is_string($link)) {
         $this->container->set($name, strval($link));
         return $this;
     }
     // Now $link can only be an object
     $link_object = $this->manager->getFactory()->make('Link', [$this->manager, $this]);
     $link_object->parse($link);
     $this->container->set($name, $link_object);
     return $this;
 }
 public function run(DataContainerInterface $applicationData)
 {
     $applicationData->get('vars')->set('title', $applicationData->get('config')->get('application_name'));
     $applicationData->get('vars')->append('message', 'hello from the controller !');
     $this->callController('Another', 'Thing');
 }
 public function run(DataContainerInterface $applicationData)
 {
     $applicationData->set("request", new DataContainerArrayAdapter($_REQUEST));
     $applicationData->set("session", new DataContainerArrayAdapter($_SESSION));
     $applicationData->set("vars", new DataContainerArrayAdapter());
 }
 public function run(DataContainerInterface $applicationData)
 {
     $applicationData->get('vars')->append('message', 'hello from the 2nd controller !');
 }