Build factories from a array template

@param array $template
@param array $factories
@param ParserInterface|null $parser
@return RuleInterface
195084
public static function buildStructure(array $template, array $factories = [], ParserInterface $parser = null): RuleInterface
    {
        $data = ['@template' => $template];

        $story = new Structure($factories);
        $parser = $parser ?? new Standard;

        $parser->parse($data, $story);
        return $data['@template'];
    }
1128905
public function withRuleFactory(string $name, callable $factory): ValidatorFactory
    {
        $factories = array_merge($this->factories, [$name => $factory]);

        return new ValidatorFactory($this->translator, $factories);
    }
1250130
protected static function initializeColumns(\Template $template)
	{
		$layout = Bootstrap::getLayout();

		switch($layout->cols)
		{
			case '2cll':
				$template->leftClass           = $layout->bootstrap_leftClass;
				$template->mainClass           = $layout->bootstrap_mainClass;

				$template->mainClassAttribute  = sprintf(static::$classAttribute, $layout->bootstrap_mainClass);
				$template->leftClassAttribute  = sprintf(static::$classAttribute, $layout->bootstrap_leftClass);
				break;

			case '2clr':
				$template->rightClass          = $layout->bootstrap_rightClass;
				$template->mainClass           = $layout->bootstrap_mainClass;

				$template->mainClassAttribute  = sprintf(static::$classAttribute, $layout->bootstrap_mainClass);
				$template->rightClassAttribute = sprintf(static::$classAttribute, $layout->bootstrap_rightClass);
				break;

			case '3cl':
				$template->leftClass           = $layout->bootstrap_leftClass;
				$template->rightClass          = $layout->bootstrap_rightClass;
				$template->mainClass           = $layout->bootstrap_mainClass;

				$template->mainClassAttribute  = sprintf(static::$classAttribute, $layout->bootstrap_mainClass);
				$template->rightClassAttribute = sprintf(static::$classAttribute, $layout->bootstrap_rightClass);
				$template->leftClassAttribute  = sprintf(static::$classAttribute, $layout->bootstrap_leftClass);
				break;

			default:
				$template->useGrid = false;
				return;
		}

		$template->useGrid = true;
	}
784555
public function addFactory(PaginatedCollectionRequestFactoryInterface $factory, $priority = 0)
    {
        $this->factories[$priority][] = $factory;

        unset($this->sorted);
    }
144569
function factory($row) {
		$mapper=clone($this);
		$mapper->reset();
		foreach ($row as $key=>$val) {
			if (array_key_exists($key,$this->fields))
				$var='fields';
			elseif (array_key_exists($key,$this->adhoc))
				$var='adhoc';
			else
				continue;
			$mapper->{$var}[$key]['value']=$val;
			$mapper->{$var}[$key]['initial']=$val;
			if ($var=='fields' && $mapper->{$var}[$key]['pkey'])
				$mapper->{$var}[$key]['previous']=$val;
		}
		$mapper->query=[clone($mapper)];
		if (isset($mapper->trigger['load']))
			\Base::instance()->call($mapper->trigger['load'],$mapper);
		return $mapper;
	}
300730
public function withTemplates(array $templates = []): Translator
    {
        $templates = array_merge($this->templates, $templates);

        return new Translator($this->labels, $templates);
    }
360750
public function compile($args, $compiler)
    {
        // check and get attributes
        $_attr = $this->getAttributes($compiler, $args);
        $_name = trim($_attr['name'], "\"'");

        // check if we process an inheritance child template
        if ($compiler->inheritance_child) {
            array_unshift(self::$nested_block_names, $_name);
            // build {block} for child block
            self::$block_data[$_name]['source'] =
                "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" .
                " uid='{$compiler->template->source->uid}' line={$compiler->lex->line}";
            if ($_attr['nocache']) {
                self::$block_data[$_name]['source'] .= ' nocache';
            }
            self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter;

            $save = array($_attr, $compiler->inheritance);
            $this->openTag($compiler, 'block', $save);
            // set flag for {block} tag
            $compiler->inheritance = true;
            $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
            $compiler->has_code = false;
            return;
        }
        // must merge includes
        if ($_attr['nocache'] == true) {
            $compiler->tag_nocache = true;
        }
        $save = array($_attr, $compiler->inheritance, $compiler->parser->current_buffer, $compiler->nocache);
        $this->openTag($compiler, 'block', $save);
        $compiler->inheritance = true;
        $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;

        $compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
        $compiler->has_code = false;

        return true;
    }
