-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b82034
commit a52f2e1
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
upload/system/library/PagSeguro/src/Constants/AbstractEnum.php
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,55 @@ | ||
<?php | ||
|
||
namespace ValdeirPsr\PagSeguro\Constants; | ||
|
||
abstract class AbstractEnum | ||
{ | ||
private static $enums = []; | ||
|
||
private function __construct() | ||
{ | ||
/** Preventing instance */ | ||
} | ||
|
||
/** | ||
* Captura a lista de constantes | ||
* | ||
* @return array | ||
*/ | ||
private static function getEnums(): array | ||
{ | ||
if (self::$enums === null) { | ||
self::$enums = []; | ||
} | ||
|
||
$calledClass = get_called_class(); | ||
|
||
if (!array_key_exists($calledClass, self::$enums)) { | ||
$reflect = new \ReflectionClass($calledClass); | ||
self::$enums[$calledClass] = $reflect->getConstants(); | ||
} | ||
|
||
return self::$enums[$calledClass]; | ||
} | ||
|
||
/** | ||
* Verifica se determinada chave existe | ||
* | ||
* @return bool | ||
*/ | ||
public static function has($name): bool | ||
{ | ||
return array_key_exists($name, self::getEnums()); | ||
} | ||
|
||
/** | ||
* Verifica se determinado valor existe | ||
* | ||
* @return bool | ||
*/ | ||
public static function isValidValue($value): bool | ||
{ | ||
$values = array_values(self::getEnums()); | ||
return in_array($value, $values); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
upload/system/library/PagSeguro/src/Constants/Shipping/Type.php
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,12 @@ | ||
<?php | ||
|
||
namespace ValdeirPsr\PagSeguro\Constants\Shipping; | ||
|
||
use ValdeirPsr\PagSeguro\Constants\AbstractEnum; | ||
|
||
class Type extends AbstractEnum | ||
{ | ||
const PAC = 1; | ||
const SEDEX = 2; | ||
const UNKNOWN = 3; | ||
} |