completer example

$prefix = ltrim($this->Request()->getParam('prefix'), '$');

        /** @var Mail $mail */
        $mail = $this->getRepository()->find((int) $this->Request()->getParam('mailId'));
        $shop = $this->get(ModelManager::class)->getRepository(Shop::class)->getActiveDefault();
        $shop->registerResources();

        $context = array_merge($this->getDefaultMailContext($shop)$mail->getContext());

        $completer = $this->container->get(AutoCompleteResolver::class);

        $context = $completer->completer($context$this->Request()->getParam('smartyCode'));
        $context = $mail->arrayGetPath($context);

        $result = [];

        foreach ($context as $key => $value) {
            if (strpos($key$prefix) !== false || !$prefix) {
                $result[] = ['word' => '$' . $key, 'value' => \is_array($value) ? 'Array' : (string) $value];
            }
        }

        $this->View()->assign('data', $result);
        

    private $completer;

    public function __construct(iterable $completer)
    {
        $this->completer = $completer;
    }

    public function completer(array $context, string $smartyCode): array
    {
        foreach ($this->completer as $completer) {
            $context = $completer->completer($context$smartyCode);
        }

        return $context;
    }
}
Home | Imprint | This part of the site doesn't use cookies.