mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 13:24:41 +03:00
Throw an exception if a HBS helper receives wrong arguments set
This commit is contained in:
parent
61ee2d0af6
commit
ff72960382
@ -100,8 +100,10 @@ class AssetHelper implements HelperInterface, AssetUrlGeneratorAwareInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"asset" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$relative_path = $context->get($parsed_args[0]);
|
||||
|
||||
|
@ -42,8 +42,10 @@ class BlockHelper extends AbstractBlockHelper implements HelperInterface
|
||||
{
|
||||
// Get block name
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"block" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$block_name = $context->get(array_shift($parsed_args));
|
||||
|
||||
|
@ -39,8 +39,10 @@ class CutStringHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args) || count($parsed_args) < 2) {
|
||||
return '';
|
||||
if (count($parsed_args) != 2) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"cutString" helper expects exactly two arguments.'
|
||||
);
|
||||
}
|
||||
|
||||
$string = $context->get($parsed_args[0]);
|
||||
|
@ -48,8 +48,10 @@ class ExtendsHelper implements HelperInterface
|
||||
{
|
||||
// Get name of the parent template
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"extends" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$parent_template = $context->get(array_shift($parsed_args));
|
||||
|
||||
|
@ -39,8 +39,10 @@ class FormatDateDiffHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"formatDateDiff" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$seconds = intval($context->get($parsed_args[0]));
|
||||
|
@ -39,8 +39,10 @@ class FormatDateHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"formatDate" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$timestamp = intval($context->get($parsed_args[0]));
|
||||
|
@ -47,8 +47,10 @@ class GeneratePaginationHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args) || count($parsed_args) < 1) {
|
||||
return '';
|
||||
if (count($parsed_args) < 1 || count($parsed_args) > 2) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"generatePagination" helper expects one or two arguments.'
|
||||
);
|
||||
}
|
||||
|
||||
$pagination_info = $context->get($parsed_args[0]);
|
||||
|
@ -45,8 +45,10 @@ class IfAnyHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) == 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"ifAny" helper expects at least one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$condition = false;
|
||||
|
@ -43,8 +43,10 @@ class IfEqualHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args) || count($parsed_args) < 2) {
|
||||
return '';
|
||||
if (count($parsed_args) != 2) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"ifEqual" helper expects exactly two arguments.'
|
||||
);
|
||||
}
|
||||
|
||||
$condition = ($context->get($parsed_args[0]) == $context->get($parsed_args[1]));
|
||||
|
@ -43,8 +43,10 @@ class IfEvenHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"ifEven" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$condition = ($context->get($parsed_args[0]) % 2 == 0);
|
||||
|
@ -44,8 +44,10 @@ class IfOddHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"ifOdd" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$condition = ($context->get($parsed_args[0]) % 2 == 1);
|
||||
|
@ -32,7 +32,7 @@ use Handlebars\Template;
|
||||
* The block was overridden
|
||||
* {{else}}
|
||||
* The block was not overridden
|
||||
* {{/ifOverriden}}
|
||||
* {{/ifOverridden}}
|
||||
* </code>
|
||||
*/
|
||||
class IfOverriddenHelper extends AbstractBlockHelper implements HelperInterface
|
||||
@ -44,8 +44,10 @@ class IfOverriddenHelper extends AbstractBlockHelper implements HelperInterface
|
||||
{
|
||||
// Get block name
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"ifOverridden" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$block_name = $context->get(array_shift($parsed_args));
|
||||
|
||||
|
@ -45,8 +45,10 @@ class L10nHelper implements HelperInterface
|
||||
{
|
||||
// Check if there is at least one argument
|
||||
$parsed_arguments = $template->parseArguments($args);
|
||||
if (empty($parsed_arguments)) {
|
||||
return '';
|
||||
if (count($parsed_arguments) == 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"l10n" helper expects at least one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$text = $context->get(array_shift($parsed_arguments));
|
||||
|
@ -48,8 +48,10 @@ class OverrideHelper extends AbstractBlockHelper implements HelperInterface
|
||||
{
|
||||
// Get block name
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"override" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$block_name = $context->get(array_shift($parsed_args));
|
||||
|
||||
|
@ -39,8 +39,10 @@ class RepeatHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"repeat" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
|
||||
$times = intval($context->get($parsed_args[0]));
|
||||
|
@ -39,8 +39,10 @@ class ReplaceHelper implements HelperInterface
|
||||
public function execute(Template $template, Context $context, $args, $source)
|
||||
{
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args) || count($parsed_args) < 2) {
|
||||
return '';
|
||||
if (count($parsed_args) != 2) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"replace" helper expects exactly two arguments.'
|
||||
);
|
||||
}
|
||||
|
||||
$search = $context->get($parsed_args[0]);
|
||||
|
@ -32,7 +32,7 @@ use Handlebars\Template;
|
||||
* The block was not overridden
|
||||
* {{else}}
|
||||
* The block was overridden
|
||||
* {{/unlessOverriden}}
|
||||
* {{/unlessOverridden}}
|
||||
* </code>
|
||||
*/
|
||||
class UnlessOverriddenHelper extends AbstractBlockHelper implements HelperInterface
|
||||
@ -44,8 +44,10 @@ class UnlessOverriddenHelper extends AbstractBlockHelper implements HelperInterf
|
||||
{
|
||||
// Get block name
|
||||
$parsed_args = $template->parseArguments($args);
|
||||
if (empty($parsed_args)) {
|
||||
return '';
|
||||
if (count($parsed_args) != 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
'"unlessOverridden" helper expects exactly one argument.'
|
||||
);
|
||||
}
|
||||
$block_name = $context->get(array_shift($parsed_args));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user