-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\GridBundle\Parser; | ||
|
||
final class OptionsParser implements OptionsParserInterface | ||
{ | ||
public function parseOptions(array $parameters): array | ||
{ | ||
return array_map( | ||
/** | ||
* @param mixed $parameter | ||
* | ||
* @return mixed | ||
*/ | ||
function ($parameter) { | ||
if (is_array($parameter)) { | ||
return $this->parseOptions($parameter); | ||
} | ||
|
||
return $this->parseOption($parameter); | ||
}, | ||
$parameters, | ||
); | ||
} | ||
|
||
/** | ||
* @param mixed $parameter | ||
* | ||
* @return mixed | ||
*/ | ||
private function parseOption($parameter) | ||
{ | ||
if (!is_string($parameter)) { | ||
return $parameter; | ||
} | ||
|
||
if (0 === strpos($parameter, 'callback:')) { | ||
return $this->parseOptionCallback(substr($parameter, 9)); | ||
} | ||
|
||
return $parameter; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function parseOptionCallback(string $callback): \Closure | ||
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^6.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.2, Symfony ^5.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.2, Symfony ^6.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.3, Symfony ^5.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.3, Symfony ^6.4
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4, PostgresSQL 13.3
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4, PostgresSQL 14.0
Check failure on line 58 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.3, Symfony ^7.0
|
||
{ | ||
return $callback(...); | ||
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^6.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.2, Symfony ^5.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.2, Symfony ^6.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.3, Symfony ^5.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.3, Symfony ^6.4
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4, PostgresSQL 13.3
Check failure on line 60 in src/Bundle/Parser/OptionsParser.php GitHub Actions / PHP 8.1, Symfony ^5.4, PostgresSQL 14.0
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\GridBundle\Parser; | ||
|
||
interface OptionsParserInterface | ||
{ | ||
public function parseOptions(array $parameters): array; | ||
} |