示例#1
0
 /**
  * Dispatch a request a context using the fluent interface
  *
  * @param	AppContextInterface $context
  * @return	AppContextInterface
  */
 public function dispatch(MvcContextInterface $context)
 {
     $key = $context->getRouteKey();
     $detail = $this->getRouteDetail($key);
     if (!$detail instanceof MvcRouteDetailInterface) {
         $err = "failed to dispatch: route -({$context->getRouteKey()}) ";
         $err .= "not found ";
         throw new RunTimeException($err, 404);
     }
     $class = $detail->getActionClass();
     if (empty($class)) {
         $namespace = $this->getNamespace($key);
         $class = $namespace . '\\' . $detail->getActionName();
     }
     $action = new $class();
     if (!$action instanceof MvcActionInterface) {
         $err = 'mvc action does not implement Appfuel\\Kernel\\Mvc\\Mvc';
         $err .= 'ActionInterface';
         throw new LogicException($err);
     }
     /*
      * Any acl codes are checked againt the route detail's acl access
      */
     if (!$detail->isAccessAllowed($context->getAclCodes())) {
         $err = 'user request is not allowed: insufficient permissions';
         throw new RunTimeException($err);
     }
     $action->process($context);
 }
示例#2
0
 /**
  * @param	MvcContextInterface $context
  * @return	null
  */
 public function process(MvcContextInterface $context)
 {
     $input = $context->getInput();
     $view = $context->getView();
     if (!ResourceTreeManager::isTree()) {
         ResourceTreeManager::loadTree();
     }
     $finder = new FileFinder('resource');
     $writer = new FileWriter($finder);
     $reader = new FileReader($finder);
     if (!$writer->deleteTree('build', true)) {
         $err = "could not detete -({$finder->getPath('build')})";
         throw new RunTimeException($err);
     }
     $list = ResourceTreeManager::getAllPageNames();
     if (!is_array($list) || empty($list)) {
         return;
     }
     foreach ($list as $pageName) {
         $pkg = ResourceTreeManager::getPkg($pageName);
         $layers = $pkg->getLayers();
         $pageStack = new FileStack();
         foreach ($layers as $layerName) {
             $stack = new FileStack();
             $layer = ResourceTreeManager::loadLayer($layerName, $stack);
             $this->buildLayer($layer, $reader, $writer, $pageStack);
         }
         $this->buildLayer(ResourceTreeManager::createPageLayer($pageName), $reader, $writer, $pageStack);
         $themeName = $pkg->getThemeName();
         if ($themeName) {
             $this->buildTheme($themeName, $reader, $writer, $pageStack);
         }
     }
     $view->assign('result', 'build completed');
 }
示例#3
0
 /**
  * @param   AppContextInterface           $context
  * @param   ConsoleViewTemplateInterface  $view
  * @return  mixed   null | AppContextInterface 
  */
 public function process(MvcContextInterface $context)
 {
     $view = $context->getView();
     $input = $context->getInput();
     $valueC = $input->get('get', 'label-c');
     $valueD = $input->get('get', 'label-d');
     $result = "processed label-a={$valueC} label-b={$valueD}";
     $view->assign('action-c:', $result);
 }
示例#4
0
 /**
  * @param   AppContextInterface           $context
  * @param   ConsoleViewTemplateInterface  $view
  * @return  mixed   null | AppContextInterface 
  */
 public function process(MvcContextInterface $context)
 {
     $view = $context->getView();
     $input = $context->getInput();
     $valueA = $input->get('get', 'label-a');
     $valueB = $input->get('get', 'label-b');
     $result = "processed label-a={$valueA} label-b={$valueB}";
     $view->assign('action-b:', $result);
 }
 /**
  * @param	ContextInterface $context
  * @return	null
  */
 public function filter(MvcContextInterface $context)
 {
     $view = $context->getView();
     if (!$view instanceof ViewTemplateInterface) {
         $this->next($context);
     }
     $value = $view->get('my-assignment', '');
     $value = str_replace(' ', ':', $value);
     $view->assign('my-assignment', $value);
     $this->next($context);
 }
 /**
  * @param	ContextInterface $context
  * @return	null
  */
 public function filter(MvcContextInterface $context)
 {
     $view = $context->getView();
     $value = $view->get('my-assignment', false);
     if (false === $value) {
         return $this->next($context);
     }
     $value = '4 5 6 ' . $value;
     $view->assign('my-assignment', $value);
     $this->next($context);
 }
