Retrieves needed arguments from container and returns them

@param ContainerInterface $container
@param array              $arguments
@param mixed              $subject
@param mixed              $message

@return array
@throws DispatcherException
428320
protected function prepare(ContainerInterface $container, array $arguments = [], $subject = null, $message = null)
    {
        $result = [];

        foreach ($arguments as $k => $arg) {
            if (is_array($arg)) {
                $result[$k] = $this->prepare($container, $arg);
                continue;
            } elseif ($arg == '@Container') {
                $result[$k] = $container;
                continue;
            } elseif ($arg == '@Subject') {
                $result[$k] = $subject;
                continue;
            } elseif ($arg == '@Message') {
                $result[$k] = $message;
                continue;
            } elseif (strpos($arg, '@') !== 0) {
                $result[$k] = $arg;
                continue;
            }

            $result[$k] = $container->get(substr($arg, 1));
        }

        return $result;
    }
704551
public function send($message): array
    {
        if (\is_array($message)) {
            $message = CloudMessage::fromArray($message);
        }

        if (!($message instanceof Message)) {
            throw new InvalidArgumentException(
                'Unsupported message type. Use an array or a class implementing %s'.Message::class
            );
        }
        $response = $this->messagingApi->sendMessage($message);

        return JSON::decode((string) $response->getBody(), true);
    }
971165
public function autowireArguments(ReflectionFunctionAbstract $reflection, array $arguments)
    {
        $newArguments = $arguments;
        foreach ($reflection->getParameters() as $index => $parameter) {
            if ($this->isArgumentWireable($newArguments, $index, $parameter)) {
                $newArguments[$index] = $this->container->get($parameter->getClass()->getName());
            }
        }

        return $newArguments;
    }
494236
protected function resolveArguments(
        ContainerInterface $container,
        \ReflectionMethod $method,
        array $parameters
    ) {
        try {
            //Getting set of arguments should be sent to requested method
            return $container->get(ResolverInterface::class)->resolveArguments(
                $method,
                $parameters
            );
        } catch (ArgumentException $e) {
            throw new ControllerException(
                "Missing/invalid parameter '{$e->getParameter()->name}'",
                ControllerException::BAD_ARGUMENT
            );
        } catch (ContainerExceptionInterface $e) {
            throw new ControllerException($e->getMessage(), ControllerException::ERROR, $e);
        }
    }
564516
protected function getVariables(TokenInterface $token, $subject)
    {
        $event = new GetExpressionVariablesEvent($token);
        $this->dispatcher->dispatch(ExpressionVariableEvents::GET, $event);

        $variables = array_merge($event->getVariables(), [
            'object' => $subject,
            'subject' => $subject,
        ]);

        if ($subject instanceof Request) {
            $variables['request'] = $subject;
        }

        return $variables;
    }
941124
public function positiveMatch(string $name, $subject, array $arguments): ?\PhpSpec\Wrapper\DelayedCall
    {
        list($realEvents, $targetEvents) = $this->formatArguments($subject, $arguments);

        $notFoundEvents = $this->eventsNotFound($realEvents, $targetEvents);

        if ( ! empty($notFoundEvents)) {
            $eventNames = join(', ', array_map(function (DomainEvent $event) {
                return '<label>' . get_class($event) . '</label>';
            }, $notFoundEvents));

            throw new FailureException("Expected matching event(s) {$eventNames} not found.");
        }

        return null;
    }
7941
private function resolveArguments(ContainerBuilder $container, array $arguments, $isRoot = false)
    {
        foreach ($arguments as $k => $argument) {
            if ($isRoot) {
                // yes, we are specifically fetching the definition from the
                // container to ensure we are not operating on stale data
                $arguments[$k] = $argument = $container->getDefinition($k);
                $this->currentId = $k;
            }
            if (is_array($argument)) {
                $arguments[$k] = $this->resolveArguments($container, $argument);
            } elseif ($argument instanceof Definition) {
                if ($argument instanceof DefinitionDecorator) {
                    $arguments[$k] = $argument = $this->resolveDefinition($container, $argument);
                    if ($isRoot) {
                        $container->setDefinition($k, $argument);
                    }
                }
                $argument->setArguments($this->resolveArguments($container, $argument->getArguments()));
                $argument->setMethodCalls($this->resolveArguments($container, $argument->getMethodCalls()));
                $argument->setProperties($this->resolveArguments($container, $argument->getProperties()));

                $configurator = $this->resolveArguments($container, array($argument->getConfigurator()));
                $argument->setConfigurator($configurator[0]);

                $factory = $this->resolveArguments($container, array($argument->getFactory()));
                $argument->setFactory($factory[0]);
            }
        }

        return $arguments;
    }