1153058
public function factory($name, array $args = array())
    {
        foreach ($this->factories as $factory) {
            $command = $factory->factory($name, $args);
            if ($command) {
                return $command;
            }
        }
    }
182101
public function buildTemplate($template, array $vars = [])
    {
        // Заменяем переменные в шаблоне
        //$found_template[$key] = preg_replace(array_keys($vars_preg_replace), array_values($vars_preg_replace), $value);

        try {
            //$tmp = $this->getContainer()->get('twig')->createTemplate('{% spaceless %} ' . $template . ' {% endspaceless %}');
            //                     'cache' => new \Twig_Cache_Filesystem($this->getConnector()->getTempDir(), \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION),
            $tmp = $this->getContainer()->get('twig')->createTemplate('{% spaceless %} ' . $template . ' {% endspaceless %}');

            if ($vars) {
                $result = $tmp->render($vars);
            } else {
                $result = $tmp->render($this->vars);
            }

            /*
            $loader = new \Twig_Loader_Array(array(
                'index.html' => '{% spaceless %}' . $template . '{% endspaceless %}',
            ));

            $twig = new \Twig_Environment($loader, array(
                'autoescape' => false,
                'debug' => false
            ));

            $result = $twig->render('index.html', $this->vars);
            */
        } catch (\Exception $e) {
            $result = '';
        }

        $result = str_replace([' x ', ' х ', '()', ' ,', ' .', '( )'], [' ', ' ', '', ',', '.', ''], $result);

        // Вырезаем незамененые переменные
        //$result = trim(preg_replace('/\{\{.*\}\}/im', ' ', $result));

        $result = trim($result, ',:');

        // Удалить два и более пробела
        $result = trim(preg_replace('/ {2,}/m', ' ', $result));

        return $result;
    }
379341
protected function getFactory(): FactoryInterface
    {
        if ($this->container instanceof FactoryInterface) {
            return $this->container;
        }

        return $this->container->get(FactoryInterface::class);
    }
724975
protected function createDefaultValidator(Factory $factory)
    {
        return $factory->make(
            $this->validationData(), $this->app()->call([$this, 'rules']),
            $this->messages(), $this->attributes()
        );
    }
586453
protected static function defaultCreateQueryParser(
        ContainerInterface $container,
        string $rulesClass = DefaultQueryValidationRules::class
    ): JsonApiQueryParserInterface {
        static::assertClassImplements($rulesClass, JsonApiQueryRulesInterface::class);

        /** @var JsonApiParserFactoryInterface $factory */
        $factory = $container->get(JsonApiParserFactoryInterface::class);
        $parser  = $factory->createQueryParser($rulesClass);

        return $parser;
    }
473991
public static function factory( array $options = null )
    {
        if ( ! empty( $options['type'] ) &&
             empty( $options['subType'] ) &&
             $type = strstr( $options['type'], '.', true ) )
        {
            $options['subType'] = substr( $options['type'], strlen( $type ) + 1 );
            $options['type']    = $type;
        }

        return parent::factory( $options );
    }
464720
protected function getParser($template = null)
    {
        $parser = $this->container->get("thelia.parser");

        // Define the template that should be used
        $parser->setTemplateDefinition(
            $template ?: $this->getTemplateHelper()->getActiveFrontTemplate(),
            $this->useFallbackTemplate
        );

        return $parser;
    }
811371
public static function fromArray(array $templates): Templates
    {
        // No templates. Nothing to do.
        if (empty($templates)) {
            return new static();
        }

        $result = new static();

        foreach ($templates as $index => $template) {
            $result->add(new Template($template), $index);
        }

        return $result;
    }
1072005
private function templates(array $templates)
    {
        if ($templates) {
            foreach ($templates as $template) {
                if ($template->getManaged()) {
                    yield $template;
                }
            }

            return;
        }

        foreach ($this->templateManager->findAll() as $template) {
            if ($template->getManaged()) {
                yield $template;
            }
        }
    }
714104
protected final function createParser(array $grammar, array $rules)
    {
        if (!$this->_syntaxParserFactory) {
            throw new RequiredDependencyException(sprintf(
                'Syntax parser factory is not injected in class "%s".',
                get_class($this)
            ));
        }

        return $this->_syntaxParserFactory->createParser($grammar, $rules);
    }