[BUGFIX] Improvements

- Fixed errors with getRoute method.
- Added Response and Request classes.
- Added CSRF stuff.
- Cleanup and bugfixes.
This commit is contained in:
Simon Sessingø
2015-10-18 17:36:06 +02:00
parent 0650e5ba93
commit b3b362a9e6
11 changed files with 272 additions and 90 deletions
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Pecee\Http\Middleware;
use Pecee\Http\Request;
use Pecee\SimpleRouter\RouterEntry;
abstract class Middleware
{
public function handle(Request $request) {
return true;
}
}
@@ -0,0 +1,9 @@
<?php
namespace Pecee\Http\Middleware;
class VerifyCsrfToken extends Middleware {
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Pecee\Http;
class Request {
protected $uri;
protected $host;
protected $method;
public function __construct() {
$this->host = $_SERVER['HTTP_HOST'];
$this->uri = rtrim($_SERVER['REQUEST_URI'], '/') . '/';
$this->method = (isset($_POST['_method'])) ? strtolower($_POST['_method']) : strtolower($_SERVER['REQUEST_METHOD']);
}
/**
* @return string
*/
public function getUri() {
return $this->uri;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/**
* @return string
*/
public function getMethod() {
return $this->method;
}
/**
* Get http basic auth user
* @return string|null
*/
public function getUser() {
$data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST']);
return (isset($data['username'])) ? $data['username'] : null;
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Pecee\Http;
class Response {
/**
* Set the http status code
*
* @param int $code
* @return self $this
*/
public function httpCode($code) {
http_response_code($code);
return $this;
}
/**
* Redirect the response
*
* @param string $url
*/
public function redirect($url) {
header('location: ' . $url);
}
}