示例#1
0
文件: Login.php 项目: alebear/horses
 /** @inheritdoc */
 public function execute(Request $request, Router $router)
 {
     if ($this->getState()->getUserId()) {
         return new Redirect($router->getUrlFromAction(Index::class));
     }
     /** @var LoginResponder $responder */
     $responder = $this->prepareResponder(new LoginResponder());
     if ($request->isMethod(Request::METHOD_POST)) {
         $responder->setMessage($this->translator->translate('wrong_credentials'));
     }
     $responder->setCredentials($request->getPostParam('username'), $request->getPostParam('password'));
     return $responder;
 }
示例#2
0
 /**
  * @expectedException \horses\UnknownRouteException
  */
 public function testRouteUnknown()
 {
     $request = $this->getBasicMock('\\horses\\Request');
     $request->query = $this->getBasicMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
     $request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/unknown'));
     $this->router->route($request);
 }
示例#3
0
 /** @inheritdoc */
 public function execute(Request $request, Router $router)
 {
     /** @var ArticleEditResponder $responder */
     $responder = $this->prepareResponder(new ArticleEditResponder());
     if ($request->isMethod(Request::METHOD_POST)) {
         //            $responder->setArticle($article);
         //            return $responder;
     }
     if ($request->getGetParam('id')) {
         $article = $this->entityManager->getRepository('stagecoach\\journal\\Article')->findOneBy(['id' => $request->getGetParam('id')]);
         if (!$article) {
             return new Redirect($router->getUrlFromAction(ArticleList::class), $this->translator->translate('article_not_found'));
         }
     } else {
         $article = new Article();
     }
     $responder->setArticle($article);
     return $responder;
 }
示例#4
0
 /**
  * @param string $actionClassName
  * @param string[] $queryStringParameters
  * @return string
  */
 public function linkToAction($actionClassName, array $queryStringParameters = [])
 {
     return $this->router->getUrlFromAction($actionClassName, $queryStringParameters);
 }
示例#5
0
 /**
  * Redirects to another module and action
  * @param string $route The "module/action" combo in one string
  * @param array $query Query string parameters, will be in the url itself
  * @param array $options Options for the router
  */
 protected function redirect($route, array $query = array(), array $options = array())
 {
     $this->router->redirect(new Route($route, $query, $options));
 }