Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/Validators for image sizes were added, unit-tests refactoring,
overall refactoring, documentation was updated
- Loading branch information
1 parent
e1ef6df
commit 0e97a6e
Showing
9 changed files
with
308 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Mezon\Security\Validators; | ||
|
||
/** | ||
* Class AbstractValidator | ||
* | ||
* @package Mezon | ||
* @subpackage Security | ||
* @author Dodonov A.A. | ||
* @version v.1.0 (2020/05/13) | ||
* @copyright Copyright (c) 2020, aeon.org | ||
*/ | ||
|
||
/** | ||
* Abstract class for validators | ||
* | ||
* @author gdever | ||
*/ | ||
abstract class AbstractValidator implements ValidatorInterface | ||
{ | ||
|
||
/** | ||
* Method validates that $_FILES[$field] exists. | ||
* If it does not then exception will be thrown | ||
* | ||
* @param string $field | ||
* field name | ||
*/ | ||
public function validateFilesFieldExists(string $field): void | ||
{ | ||
if (isset($_FILES[$field]) === false) { | ||
throw (new \Exception('The index "' . $field . '" was not found in the $_FILES array', - 1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
namespace Mezon\Security\Validators\File; | ||
|
||
/** | ||
* Class ImageMaximumWidthHeight | ||
* | ||
* @package Mezon | ||
* @subpackage Security | ||
* @author Dodonov A.A. | ||
* @version v.1.0 (2020/05/13) | ||
* @copyright Copyright (c) 2020, aeon.org | ||
*/ | ||
class ImageMaximumWidthHeight extends \Mezon\Security\Validators\AbstractValidator | ||
{ | ||
|
||
/** | ||
* Index in the $_FILES array | ||
* | ||
* @var string | ||
*/ | ||
private $file = ''; | ||
|
||
/** | ||
* Maximum width of the image | ||
* | ||
* @var integer | ||
*/ | ||
private $maximumWidth = 0; | ||
|
||
/** | ||
* Maximum height of the image | ||
* | ||
* @var integer | ||
*/ | ||
private $maximumHeight = 0; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param int $width | ||
* width constraint for the file | ||
* @param int $height | ||
* height constraint for the file | ||
* @codeCoverageIgnore | ||
*/ | ||
public function __construct(int $width, int $height) | ||
{ | ||
$this->maximumWidth = $width; | ||
|
||
$this->maximumHeight = $height; | ||
} | ||
|
||
/** | ||
* | ||
* {@inheritdoc} | ||
* @see \Mezon\Security\Validators\ValidatorInterface::valid() | ||
*/ | ||
public function valid(): bool | ||
{ | ||
$this->validateFilesFieldExists($this->file); | ||
|
||
list($width, $height) = getimagesize($_FILES[$this->file]['tmp_name']); | ||
|
||
return $width <= $this->maximumWidth && $height <= $this->maximumHeight; | ||
} | ||
|
||
/** | ||
* | ||
* {@inheritdoc} | ||
* @see \Mezon\Security\Validators\ValidatorInterface::setValidatingData() | ||
*/ | ||
public function setValidatingData($data): void | ||
{ | ||
$this->file = $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
namespace Mezon\Security\Validators\File; | ||
|
||
/** | ||
* Class ImageMinimumWidthHeight | ||
* | ||
* @package Mezon | ||
* @subpackage Security | ||
* @author Dodonov A.A. | ||
* @version v.1.0 (2020/05/13) | ||
* @copyright Copyright (c) 2020, aeon.org | ||
*/ | ||
class ImageMinimumWidthHeight extends \Mezon\Security\Validators\AbstractValidator | ||
{ | ||
|
||
/** | ||
* Index in the $_FILES array | ||
* | ||
* @var string | ||
*/ | ||
private $file = ''; | ||
|
||
/** | ||
* Minumum width of the image | ||
* | ||
* @var integer | ||
*/ | ||
private $minimumWidth = 0; | ||
|
||
/** | ||
* Minumum height of the image | ||
* | ||
* @var integer | ||
*/ | ||
private $minimumHeight = 0; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param int $width | ||
* width constraint for the file | ||
* @param int $height | ||
* height constraint for the file | ||
* @codeCoverageIgnore | ||
*/ | ||
public function __construct(int $width, int $height) | ||
{ | ||
$this->minimumWidth = $width; | ||
|
||
$this->minimumHeight = $height; | ||
} | ||
|
||
/** | ||
* | ||
* {@inheritdoc} | ||
* @see \Mezon\Security\Validators\ValidatorInterface::valid() | ||
*/ | ||
public function valid(): bool | ||
{ | ||
$this->validateFilesFieldExists($this->file); | ||
|
||
list($width, $height) = getimagesize($_FILES[$this->file]['tmp_name']); | ||
|
||
return $width >= $this->minimumWidth && $height >= $this->minimumHeight; | ||
} | ||
|
||
/** | ||
* | ||
* {@inheritdoc} | ||
* @see \Mezon\Security\Validators\ValidatorInterface::setValidatingData() | ||
*/ | ||
public function setValidatingData($data): void | ||
{ | ||
$this->file = $data; | ||
} | ||
} |
Oops, something went wrong.