Permalink
Browse files

Symfony 2.4 provides status-code constants now

  • Loading branch information...
indeyets committed Feb 2, 2014
1 parent ed0bc1d commit b4c97e5037f4e90057d6b733a099bb33e8b2fbda
Showing with 14 additions and 14 deletions.
  1. +4 −4 composer.json
  2. +10 −10 src/GridsBy/OAuth/WebHandler.php
View
@@ -3,10 +3,10 @@
"description": "CLI-tool for OAuth tests",
"require": {
"aip/aip": "~0.10.0",
- "symfony/console": "~2.3",
- "symfony/yaml": "~2.3",
- "teapot/status": "dev-master",
- "twig/twig": "~1.13"
+ "symfony/console": "~2.4",
+ "symfony/http-foundation": "~2.4",
+ "symfony/yaml": "~2.4",
+ "twig/twig": "~1.15"
},
"license": "MIT",
"authors": [
@@ -3,7 +3,7 @@
use AiP\Middleware\URLMap;
-use Teapot\HttpResponse\Status\StatusCode;
+use Symfony\Component\HttpFoundation\Response;
class WebHandler extends URLMap
@@ -19,7 +19,7 @@ public function __construct()
$this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem($root.'/templates'));
parent::__construct([
- '/favicon.ico' => function(){ return array(StatusCode::NOT_FOUND, array('Content-type', 'text/plain'), 'Page not found'); },
+ '/favicon.ico' => function(){ return array(Response::HTTP_NOT_FOUND, array('Content-type', 'text/plain'), 'Page not found'); },
'/' => [$this, 'index'],
'/callback/' => [$this, 'callback'],
]);
@@ -33,7 +33,7 @@ public function index($ctx)
$body = $this->twig->render('index.twig', $data);
- return [StatusCode::OK, ['Content-type', 'text/html; charset=utf-8'], $body];
+ return [Response::HTTP_OK, ['Content-type', 'text/html; charset=utf-8'], $body];
} else {
if (array_key_exists('action', $ctx['_POST'])) {
if ($ctx['_POST']['action'] == 'request_token') {
@@ -48,40 +48,40 @@ public function index($ctx)
}
}
- return [StatusCode::BAD_REQUEST, ['Conent-type', 'text/html; charset=utf-8'], 'Bad request'];
+ return [Response::HTTP_BAD_REQUEST, ['Conent-type', 'text/html; charset=utf-8'], 'Bad request'];
}
}
public function callback($ctx)
{
if (isset($ctx['_GET']['oauth_token'])) {
if (!isset($ctx['_GET']['oauth_verifier'])) {
- return [StatusCode::BAD_REQUEST, ['Content-type', 'text/html'], '<h1>Bad request</h1><p>Verifier is expected</p>'];
+ return [Response::HTTP_BAD_REQUEST, ['Content-type', 'text/html'], '<h1>Bad request</h1><p>Verifier is expected</p>'];
}
$token = $ctx['_GET']['oauth_token'];
$verifier = $ctx['_GET']['oauth_verifier'];
if ($token !== $this->client->configData()['tokens']['request_token']) {
- return [StatusCode::NOT_FOUND, ['Content-type', 'text/plain; charset=utf-8'], 'token not found'];
+ return [Response::HTTP_NOT_FOUND, ['Content-type', 'text/plain; charset=utf-8'], 'token not found'];
}
try {
$this->client->fetchAccessToken($verifier);
} catch (\Exception $e) {
$body = '<h1>Failed to fetch Access Token</h1><p>'.$e->getMessage().'</p>';
- return [StatusCode::INTERNAL_SERVER_ERROR, ['Content-type', 'text/html'], $body];
+ return [Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-type', 'text/html'], $body];
}
} elseif (isset($ctx['_GET']['denied'])) {
$token = $ctx['_GET']['denied'];
if ($token !== $this->client->configData()['tokens']['request_token']) {
- return [StatusCode::NOT_FOUND, ['Content-type', 'text/plain; charset=utf-8'], 'token not found'];
+ return [Response::HTTP_NOT_FOUND, ['Content-type', 'text/plain; charset=utf-8'], 'token not found'];
}
$this->client->resetRequestToken();
} else {
- return [StatusCode::BAD_REQUEST, ['Content-type', 'text/html'], '<h1>Bad request</h1>'];
+ return [Response::HTTP_BAD_REQUEST, ['Content-type', 'text/html'], '<h1>Bad request</h1>'];
}
return $this->redirectAfterPost('http://127.0.0.1:8081/');
@@ -90,7 +90,7 @@ public function callback($ctx)
private function redirectAfterPost($url)
{
return [
- StatusCode::SEE_OTHER,
+ Response::HTTP_SEE_OTHER,
[
'Content-type', 'text/html; charset=utf-8',
'Location', $url

0 comments on commit b4c97e5

Please sign in to comment.