-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make callback field compatible with yaml config
- Loading branch information
1 parent
7f9689b
commit bf89482
Showing
14 changed files
with
213 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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; | ||
} | ||
|
||
private function parseOptionCallback(string $callback): \Closure | ||
{ | ||
if (!is_callable($callback)) { | ||
throw new \RuntimeException(\sprintf('%s is not a callable.', $callback)); | ||
} | ||
|
||
return $callback(...); | ||
} | ||
} |
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,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; | ||
} |
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
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
Oops, something went wrong.