public function initializeArgs(array $nameValuePairs)
    {
        $faultActor = [];
        $faultDetails = [];

        if (null !== $eventName = $this->getDispatchEventName(TheliaEvents::LOOP_EXTENDS_INITIALIZE_ARGS)) {
            $event = new LoopExtendsInitializeArgsEvent($this, $nameValuePairs);
            $this->dispatcher->dispatch($eventName, $event);
            $nameValuePairs = $event->getLoopParameters();
        }

        $loopType = isset($nameValuePairs['type']) ? $nameValuePairs['type'] : "undefined";
        $loopName = isset($nameValuePairs['name']) ? $nameValuePairs['name'] : "undefined";

        $this->args->rewind();
        while (($argument = $this->args->current()) !== false) {
            $this->args->next();

            $value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;

            /* check if mandatory */
            if ($value === null && $argument->mandatory) {
                $faultActor[] = $argument->name;
                $faultDetails[] = $this->translator->trans(
                    '"%param" parameter is missing in loop type: %type, name: %name',
                    [
                        '%param' => $argument->name,
                        '%type' => $loopType,
                        '%name' => $loopName
                    ]
                );
            } elseif ($value === '') {
                if (!$argument->empty) {
                    /* check if empty */
                    $faultActor[] = $argument->name;
                    $faultDetails[] = $this->translator->trans(
                        '"%param" parameter cannot be empty in loop type: %type, name: %name',
                        [
                            '%param' => $argument->name,
                            '%type' => $loopType,
                            '%name' => $loopName
                        ]
                    );
                }
            } elseif ($value !== null && !$argument->type->isValid($value)) {
                /* check type */
                $faultActor[] = $argument->name;
                $faultDetails[] = $this->translator->trans(
                    'Invalid value "%value" for "%param" parameter in loop type: %type, name: %name',
                    [
                        '%value' => $value,
                        '%param' => $argument->name,
                        '%type' => $loopType,
                        '%name' => $loopName
                    ]
                );
            } else {
                /* set default value */
                /* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
                if ($value === null) {
                    $value = $argument->default;
                }

                $argument->setValue($value);
            }
        }

        if (! empty($faultActor)) {
            $complement = sprintf('[%s]', implode(', ', $faultDetails));

            throw new \InvalidArgumentException($complement);
        }
    }
public function initializeArgs(array $nameValuePairs)
    {
        $faultActor = [];
        $faultDetails = [];

        if (null !== $eventName = $this->getDispatchEventName(TheliaEvents::LOOP_EXTENDS_INITIALIZE_ARGS)) {
            $event = new LoopExtendsInitializeArgsEvent($this, $nameValuePairs);
            $this->dispatcher->dispatch($eventName, $event);
            $nameValuePairs = $event->getLoopParameters();
        }

        $loopType = isset($nameValuePairs['type']) ? $nameValuePairs['type'] : "undefined";
        $loopName = isset($nameValuePairs['name']) ? $nameValuePairs['name'] : "undefined";

        $this->args->rewind();
        while (($argument = $this->args->current()) !== false) {
            $this->args->next();

            $value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;

            /* check if mandatory */
            if ($value === null && $argument->mandatory) {
                $faultActor[] = $argument->name;
                $faultDetails[] = $this->translator->trans(
                    '"%param" parameter is missing in loop type: %type, name: %name',
                    [
                        '%param' => $argument->name,
                        '%type' => $loopType,
                        '%name' => $loopName
                    ]
                );
            } elseif ($value === '') {
                if (!$argument->empty) {
                    /* check if empty */
                    $faultActor[] = $argument->name;
                    $faultDetails[] = $this->translator->trans(
                        '"%param" parameter cannot be empty in loop type: %type, name: %name',
                        [
                            '%param' => $argument->name,
                            '%type' => $loopType,
                            '%name' => $loopName
                        ]
                    );
                }
            } elseif ($value !== null && !$argument->type->isValid($value)) {
                /* check type */
                $faultActor[] = $argument->name;
                $faultDetails[] = $this->translator->trans(
                    'Invalid value "%value" for "%param" parameter in loop type: %type, name: %name',
                    [
                        '%value' => $value,
                        '%param' => $argument->name,
                        '%type' => $loopType,
                        '%name' => $loopName
                    ]
                );
            } else {
                /* set default value */
                /* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
                if ($value === null) {
                    $value = $argument->default;
                }

                $argument->setValue($value);
            }
        }

        if (! empty($faultActor)) {
            $complement = sprintf('[%s]', implode(', ', $faultDetails));

            throw new \InvalidArgumentException($complement);
        }
    }
public function initializeArgs ( array $ nameValuePairs ) { $ faultActor = [ ] ; $ faultDetails = [ ] ; if ( null !== $ eventName = $ this -> getDispatchEventName ( TheliaEvents :: LOOP_EXTENDS_INITIALIZE_ARGS ) ) { $ event = new LoopExtendsInitializeArgsEvent ( $ this , $ nameValuePairs ) ; $ this -> dispatcher -> dispatch ( $ eventName , $ event ) ; $ nameValuePairs = $ event -> getLoopParameters ( ) ; } $ loopType = isset ( $ nameValuePairs [ 'type' ] ) ? $ nameValuePairs [ 'type' ] : "undefined" ; $ loopName = isset ( $ nameValuePairs [ 'name' ] ) ? $ nameValuePairs [ 'name' ] : "undefined" ; $ this -> args -> rewind ( ) ; while ( ( $ argument = $ this -> args -> current ( ) ) !== false ) { $ this -> args -> next ( ) ; $ value = isset ( $ nameValuePairs [ $ argument -> name ] ) ? $ nameValuePairs [ $ argument -> name ] : null ; /* check if mandatory */ if ( $ value === null && $ argument -> mandatory ) { $ faultActor [ ] = $ argument -> name ; $ faultDetails [ ] = $ this -> translator -> trans ( '"%param" parameter is missing in loop type: %type, name: %name' , [ '%param' => $ argument -> name , '%type' => $ loopType , '%name' => $ loopName ] ) ; } elseif ( $ value === '' ) { if ( ! $ argument -> empty ) { /* check if empty */ $ faultActor [ ] = $ argument -> name ; $ faultDetails [ ] = $ this -> translator -> trans ( '"%param" parameter cannot be empty in loop type: %type, name: %name' , [ '%param' => $ argument -> name , '%type' => $ loopType , '%name' => $ loopName ] ) ; } } elseif ( $ value !== null && ! $ argument -> type -> isValid ( $ value ) ) { /* check type */ $ faultActor [ ] = $ argument -> name ; $ faultDetails [ ] = $ this -> translator -> trans ( 'Invalid value "%value" for "%param" parameter in loop type: %type, name: %name' , [ '%value' => $ value , '%param' => $ argument -> name , '%type' => $ loopType , '%name' => $ loopName ] ) ; } else { /* set default value */ /* did it as last checking for we consider default value is acceptable no matter type or empty restriction */ if ( $ value === null ) { $ value = $ argument -> default ; } $ argument -> setValue ( $ value ) ; } } if ( ! empty ( $ faultActor ) ) { $ complement = sprintf ( '[%s]' , implode ( ', ' , $ faultDetails ) ) ; throw new \ InvalidArgumentException ( $ complement ) ; } }
Initialize the loop arguments.

@param array $nameValuePairs a array of name => value pairs. The name is the name of the argument.

@throws \InvalidArgumentException if some argument values are missing, or invalid
Initialize the loop arguments .