Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/5436' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 57 changed files with 848 additions and 363 deletions.
16 changes: 2 additions & 14 deletions src/BaseName.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,17 @@ class BaseName extends AbstractFilter
* Returns basename($value).
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string|mixed
*/
public function filter($value)
{
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}
$value = (string) $value;

return basename((string) $value);
return basename($value);
}
}
2 changes: 1 addition & 1 deletion src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getCallback()
/**
* Sets parameters for the callback
*
* @param mixed $params
* @param array $params
* @return self
*/
public function setCallbackParams($params)
Expand Down
4 changes: 4 additions & 0 deletions src/Compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public function __call($method, $options)
*/
public function filter($value)
{
if (!is_string($value)) {
return $value;
}

return $this->getAdapter()->compress($value);
}
}
16 changes: 14 additions & 2 deletions src/DateTimeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public function __construct($options = null)
public function setFormat($format)
{
$this->format = $format;

return $this;
}

/**
* Filter a datetime string by normalizing it to the filters specified format
*
* @param string $value
* @param DateTime|string|integer $value
* @throws Exception\InvalidArgumentException
* @return string
*/
Expand All @@ -60,6 +61,10 @@ public function filter($value)
throw new Exception\InvalidArgumentException('Invalid date string provided', $e->getCode(), $e);
}

if ($result === false) {
return $value;
}

return $result;
}

Expand All @@ -73,7 +78,14 @@ protected function normalizeDateTime($value)
{
if ($value === '' || $value === null) {
return $value;
} elseif (is_int($value)) {
}

if (!is_string($value) && !is_int($value) && !$value instanceof DateTime) {
return $value;
}

if (is_int($value)) {
//timestamp
$value = new DateTime('@' . $value);
} elseif (!$value instanceof DateTime) {
$value = new DateTime($value);
Expand Down
6 changes: 5 additions & 1 deletion src/Decompress.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Decompress extends Compress
*/
public function __invoke($value)
{
return $this->getAdapter()->decompress($value);
return $this->filter($value);
}

/**
Expand All @@ -37,6 +37,10 @@ public function __invoke($value)
*/
public function filter($value)
{
if (!is_string($value) && $value !== null) {
return $value;
}

return $this->getAdapter()->decompress($value);
}
}
4 changes: 4 additions & 0 deletions src/Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Decrypt extends Encrypt
*/
public function filter($value)
{
if (!is_string($value)) {
return $value;
}

return $this->adapter->decrypt($value);
}
}
16 changes: 2 additions & 14 deletions src/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,16 @@ class Digits extends AbstractFilter
* Returns the string $value, removing all but digit characters
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string|mixed
*/
public function filter($value)
{
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}
$value = (string) $value;

if (!StringUtils::hasPcreUnicodeSupport()) {
// POSIX named classes are not supported, use alternative 0-9 match
Expand All @@ -53,6 +41,6 @@ public function filter($value)
$pattern = '/[\p{^N}]/';
}

return preg_replace($pattern, '', (string) $value);
return preg_replace($pattern, '', $value);
}
}
7 changes: 6 additions & 1 deletion src/Dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Dir extends AbstractFilter
*/
public function filter($value)
{
return dirname((string) $value);
if (!is_scalar($value)) {
return $value;
}
$value = (string) $value;

return dirname($value);
}
}
7 changes: 7 additions & 0 deletions src/Encrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Encrypt extends AbstractFilter
{
/**
* Encryption adapter
*
* @param Encrypt\EncryptionAlgorithmInterface
*/
protected $adapter;

Expand All @@ -38,6 +40,7 @@ public function __construct($options = null)

/**
* Returns the name of the set adapter
* @todo inconsitent: get adapter should return the adapter and not the name
*
* @return string
*/
Expand Down Expand Up @@ -117,6 +120,10 @@ public function __call($method, $options)
*/
public function filter($value)
{
if (!is_string($value)) {
return $value;
}

return $this->adapter->encrypt($value);
}
}
14 changes: 12 additions & 2 deletions src/File/Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,23 @@ public function setFilename($filename = null)
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$value = $value['tmp_name'];
}


if (!file_exists($value)) {
throw new Exception\InvalidArgumentException("File '$value' not found");
}
Expand Down
13 changes: 11 additions & 2 deletions src/File/Encrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@ public function setFilename($filename = null)
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$value = $value['tmp_name'];
}
Expand Down
13 changes: 11 additions & 2 deletions src/File/LowerCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ class LowerCase extends StringToLower
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$value = $value['tmp_name'];
}
Expand Down
13 changes: 11 additions & 2 deletions src/File/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,18 @@ public function getNewName($value, $source = false)
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$value = $value['tmp_name'];
}
Expand Down
15 changes: 12 additions & 3 deletions src/File/RenameUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,21 @@ public function getRandomize()
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$sourceFile = $value['tmp_name'];
} else {
} else{
$uploadData = array(
'tmp_name' => $value,
'name' => $value,
Expand Down
13 changes: 11 additions & 2 deletions src/File/UpperCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ class UpperCase extends StringToUpper
*/
public function filter($value)
{
if (!is_scalar($value) && !is_array($value)) {
return $value;
}

// An uploaded file? Retrieve the 'tmp_name'
$isFileUpload = (is_array($value) && isset($value['tmp_name']));
if ($isFileUpload) {
$isFileUpload = false;
if (is_array($value)) {
if (!isset($value['tmp_name'])) {
return $value;
}

$isFileUpload = true;
$uploadData = $value;
$value = $value['tmp_name'];
}
Expand Down
20 changes: 4 additions & 16 deletions src/HtmlEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,37 +174,25 @@ public function setDoubleQuote($doubleQuote)
* equivalents where they exist
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string|mixed
* @throws Exception\DomainException on encoding mismatches
*/
public function filter($value)
{
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}
$value = (string) $value;

$filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
if (strlen((string) $value) && !strlen($filtered)) {
$filtered = htmlentities($value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
if (strlen($value) && !strlen($filtered)) {
if (!function_exists('iconv')) {
throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors');
}
$enc = $this->getEncoding();
$value = iconv('', $this->getEncoding() . '//IGNORE', (string) $value);
$value = iconv('', $this->getEncoding() . '//IGNORE', $value);
$filtered = htmlentities($value, $this->getQuoteStyle(), $enc, $this->getDoubleQuote());
if (!strlen($filtered)) {
throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors');
Expand Down
Loading

0 comments on commit 77f0d14

Please sign in to comment.