public function testIsPostParamValid() { $validator = $this->getBasicMock('horses\\Validator'); $validator->expects($this->any())->method('isValid')->will($this->returnCallback(function ($key) { return $key == 'pff'; })); $this->assertTrue($this->request->isPostParamValid('greu', $validator)); $this->assertFalse($this->request->isPostParamValid('another', $validator)); $this->assertFalse($this->request->isGetParamValid('unknown', $validator)); }
/** @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; }
/** @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; }
/** * @param Request $request * @return string[] */ protected function breakdownRoute(Request $request) { $actionName = ''; $parts = explode('/', rtrim($request->getPathInfo(), '/')); array_shift($parts); if ($prefix = $this->config->get(self::CONFIG_KEY_PREFIX)) { if (count($parts) && $parts[0] == $prefix) { array_shift($parts); } } $subnamespaces = $this->config->get(self::CONFIG_KEY_ACTION_SUBNAMESPACES, []); if (is_array($subnamespaces) && count($subnamespaces) && count($parts) && in_array($parts[0], $subnamespaces)) { $actionName = $parts[0] . '\\'; array_shift($parts); } $actionName .= count($parts) ? array_shift($parts) : self::DEFAULT_ACTION; $params = []; while (count($parts)) { $params[array_shift($parts)] = count($parts) ? array_shift($parts) : null; } return [$actionName, $params]; }
/** @inheritdoc */ public function getCredentials(Request $request) { return new UsernamePasswordCredentials($request->getPostParam('username'), $request->getPostParam('password')); }
<?php include_once '../../../../vendor/autoload.php'; use horses\Kernel; use horses\ServerContext; use horses\FrontController; use horses\Request; use stagecoach\ExceptionHandler; use horses\responder\ExceptionResponder; $request = Request::createFromGlobals(); $kernel = new Kernel(dirname(__DIR__), $request->server->get('ENV', Kernel::DEFAULT_ENV), new ServerContext(), new ExceptionHandler(new ExceptionResponder())); (new FrontController())->run($request, $kernel);