484582
public function transform(Template $message)
    {
        if (empty($message->getText())) {
            throw new RequiredArgumentException('Text is required');
        }

        return [
            'template_type' => 'button',
            'text' => $message->getText(),
            'buttons' => $message->getCollections()->toData(),
        ];
    }
462518
protected function execute($name, $arguments, $message)
    {
        if (array_key_exists($name, $this->commands)) {
            return $this->commands[$name]->make($this->telegram, $arguments, $message);
        } elseif (array_key_exists($name, $this->commandAliases)) {
            return $this->commandAliases[$name]->make($this->telegram, $arguments, $message);
        } elseif ($command = collect($this->commands)->filter(function($command) use ($name){
            return $command instanceof $name;
        })->first()) {
            $command->make($this->telegram, $arguments, $message);
        } elseif (array_key_exists('help', $this->commands)) {
            return $this->commands['help']->make($this->telegram, $arguments, $message);
        }

        return 'Ok';
    }
1180424
public static function sendSimple($to, string $subject, string $message) : array {
		return self::send(['to' => $to, 'subject' => $subject, 'message' => $message]);
	}
229705
private function computeArguments(
        \ReflectionMethod $constructor,
        MapInterface $properties
    ): MapInterface {
        $arguments = $properties->clear();

        foreach ($constructor->getParameters() as $parameter) {
            if ($this->canInject($parameter, $properties)) {
                $arguments = $arguments->put(
                    $parameter->name,
                    $properties->get($parameter->name)
                );
            }
        }

        return $arguments;
    }
932783
protected function parseCallbacks(ContainerInterface $container, EventDispatcherInterface $dispatcher)
    {
        $args = [$container->getName()];
        foreach ([
                'config/onload_callback'                => [
                    'event' => CreateDcGeneralEvent::NAME,
                    'class' => ContainerOnLoadCallbackListener::class
                ],
                'config/onsubmit_callback'              => [
                    'event' => PostPersistModelEvent::NAME,
                    'class' => ContainerOnSubmitCallbackListener::class
                ],
                'config/ondelete_callback'              => [
                    'event' => PostDeleteModelEvent::NAME,
                    'class' => ContainerOnDeleteCallbackListener::class
                ],
                'config/oncut_callback'                 => [
                    'event' => PostPasteModelEvent::NAME,
                    'class' => ContainerOnCutCallbackListener::class
                ],
                'config/oncopy_callback'                => [
                    'event' => PostDuplicateModelEvent::NAME,
                    'class' => ContainerOnCopyCallbackListener::class
                ],
                'list/sorting/header_callback'          => [
                    'event' => GetParentHeaderEvent::NAME,
                    'class' => ContainerHeaderCallbackListener::class
                ],
                'list/sorting/paste_button_callback'    => [
                    [
                        'event' => GetPasteRootButtonEvent::NAME,
                        'class' => ContainerPasteRootButtonCallbackListener::class
                    ],
                    [
                        'event' => GetPasteButtonEvent::NAME,
                        'class' => ContainerPasteButtonCallbackListener::class
                    ]
                ],
                'list/sorting/child_record_callback'    => [
                    'event' => ParentViewChildRecordEvent::NAME,
                    'class' => ModelChildRecordCallbackListener::class
                ],
                'list/label/group_callback'             => [
                    'event' => GetGroupHeaderEvent::NAME,
                    'class' => ModelGroupCallbackListener::class
                ],
                'list/label/label_callback'             => [
                    'event' => ModelToLabelEvent::NAME,
                    'class' => ModelLabelCallbackListener::class
                ],
                'list/presentation/breadcrumb_callback' => [
                    'event' => GetBreadcrumbEvent::NAME,
                    'class' => ContainerGetBreadcrumbCallbackListener::class
                ]
            ] as $name => $callback) {
            if ($callbacks = $this->getFromDca($name)) {
                if (isset($callback['event'])) {
                    $this->parseCallback($dispatcher, $callbacks, $callback['event'], $args, $callback['class']);

                    continue;
                }

                foreach ($callback as $sub) {
                    $this->parseCallback($dispatcher, $callbacks, $sub['event'], $args, $sub['class']);
                }
            }
        }

        foreach ((array) $this->getFromDca('list/global_operations') as $name => $operation) {
            if (isset($operation['button_callback'])) {
                $this->parseCallback(
                    $dispatcher,
                    [$operation['button_callback']],
                    GetGlobalButtonEvent::NAME,
                    [$container->getName(), $name],
                    ContainerGlobalButtonCallbackListener::class
                );
            }
        }

        foreach ((array) $this->getFromDca('list/operations') as $name => $operation) {
            if (isset($operation['button_callback'])) {
                $this->parseCallback(
                    $dispatcher,
                    [$operation['button_callback']],
                    GetOperationButtonEvent::NAME,
                    [$container->getName(), $name],
                    ModelOperationButtonCallbackListener::class
                );
            }
        }

        $this->parsePropertyCallbacks($container, $dispatcher);
    }
