generated from spatie/package-skeleton-laravel
-
-
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.
Merge pull request #11 from VPremiss/dev
v1.0.12
- Loading branch information
Showing
18 changed files
with
235 additions
and
170 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
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 |
---|---|---|
@@ -1,29 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Throw if Nonce attributes are long limit (bool) | ||
| Nonce key attributes character length (int) | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Decide whether the package would throw and remind you if it found the | ||
| nonce attributes (title and unique-key) used for caching are a bit | ||
| long or not. | ||
| Determine the length of Nonce attributes' strings. | ||
| | ||
*/ | ||
|
||
'throw_if_long' => false, | ||
'key_attributes_length' => 40, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Nonce attributes character length (int) | ||
| Throw if Nonce attributes are long (bool) | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Determine the length of Nonce attributes' strings. | ||
| Decide whether the package should throw if it found the nonce key attributes | ||
| (title and unique-key) used for caching are a longer than the set length | ||
| in the previous configuration. | ||
| | ||
*/ | ||
|
||
'attributes_length' => 40, | ||
'throw_if_key_attributes_are_long' => false, | ||
|
||
]; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VPremiss\LivewireNonceable\Interfaces; | ||
|
||
interface Noncing | ||
|
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VPremiss\LivewireNonceable\Support\Concerns; | ||
|
||
use VPremiss\Crafty\Facades\CraftyPackage; | ||
use VPremiss\LivewireNonceable\LivewireNonceableServiceProvider; | ||
use VPremiss\LivewireNonceable\Support\Exceptions\NoncenseException; | ||
|
||
trait HasNoncingValidations | ||
{ | ||
private function validateTheNoncingInterface(): void | ||
{ | ||
if ( | ||
!method_exists(self::class, 'getNonces') | ||
|| !method_exists(self::class, 'getNonceUniqueId') | ||
) { | ||
throw new NoncenseException( | ||
'Noncing interface methods were not found! Please implement it on ' . self::class . ' Livewire component.' | ||
); | ||
} | ||
} | ||
|
||
private function validateTheNonceUniqueId(): void | ||
{ | ||
if (empty($uniqueId = $this->getNonceUniqueId())) { | ||
throw new NoncenseException( | ||
'The Noncing unique ID was found in ' . self::class . ' Livewire component to be an empty string!' | ||
); | ||
} | ||
|
||
if ( | ||
CraftyPackage::validatedConfig( | ||
'livewire-nonceable.throw_if_key_attributes_are_long', | ||
LivewireNonceableServiceProvider::class, | ||
) | ||
) { | ||
$length = CraftyPackage::validatedConfig( | ||
'livewire-nonceable.key_attributes_length', | ||
LivewireNonceableServiceProvider::class, | ||
); | ||
|
||
if (strlen($uniqueId) > $length) { | ||
throw new NoncenseException( | ||
'The Noncing unique ID was found in ' . self::class . " Livewire component to surpass the limit defined in configuration: ({$length})." | ||
); | ||
} | ||
} | ||
} | ||
|
||
private function validateTheNonces(): void | ||
{ | ||
if (empty($nonces = $this->getNonces())) { | ||
throw new NoncenseException( | ||
'The Noncing nonces were found in ' . self::class . ' Livewire component to be an empty array!' | ||
); | ||
} | ||
|
||
foreach ($nonces as $key => $value) { | ||
if (!is_string($key) || empty($key)) { | ||
throw new NoncenseException( | ||
'A key in Noncing nonces was found in ' . self::class . ' Livewire component to NOT be a string or empty! It is meant to be cache key title to lasting cache time in seconds; strings to integers.' | ||
); | ||
} | ||
|
||
if ( | ||
CraftyPackage::validatedConfig( | ||
'livewire-nonceable.throw_if_key_attributes_are_long', | ||
LivewireNonceableServiceProvider::class, | ||
) | ||
) { | ||
$length = CraftyPackage::validatedConfig( | ||
'livewire-nonceable.key_attributes_length', | ||
LivewireNonceableServiceProvider::class, | ||
); | ||
|
||
if (strlen($key) > $length) { | ||
throw new NoncenseException( | ||
'A key in Noncing nonces was found in ' . self::class . " Livewire component to be a long string! Longer than the length defined in configuration: ($length)." | ||
); | ||
} | ||
} | ||
|
||
if (!is_int($value)) { | ||
throw new NoncenseException( | ||
'A value in Noncing nonces was found in ' . self::class . ' Livewire component to NOT be an integer! It is meant to be cache key title to lasting cache time in seconds; strings to integers.' | ||
); | ||
} | ||
|
||
if ($value <= 0) { | ||
throw new NoncenseException( | ||
'A value in Noncing nonces was found in ' . self::class . ' Livewire component to an integer less than zero! It is meant to be cache key title to lasting cache time in seconds; strings to integers. (MORE than zero, obviously!)' | ||
); | ||
} | ||
} | ||
} | ||
|
||
private function validateNonceTitle($title): void | ||
{ | ||
if (!array_key_exists($title, $this->getNonces())) { | ||
throw new NoncenseException( | ||
"The given nonce title '$title' doesn't exist in " . self::class . " Livewire component's getNonces() titles-to-seconds array." | ||
); | ||
} | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VPremiss\LivewireNonceable\Support\Concerns; | ||
|
||
use VPremiss\Crafty\Facades\CraftyPackage; | ||
use VPremiss\Crafty\Utilities\Configurated\Exceptions\ConfiguratedValidatedConfigurationException; | ||
|
||
trait HasValidatedConfiguration | ||
{ | ||
protected function validateKeyAttributesLengthConfig() | ||
{ | ||
if (!is_int(CraftyPackage::config('livewire-nonceable.key_attributes_length', $this))) { | ||
throw new ConfiguratedValidatedConfigurationException( | ||
'The configuration integer for "key attributes length" is not found!' | ||
); | ||
} | ||
} | ||
|
||
protected function validateThrowIfLongConfig() | ||
{ | ||
if (!is_bool(CraftyPackage::config('livewire-nonceable.throw_if_key_attributes_are_long', $this))) { | ||
throw new ConfiguratedValidatedConfigurationException( | ||
'The configuration boolean for "throwing if key attributes are long" is not found!' | ||
); | ||
} | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VPremiss\LivewireNonceable\Support\Exceptions; | ||
|
||
use Exception; | ||
|
||
class NoncenseException extends Exception | ||
{ | ||
} |
Oops, something went wrong.