Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed May 15, 2017
1 parent 45eaaea commit c4d3776
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Classes/Condition/ConditionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Romm\Formz\Condition;

use InvalidArgumentException;
use Romm\Formz\Condition\Items\ConditionItemInterface;
use Romm\Formz\Condition\Items\FieldHasErrorCondition;
use Romm\Formz\Condition\Items\FieldHasValueCondition;
Expand All @@ -22,6 +23,7 @@
use Romm\Formz\Exceptions\ClassNotFoundException;
use Romm\Formz\Exceptions\EntryNotFoundException;
use Romm\Formz\Exceptions\InvalidArgumentTypeException;
use Romm\Formz\Exceptions\MissingArgumentException;
use Romm\Formz\Service\Traits\SelfInstantiateTrait;
use TYPO3\CMS\Core\SingletonInterface;

Expand Down Expand Up @@ -128,19 +130,23 @@ public function getConditions()
* @param array $arguments
* @return ConditionItemInterface
* @throws EntryNotFoundException
* @throws MissingArgumentException
*/
public function instantiateCondition($identifier, array $arguments = [])
{
if (false === $this->hasCondition($identifier)) {
throw EntryNotFoundException::instantiateConditionNotFound($identifier, $this->conditions);
}

// @todo handle \InvalidArgumentException
/** @var ConditionItemInterface $condition */
$condition = call_user_func_array(
[Core::class, 'instantiate'],
array_merge([$this->conditions[$identifier]], $arguments)
);
try {
/** @var ConditionItemInterface $condition */
$condition = call_user_func_array(
[Core::class, 'instantiate'],
array_merge([$this->conditions[$identifier]], $arguments)
);
} catch (InvalidArgumentException $exception) {
throw MissingArgumentException::conditionConstructorArgumentMissing($identifier, $this->conditions[$identifier], $arguments);
}

return $condition;
}
Expand Down
21 changes: 21 additions & 0 deletions Classes/Exceptions/MissingArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class MissingArgumentException extends FormzException
{
const ARGUMENT_MISSING = 'The argument "%s" was not found in the request.';

const CONDITION_CONSTRUCTOR_ARGUMENT_MISSING = 'Error while instantiating the condition "%s" of type "%s": a constructor argument is missing. Given arguments were: "%s".';

/**
* @code 1490179179
*
Expand Down Expand Up @@ -48,4 +50,23 @@ final public static function ajaxControllerClassNameArgumentNotSet()

return $exception;
}

/**
* @code 1494850270
*
* @param string $conditionName
* @param string $conditionClassName
* @param array $arguments
* @return self
*/
final public static function conditionConstructorArgumentMissing($conditionName, $conditionClassName, array $arguments)
{
/** @var self $exception */
$exception = self::getNewExceptionInstance(
self::CONDITION_CONSTRUCTOR_ARGUMENT_MISSING,
[$conditionName, $conditionClassName, implode('", "', array_keys($arguments))]
);

return $exception;
}
}

0 comments on commit c4d3776

Please sign in to comment.