405325
public function get(ContainerInterface $container = null)
    {
        if (empty($this->arguments)) {
            $instance = new $this->class();
        } else {
            $ref = new \ReflectionClass($this->class);
            $instance = $ref->newInstanceArgs($this->prepare($container, $this->arguments));
        }

        return $this->executeMethods($instance, $container);
    }
951419
private function arrayHelperMethod( $fn, array $args )
    {

        $class = $this->classGet();
        $fnArguments = array( $this->collection );

        foreach( $args as $container ) {

            // validate the arguments
            if( !( $container instanceof $this ) ) {
                throw new \InvalidArgumentException("You can only `{$fn}` containers.");
            }
            $containerClass = $container->classGet();
            if( isset($class) and isset( $containerClass ) and ( $class !== $containerClass ) ) {
                throw new IncompatibleContainerException("Container -> `{$containerClass}` not compatible with `{$class}`");
            }

            $fnArguments[] = $container->collection;

        }

        $output = $this->newContainer(
            call_user_func_array(
                $fn,
                $fnArguments
            )
        );
        return $output;

    }
839595
private function getInjectionFuncParams(Argument $argument) : array
    {
        $dependencyIndex = (string) $argument;
        if ($this->container->getContainer()[$dependencyIndex] instanceof DependencyProvider) {
            return $this->getInjectionProviderParams($argument);
        }

        return [new Node\Arg(new Scalar\String_((string) $argument))];
    }
764393
protected function dispatchMessage($message): Envelope
    {
        if (!$this->container->has('messenger.default_bus')) {
            $message = class_exists(Envelope::class) ? 'You need to define the "messenger.default_bus" configuration option.' : 'Try running "composer require symfony/messenger".';
            throw new \LogicException('The message bus is not enabled in your application. '.$message);
        }

        return $this->container->get('messenger.default_bus')->dispatch($message);
    }
1356934
private function getServiceCallsFromArguments(array $arguments, array &$calls, array &$behavior)
    {
        foreach ($arguments as $argument) {
            if (is_array($argument)) {
                $this->getServiceCallsFromArguments($argument, $calls, $behavior);
            } elseif ($argument instanceof Reference) {
                $id = (string) $argument;

                if (!isset($calls[$id])) {
                    $calls[$id] = 0;
                }
                if (!isset($behavior[$id])) {
                    $behavior[$id] = $argument->getInvalidBehavior();
                } elseif (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $behavior[$id]) {
                    $behavior[$id] = $argument->getInvalidBehavior();
                }

                ++$calls[$id];
            }
        }
    }