-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
…ata configuration data
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Bag; | ||
|
||
class ScalarDataBag extends DataBag implements ScalarDataBagInterface | ||
{ | ||
public function __construct(array $container = []) | ||
{ | ||
$this->validateValues($container); | ||
|
||
parent::__construct($container); | ||
} | ||
|
||
public function offsetSet(mixed $offset, mixed $value): void | ||
{ | ||
if (!is_scalar($value)) { | ||
throw new \InvalidArgumentException('The value must be a scalar.'); | ||
} | ||
|
||
parent::offsetSet($offset, $value); | ||
} | ||
|
||
private function validateValues(array $values): void | ||
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.1 / Symfony ^5.4)
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.1 / Symfony ^6.4)
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.2 / Symfony ^5.4)
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.2 / Symfony ^6.4)
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.3 / Symfony ^5.4)
Check failure on line 25 in src/TwigHooks/src/Bag/ScalarDataBag.php GitHub Actions / Continuous Integration (PHP 8.3 / Symfony ^6.4)
|
||
{ | ||
foreach ($values as $value) { | ||
if (is_array($value)) { | ||
$this->validateValues($value); | ||
continue; | ||
} | ||
|
||
if (!is_scalar($value)) { | ||
throw new \InvalidArgumentException('The value must be a scalar.'); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Bag; | ||
|
||
/** | ||
* @extends \ArrayAccess<string, scalar> | ||
*/ | ||
interface ScalarDataBagInterface extends \ArrayAccess | ||
{ | ||
} |