Compare commits

...

9 Commits

Author SHA1 Message Date
Simon Sessingø e77d78e2f2 Merge pull request #399 from skipperbent/v4-development
Bugfixes and optimizations
2018-04-01 03:02:49 +02:00
Simon Sessingø 1dc88d23e1 Bugfixes and optimizations
- Fixed `hasParam` not working returning expected value in `Url` class.
- Chained the remaining methods in the `Url` class.
- Simplified `removeParam` method in `Url` class.
- Added new `removeParams` method to `Url` class for removal of multiple params.
2018-04-01 03:02:21 +02:00
Simon Sessingø bd033d9e13 Merge pull request #398 from skipperbent/v4-development
Version 4.0.0.11
2018-03-30 06:48:15 +02:00
Simon Sessingø 53f0b7d8e2 - Fixed getName method in LoadableRoute class can contain nullable value. 2018-03-30 06:47:27 +02:00
Simon Sessingø 5df0c12864 Updated helpers 2018-03-30 05:54:12 +02:00
Simon Sessingø 5bae3ff773 Merge pull request #397 from skipperbent/v4-development
Version 4.0.0.10
2018-03-30 05:38:27 +02:00
Simon Sessingø 833961ddc3 Fixed getError in InputFile returning string instead of int. 2018-03-30 05:37:04 +02:00
Simon Sessingø 36388f0f79 Merge pull request #396 from skipperbent/v4-development
Version 4.0.0.9
2018-03-30 05:23:54 +02:00
Simon Sessingø ce63e247b1 Bugfixes
- Fixed `Url` not outputting correct class when used in json_encode.
- Fixed `IInputItem` being too strict about strings which may be nullable.
2018-03-30 05:22:41 +02:00
10 changed files with 527 additions and 555 deletions
+471 -511
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -332,7 +332,7 @@ function request(): Request
* @param string|null $index Parameter index name
* @param string|null $defaultValue Default return value
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|\Pecee\Http\Input\IInputItem|string
* @return \Pecee\Http\Input\InputHandler|string
*/
function input($index = null, $defaultValue = null, ...$methods)
{
+1 -1
View File
@@ -49,7 +49,7 @@ function request(): Request
* @param string|null $index Parameter index name
* @param string|null $defaultValue Default return value
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|\Pecee\Http\Input\IInputItem|string
* @return \Pecee\Http\Input\InputHandler|string
*/
function input($index = null, $defaultValue = null, ...$methods)
{
+3 -3
View File
@@ -9,14 +9,14 @@ interface IInputItem
public function setIndex(string $index): self;
public function getName(): string;
public function getName(): ?string;
public function setName(string $name): self;
public function getValue(): string;
public function getValue(): ?string;
public function setValue(string $value): self;
public function __toString();
public function __toString(): string;
}
+8 -8
View File
@@ -49,7 +49,7 @@ class InputFile implements IInputItem
return (new static($values['index']))
->setSize((int)$values['size'])
->setError($values['error'])
->setError((int)$values['error'])
->setType($values['type'])
->setTmpName($values['tmp_name'])
->setFilename($values['name']);
@@ -140,7 +140,7 @@ class InputFile implements IInputItem
*
* @return string
*/
public function getName(): string
public function getName(): ?string
{
return $this->name;
}
@@ -177,7 +177,7 @@ class InputFile implements IInputItem
*
* @return string mixed
*/
public function getFilename(): string
public function getFilename(): ?string
{
return $this->filename;
}
@@ -216,11 +216,11 @@ class InputFile implements IInputItem
/**
* Get upload-error code.
*
* @return string
* @return int
*/
public function getError(): string
public function getError(): int
{
return $this->errors;
return (int)$this->errors;
}
/**
@@ -256,12 +256,12 @@ class InputFile implements IInputItem
return $this;
}
public function __toString()
public function __toString(): string
{
return $this->getTmpName();
}
public function getValue(): string
public function getValue(): ?string
{
return $this->getFilename();
}
+3 -3
View File
@@ -35,7 +35,7 @@ class InputItem implements IInputItem
/**
* @return string
*/
public function getName(): string
public function getName(): ?string
{
return $this->name;
}
@@ -55,7 +55,7 @@ class InputItem implements IInputItem
/**
* @return string
*/
public function getValue(): string
public function getValue(): ?string
{
return $this->value;
}
@@ -72,7 +72,7 @@ class InputItem implements IInputItem
return $this;
}
public function __toString()
public function __toString(): string
{
return (string)$this->value;
}
+37 -25
View File
@@ -4,7 +4,7 @@ namespace Pecee\Http;
use Pecee\Http\Exceptions\MalformedUrlException;
class Url
class Url implements \JsonSerializable
{
private $originalUrl;
@@ -314,25 +314,36 @@ class Url
*/
public function hasParam(string $name): bool
{
return \in_array($name, $this->getParams(), true);
return array_key_exists($name, $this->getParams());
}
/**
* Removes parameter from query-string
* Removes multiple parameters from the query-string
*
* @param array ...$names
* @return static
*/
public function removeParams(...$names): self
{
$params = array_diff_key($this->getParams(), array_flip($names));
$this->setParams($params);
return $this;
}
/**
* Removes parameter from the query-string
*
* @param string $name
* @return static
*/
public function removeParam(string $name): void
public function removeParam(string $name): self
{
if ($this->hasParam($name) === true) {
$params = $this->getParams();
$key = \array_search($name, $params, true);
$params = $this->getParams();
unset($params[$name]);
$this->setParams($params);
if ($key === true) {
unset($params[$key]);
$this->setParams($params);
}
}
return $this;
}
/**
@@ -345,18 +356,7 @@ class Url
*/
public function getParam(string $name, ?string $defaultValue = null): ?string
{
$output = null;
if ($this->hasParam($name) === true) {
$params = $this->getParams();
$key = \array_search($name, $params, true);
if ($key === true) {
$output = $params[$key];
}
}
return $output ?? $defaultValue;
return isset($this->getParams()[$name]) ?? $defaultValue;
}
/**
@@ -441,7 +441,19 @@ class Url
return $scheme . $user . $pass . $host . $port . $this->getRelativeUrl();
}
public function __toString()
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize(): string
{
return $this->getRelativeUrl();
}
public function __toString(): string
{
return $this->getRelativeUrl();
}
@@ -154,7 +154,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*
* @return string
*/
public function getName(): string
public function getName(): ?string
{
return $this->name;
}
+1 -1
View File
@@ -192,7 +192,7 @@ abstract class Route implements IRoute
return $this->callback;
}
return 'function_' . md5($this->callback);
return 'function:' . md5($this->callback);
}
/**
+1 -1
View File
@@ -447,7 +447,7 @@ class SimpleRouter
* @param array|null $getParams
* @return Url
*/
public static function getUrl(?string $name = null, $parameters = null, $getParams = null): Url
public static function getUrl(?string $name = null, $parameters = null, ?array $getParams = null): Url
{
try {
return static::router()->getUrl($name, $parameters, $getParams);