本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getAttribute方法的具体用法?PHP ServerRequestInterface::getAttribute怎么用?PHP ServerRequestInterface::getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
{
try {
$qp = $request->getQueryParams();
$options = ['profileId' => null, 'seek' => ['limit' => $request->getAttribute('limit'), 'offset' => $request->getAttribute('offset')], 'filter' => []];
if (isset($qp['profileId'])) {
$options['profileId'] = (int) $qp['profileId'];
} else {
$options['profileId'] = $this->currentAccountService->getCurrentAccount()->getCurrentProfile()->getId();
}
if (isset($qp['read'])) {
$options['filter']['read'] = QueryBoolean::extract($qp['read']);
}
if (isset($qp['answer'])) {
$options['filter']['answer'] = QueryBoolean::extract($qp['answer']);
}
$feedbackEntities = $this->feedbackService->getFeedbackEntities($options);
$responseBuilder->setStatusSuccess()->setJson(['entities' => array_map(function (Feedback $feedback) {
return $feedback->toJSON();
}, $feedbackEntities)]);
} catch (ProfileNotFoundException $e) {
$responseBuilder->setStatusNotFound()->setError($e);
} catch (SeekException $e) {
$responseBuilder->setStatusBadRequest()->setError($e);
}
return $responseBuilder->build();
}
示例2: handle
/**
* @param Request $request
* @return JsonResponse|EmptyResponse
*/
public function handle(Request $request)
{
$actor = $request->getAttribute('actor');
$Referer = $request->getHeader('Referer');
$params = array_only($request->getParsedBody(), ['identification', 'password']);
$response = $this->apiClient->send(TokenController::class, $actor, [], $params);
if ($response->getStatusCode() === 200) {
$data = json_decode($response->getBody());
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $data->userId);
$token = AccessToken::find($data->token);
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
$response = FigResponseCookies::set($response, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/'));
$response = $this->rememberer->remember($response, $token);
} elseif ($response->getStatusCode() === 401) {
$responseNew = $this->apiClient->send(PingxxTokenController::class, $actor, [], $params);
if ($responseNew->getStatusCode() === 200) {
$data = json_decode($responseNew->getBody());
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $data->userId);
$token = AccessToken::find($data->token);
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
$responseNew = FigResponseCookies::set($responseNew, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/')->withDomain('dashboard.pingxx.com'));
$responseNew = $this->rememberer->remember($responseNew, $token);
return $responseNew;
} else {
return $response;
}
}
return $response;
}
示例3: bindParameter
/**
* @param \Wandu\DI\ContainerInterface $container
* @param \Psr\Http\Message\ServerRequestInterface $request
*/
private function bindParameter(ContainerInterface $container, ServerRequestInterface $request)
{
if ($queryParams = $request->getAttribute('server_params')) {
$container->instance(ServerParams::class, $queryParams);
$container->alias(ServerParamsInterface::class, ServerParams::class);
$container->alias('server_params', ServerParams::class);
}
if ($queryParams = $request->getAttribute('query_params')) {
$container->instance(QueryParams::class, $queryParams);
$container->alias(QueryParamsInterface::class, QueryParams::class);
$container->alias('query_params', QueryParams::class);
}
if ($parsedBody = $request->getAttribute('parsed_body')) {
$container->instance(ParsedBody::class, $parsedBody);
$container->alias(ParsedBodyInterface::class, ParsedBody::class);
$container->alias('parsed_body', ParsedBody::class);
}
if ($cookie = $request->getAttribute('cookie')) {
$container->instance(CookieJar::class, $cookie);
$container->alias(CookieJarInterface::class, CookieJar::class);
$container->alias('cookie', CookieJar::class);
}
if ($session = $request->getAttribute('session')) {
$container->instance(Session::class, $session);
$container->alias(SessionInterface::class, Session::class);
$container->alias('session', Session::class);
}
}
示例4: indexAction
/**
* Returns the view for the ExtJS admin interface
*
* @param ContainerInterface $container Dependency injection container
* @param ServerRequestInterface $request Request object
* @param ResponseInterface $response Response object
* @param array $args Associative list of route parameters
* @return ResponseInterface $response Modified response object with generated output
*/
public static function indexAction(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args)
{
$site = isset($args['site']) ? $args['site'] : 'default';
$lang = isset($args['lang']) ? $args['lang'] : 'en';
$tab = isset($args['tab']) ? $args['tab'] : 0;
$aimeos = $container->get('aimeos');
$cntlPaths = $aimeos->getCustomPaths('controller/extjs');
$context = $container->get('aimeos_context')->get(false, $args, 'backend');
$context = self::setLocale($context, $site, $lang);
$controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths);
$cssFiles = array();
foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths) {
foreach ($paths as $path) {
$jsbAbsPath = $base . '/' . $path;
if (!is_file($jsbAbsPath)) {
throw new \Exception(sprintf('JSB2 file "%1$s" not found', $jsbAbsPath));
}
$jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($path));
$cssFiles = array_merge($cssFiles, $jsb2->getUrls('css'));
}
}
$csrfname = $request->getAttribute('csrf_name');
$csrfvalue = $request->getAttribute('csrf_value');
$router = $container->get('router');
$jqadmUrl = $router->pathFor('aimeos_shop_jqadm_search', array('site' => $site, 'resource' => 'product'));
$jsonUrl = $router->pathFor('aimeos_shop_extadm_json', array('site' => $site, $csrfname => $csrfvalue));
$adminUrl = $router->pathFor('aimeos_shop_extadm', array('site' => '<site>', 'lang' => '<lang>', 'tab' => '<tab>'));
$vars = array('lang' => $lang, 'cssFiles' => $cssFiles, 'languages' => self::getJsonLanguages($aimeos), 'config' => self::getJsonClientConfig($context), 'site' => self::getJsonSiteItem($context, $site), 'i18nContent' => self::getJsonClientI18n($aimeos->getI18nPaths(), $lang), 'uploaddir' => $context->getConfig()->get('uploaddir', '/.'), 'searchSchemas' => $controller->getJsonSearchSchemas(), 'itemSchemas' => $controller->getJsonItemSchemas(), 'smd' => $controller->getJsonSmd($jsonUrl), 'urlTemplate' => $adminUrl, 'jqadmurl' => $jqadmUrl, 'activeTab' => $tab, 'version' => \Aimeos\Slim\Bootstrap::getVersion());
return $container->get('view')->render($response, 'Extadm/index.html.twig', $vars);
}
示例5: handle
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface|RedirectResponse
*/
public function handle(Request $request)
{
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
$server = new Twitter(['identifier' => $this->settings->get('flarum-auth-twitter.api_key'), 'secret' => $this->settings->get('flarum-auth-twitter.api_secret'), 'callback_uri' => $redirectUri]);
$session = $request->getAttribute('session');
$queryParams = $request->getQueryParams();
$oAuthToken = array_get($queryParams, 'oauth_token');
$oAuthVerifier = array_get($queryParams, 'oauth_verifier');
if (!$oAuthToken || !$oAuthVerifier) {
$temporaryCredentials = $server->getTemporaryCredentials();
$session->set('temporary_credentials', serialize($temporaryCredentials));
$session->save();
// Second part of OAuth 1.0 authentication is to redirect the
// resource owner to the login screen on the server.
$server->authorize($temporaryCredentials);
exit;
}
// Retrieve the temporary credentials we saved before
$temporaryCredentials = unserialize($session->get('temporary_credentials'));
// We will now retrieve token credentials from the server
$tokenCredentials = $server->getTokenCredentials($temporaryCredentials, $oAuthToken, $oAuthVerifier);
$user = $server->getUserDetails($tokenCredentials);
$identification = ['twitter_id' => $user->uid];
$suggestions = ['username' => $user->nickname, 'avatarUrl' => str_replace('_normal', '', $user->imageUrl)];
return $this->authResponse->make($request, $identification, $suggestions);
}
示例6: loginPost
public function loginPost(Request $request, Response $response, $args)
{
$identifier = Input::post('identifier');
$password = Input::post('password');
$v = new Validator(new User());
$v->validate(['identifier' => [$identifier, 'required|email'], 'password' => [$password, 'required']]);
if ($request->getAttribute('csrf_status') === false) {
$flash = 'CSRF faiure';
$this->view->render($response, 'login.twig', ['errors' => $v->errors(), 'flash' => $flash, 'request' => $request]);
} else {
if ($v->passes()) {
$user = User::where('username', $identifier)->orWhere('email', $identifier)->first();
if ($user && $this->hash->passwordCheck($password, $user->password)) {
$this->session->set($this->auth['session'], $user->id);
$this->session->set($this->auth['group'], $user->group_id);
return $response->withRedirect('dashboard');
} else {
$flash = 'Sorry, you couldn\'t be logged in.';
$this->view->render($response, 'login.twig', ['errors' => $v->errors(), 'flash' => $flash, 'request' => $request]);
}
} else {
$this->view->render($response, 'login.twig', ['errors' => $v->errors(), 'request' => $request, 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]);
}
}
return $response;
}
示例7: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
if ($request->getAttribute('resourceId') == 666) {
throw new ApiProblemException('You had the try huh?', 666);
}
return new JsonResponse(['ack' => time(), 'action' => 'Read', 'resource' => $request->getAttribute('resource'), 'resourceId' => $request->getAttribute('resourceId')]);
}
示例8: __invoke
public function __invoke(ServerRequestInterface $request)
{
// return ['todoId' => $request->getQueryParams()['todoId'], 'description' => $request->getQueryParams()['description']];
// return [$request->getQueryParams()['todoId'], $request->getQueryParams()['description']];
$todoId = $request->getAttribute('todoId');
$description = $request->getAttribute('description');
return array('todoId' => $todoId, 'description' => $description);
}
示例9: render
/**
* @param Request $request
* @return \Illuminate\Contracts\View\View
* @throws InvalidConfirmationTokenException
*/
public function render(Request $request)
{
$token = array_get($request->getQueryParams(), 'token');
$token = PasswordToken::findOrFail($token);
if ($token->created_at < new DateTime('-1 day')) {
throw new InvalidConfirmationTokenException();
}
return $this->view->make('flarum::reset')->with('translator', $this->translator)->with('passwordToken', $token->id)->with('csrfToken', $request->getAttribute('session')->get('csrf_token'))->with('error', $request->getAttribute('session')->get('error'));
}
示例10: __invoke
public function __invoke(ServerRequestInterface $req, ResponseInterface $res, callable $next)
{
$nameKey = $this->csrf->getTokenNameKey();
$valueKey = $this->csrf->getTokenValueKey();
$name = $req->getAttribute($nameKey);
$value = $req->getAttribute($valueKey);
$this->view['csrf'] = ['name_key' => $nameKey, 'value_key' => $valueKey, 'name' => $name, 'value' => $value];
return $next($req, $res);
}
示例11: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$nameKey = $this->container->csrf->getTokenNameKey();
$valueKey = $this->container->csrf->getTokenValueKey();
$name = $request->getAttribute($nameKey);
$value = $request->getAttribute($valueKey);
$this->container->view->getEnvironment()->addGlobal('csrf', ['keys' => ['name' => $nameKey, 'value' => $valueKey], 'name' => $name, 'value' => $value]);
$response = $next($request, $response);
return $response;
}
示例12: __invoke
public function __invoke(Request $req, Response $res, callable $next) : Response
{
$tag = $req->getAttribute('tag');
$type = $req->getAttribute('type', 'rss');
$path = $tag ? $this->getTagFeedPath($tag, $type) : $this->getFeedPath($type);
if (!file_exists($path)) {
return $next($req, $res->withStatus(404), 'Not found');
}
return $res->withHeader('Content-Type', sprintf('application/%s+xml', $type))->withBody(new Stream(fopen($path, 'r')));
}
示例13: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
$id = $request->getAttribute('id');
$secret = $request->getAttribute('secret');
if ($secret !== $this->secret) {
return $response->withStatus(400, 'not authenticated');
}
$comment = $this->repository->load($id);
$this->repository->delete($comment);
}
示例14: execute
public function execute(Request $req, Response $res, callable $next = null)
{
try {
$id = $req->getAttribute('id');
$name = urldecode($req->getAttribute('name'));
$collection = $this->boot()->get('store')->getCollection($name);
return $next($req, new JsonResponse(['status' => 'ok', 'data' => $collection->delete($collection->item($id))]));
} catch (\Exception $ex) {
return new JsonResponse(['status' => 'error', 'error' => $ex->getMessage()], 500);
}
}
示例15: run
public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
{
try {
$profileId = $request->getAttribute('profileId');
$communitySID = $request->getAttribute('communitySID');
$this->profileCommunitiesService->leaveCommunity($this->currentAccountService->getCurrentAccount()->getProfileWithId($profileId)->getId(), $communitySID);
$responseBuilder->setStatusSuccess();
} catch (AlreadyLeavedException $e) {
$responseBuilder->setError($e)->setStatusConflict();
}
return $responseBuilder->build();
}