mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
Minor optimisations.
This commit is contained in:
@@ -15,7 +15,7 @@ class CsrfToken
|
|||||||
*/
|
*/
|
||||||
public static function generateToken()
|
public static function generateToken()
|
||||||
{
|
{
|
||||||
if (function_exists('random_bytes')) {
|
if (function_exists('random_bytes') === true) {
|
||||||
return bin2hex(random_bytes(32));
|
return bin2hex(random_bytes(32));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ class CsrfToken
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set csrf token cookie
|
* Set csrf token cookie
|
||||||
|
* Overwrite this method to save the token to another storage like session etc.
|
||||||
*
|
*
|
||||||
* @param $token
|
* @param $token
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Pecee\Http;
|
namespace Pecee\Http;
|
||||||
|
|
||||||
use Pecee\Http\Input\Input;
|
use Pecee\Http\Input\Input;
|
||||||
@@ -42,13 +43,7 @@ class Request
|
|||||||
{
|
{
|
||||||
$this->headers = [];
|
$this->headers = [];
|
||||||
|
|
||||||
$max = count($_SERVER) - 1;
|
foreach ($_SERVER as $key => $value) {
|
||||||
$keys = array_keys($_SERVER);
|
|
||||||
|
|
||||||
for ($i = $max; $i >= 0; $i--) {
|
|
||||||
$key = $keys[$i];
|
|
||||||
$value = $_SERVER[$key];
|
|
||||||
|
|
||||||
$this->headers[strtolower($key)] = $value;
|
$this->headers[strtolower($key)] = $value;
|
||||||
$this->headers[strtolower(str_replace('_', '-', $key))] = $value;
|
$this->headers[strtolower(str_replace('_', '-', $key))] = $value;
|
||||||
}
|
}
|
||||||
@@ -167,24 +162,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getHeader($name, $defaultValue = null)
|
public function getHeader($name, $defaultValue = null)
|
||||||
{
|
{
|
||||||
if (array_key_exists(strtolower($name), $this->headers) === true) {
|
return isset($this->headers[strtolower($name)]) ? $this->headers[strtolower($name)] : $defaultValue;
|
||||||
return $this->headers[strtolower($name)];
|
|
||||||
}
|
|
||||||
|
|
||||||
$max = count($_SERVER) - 1;
|
|
||||||
$keys = array_keys($_SERVER);
|
|
||||||
|
|
||||||
for ($i = $max; $i >= 0; $i--) {
|
|
||||||
|
|
||||||
$key = $keys[$i];
|
|
||||||
$name = $_SERVER[$key];
|
|
||||||
|
|
||||||
if ($key === $name) {
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user