示例#7
0
 /**
  * @param   AppContextInterface           $context
  * @param   ConsoleViewTemplateInterface  $view
  * @return  mixed   null | AppContextInterface 
  */
 public function process(MvcContextInterface $context)
 {
     $view = $context->getView();
     $params = array('get' => array('label-a' => 'value-a', 'label-b' => 'value-b'));
     $uriB = 'action-b/label-a/value-a/label-b/value-b';
     $uriC = 'action-c/label-c/value-c/label-d/value-d';
     $strategy = $context->getStrategy();
     $contextB = $this->callUri($uriB, $strategy);
     $contextC = $this->callUri($uriC, $strategy);
     $results = $contextB->buildView() . ' and ' . $contextC->buildView();
     $view->assign('results', $results);
 }
示例#8
0
 /**
  * @param   AppContextInterface           $context
  * @param   ConsoleViewTemplateInterface  $view
  * @return  mixed   null | AppContextInterface 
  */
 public function process(MvcContextInterface $context)
 {
     $view = $context->getView();
     $label = 'my-assignment';
     $default = 'this action has been executed';
     $value = $view->get($label, null);
     if (!empty($value) && is_string($value)) {
         $value .= " {$default}";
     } else {
         $value = $default;
     }
     $view->assign($label, $value);
 }
示例#9
0
 /**
  * @param   AppContextInterface           $context
  * @param   ConsoleViewTemplateInterface  $view
  * @return  mixed   null | AppContextInterface 
  */
 public function process(MvcContextInterface $context)
 {
     $strategy = $context->getStrategy();
     $view = $context->getView();
     $view->assign('common-a', 'value-a')->assign('common-b', 'value-b');
     switch ($strategy) {
         case 'console':
             $label = 'console-foo';
             break;
         case 'ajax':
             $label = 'ajax-foo';
             break;
         case 'html':
             $label = 'html-foo';
             break;
     }
     $view->assign($label, 'bar');
 }
示例#10
0
 /**
  * Uses the route detail to detemine if the view is disabled, also
  * checks the data type of the view. Eventhough, ViewInterface implements
  * __toString, it has the possibility of throwing exceptions which in
  * __toString leaves a nasty little error that says simply, you can
  * not throw exceptions in __toString. To avoid this we run build instead
  *
  * @param	MvcContextInterface $context
  * @param	MvcRouteDetailInterface $route
  * @return	string
  */
 public function composeView(MvcContextInterface $context, MvcRouteDetailInterface $route)
 {
     if (!$route->isView()) {
         return '';
     }
     $view = $context->getView();
     if (is_string($view)) {
         $result = $view;
     } else {
         if ($view instanceof ViewInterface) {
             $result = $view->build();
         } else {
             if (is_callable(array($view, '__toString'))) {
                 $result = (string) $view;
             } else {
                 $err = "view must be a string or an object the implements ";
                 $err .= "Appfuel\\View\\ViewInterface or an object thtat implemnts ";
                 $err .= "__toString";
                 throw new DomainException($err);
             }
         }
     }
     return $result;
 }
示例#11
0
 /**
  * @param   MvcContextInterface $context
  * @return  null
  */
 public function process(MvcContextInterface $context)
 {
     $view = $context->getView();
     $view->assign('foo', 'bar');
 }
示例#12
0
 /**
  * @param	MvcRotueDetailInterface $route
  * @param	MvcContextInterface $context
  * @return	null
  */
 public function kernelExecute(array $params = null, MvcRouteDetailInterface $route, MvcContextInterface $context)
 {
     $context->add('test-a', 'value-a');
     $this->execute($params);
 }
示例#13
0
 /**
  * @param	ContextInterface $context
  * @return	null
  */
 public function filter(MvcContextInterface $context)
 {
     $view = $context->getView();
     $view->assign('my-assignment', 'value 1 2 3');
     $this->next($context);
 }
示例#14
0
 /**
  * @param	MvcRotueDetailInterface $route
  * @param	MvcContextInterface $context
  * @return	null
  */
 public function kernelExecute(array $params = null, MvcRouteDetailInterface $route, MvcContextInterface $context)
 {
     $value = $params['test-b'];
     $context->add('test-b', $value);
     $this->execute($params);
 }
示例#15
0
 /**
  * @param	string	$routeKey
  * @param	MvcContextInterface $context
  * @return	MvcContextInterface
  */
 public function callWithContext($routeKey, MvcContextInterface $context)
 {
     $dispatcher = $this->getDispatcher();
     $tmp = $this->getMvcFactory()->createContext($routeKey, $context->getInput());
     $tmp->load($context->getAll());
     $dispatcher->dispatch($tmp);
     /* transfer all assignments made by mvc action */
     $context->load($tmp->getAll());
     $view = $tmp->getView();
     if (!empty($view)) {
         $context->setView($view);
     }
     return $context;
 }