Allow any db field to be parsed (specifically for templates)

@param string $parser
@return mixed
354006
public function Parse($parser = 'TextParser') {
        if($parser == 'TextParser' || is_subclass_of($parser, 'TextParser')) {
            $obj = Object::create($parser, $this->owner->value);
            return $obj->parse();
        } else {
            return $this->owner->Nice();
        }
    }
822489
public function getParser() : ParserInterface
    {
        if (null === $this->parser) {
            $patternHelper = new Parser\Helper\GetPattern($this->cache, $this->logger);
            $dataHelper = new Parser\Helper\GetData($this->cache, $this->logger, new Quoter());

            $this->parser = new Parser\Ini($patternHelper, $dataHelper, $this->formatter);
        }

        return $this->parser;
    }
604444
public function getParser()
    {
        $parser = new QueryParser();
        $parser->addResolvers([
            new Resolvers\ValueResolver(),
            new Resolvers\KeyResolver(),
            new Resolvers\GroupingResolver(),
            new Resolvers\SumFunctionResolver(),
            new Resolvers\DateFormatFunctionResolver(),
            new Resolvers\ConcatFunctionResolver(),
            new Resolvers\NotEqResolver(),
            new Resolvers\EqResolver(),
            new Resolvers\LteResolver(),
            new Resolvers\LtResolver(),
            new Resolvers\GteResolver(),
            new Resolvers\GtResolver(),
            new Resolvers\CtResolver(),
            new Resolvers\SwResolver(),
            new Resolvers\EwResolver(),
            new Resolvers\NotInResolver(),
            new Resolvers\InResolver(),
            new Resolvers\NotNullResolver(),
            new Resolvers\NullResolver(),
            new Resolvers\AndResolver(),
            new Resolvers\OrResolver(),
        ]);

        return $parser;
    }
559784
protected function addData($parser, $data)
    {
        //Having a path data entry means at least 1 callback is interested in
        //the data. Loop through each path here and, if inside that path, add
        //the data
        foreach ($this->pathData as $key => $val) {
            if (strpos($this->currentPath, $key) !== FALSE) {
                $this->pathData[$key] .= $data;
            }
        }

        return $parser;
    }
847638
public static function parse(Parser $parser, TokensList $list, array $options = [])
    {
        $ret = [];

        $expr = new self();

        /**
         * The state of the parser.
         *
         * Below are the states of the parser.
         *
         *      0 -----------------------[ ( ]------------------------> 1
         *
         *      1 --------------------[ CONSTRAINT ]------------------> 1
         *      1 -----------------------[ key ]----------------------> 2
         *      1 -------------[ constraint / column name ]-----------> 2
         *
         *      2 --------------------[ data type ]-------------------> 3
         *
         *      3 ---------------------[ options ]--------------------> 4
         *
         *      4 --------------------[ REFERENCES ]------------------> 4
         *
         *      5 ------------------------[ , ]-----------------------> 1
         *      5 ------------------------[ ) ]-----------------------> 6 (-1)
         *
         * @var int
         */
        $state = 0;

        for (; $list->idx < $list->count; ++$list->idx) {
            /**
             * Token parsed at this moment.
             *
             * @var Token
             */
            $token = $list->tokens[$list->idx];

            // End of statement.
            if ($token->type === Token::TYPE_DELIMITER) {
                break;
            }

            // Skipping whitespaces and comments.
            if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {
                continue;
            }

            if ($state === 0) {
                if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
                    $state = 1;
                } else {
                    $parser->error(
                        'An opening bracket was expected.',
                        $token
                    );

                    break;
                }
            } elseif ($state === 1) {
                if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'CONSTRAINT') {
                    $expr->isConstraint = true;
                } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_KEY)) {
                    $expr->key = Key::parse($parser, $list);
                    $state = 4;
                } elseif ($token->type === Token::TYPE_SYMBOL || $token->type === Token::TYPE_NONE) {
                    $expr->name = $token->value;
                    if (! $expr->isConstraint) {
                        $state = 2;
                    }
                } elseif ($token->type === Token::TYPE_KEYWORD) {
                    if ($token->flags & Token::FLAG_KEYWORD_RESERVED) {
                        // Reserved keywords can't be used
                        // as field names without backquotes
                        $parser->error(
                            'A symbol name was expected! '
                            . 'A reserved keyword can not be used '
                            . 'as a column name without backquotes.',
                            $token
                        );

                        return $ret;
                    }

                    // Non-reserved keywords are allowed without backquotes
                    $expr->name = $token->value;
                    $state = 2;
                } else {
                    $parser->error(
                        'A symbol name was expected!',
                        $token
                    );

                    return $ret;
                }
            } elseif ($state === 2) {
                $expr->type = DataType::parse($parser, $list);
                $state = 3;
            } elseif ($state === 3) {
                $expr->options = OptionsArray::parse($parser, $list, static::$FIELD_OPTIONS);
                $state = 4;
            } elseif ($state === 4) {
                if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'REFERENCES') {
                    ++$list->idx; // Skipping keyword 'REFERENCES'.
                    $expr->references = Reference::parse($parser, $list);
                } else {
                    --$list->idx;
                }
                $state = 5;
            } elseif ($state === 5) {
                if (! empty($expr->type) || ! empty($expr->key)) {
                    $ret[] = $expr;
                }
                $expr = new self();
                if ($token->value === ',') {
                    $state = 1;
                } elseif ($token->value === ')') {
                    $state = 6;
                    ++$list->idx;
                    break;
                } else {
                    $parser->error(
                        'A comma or a closing bracket was expected.',
                        $token
                    );
                    $state = 0;
                    break;
                }
            }
        }

        // Last iteration was not saved.
        if (! empty($expr->type) || ! empty($expr->key)) {
            $ret[] = $expr;
        }

        if (($state !== 0) && ($state !== 6)) {
            $parser->error(
                'A closing bracket was expected.',
                $list->tokens[$list->idx - 1]
            );
        }

        --$list->idx;

        return $ret;
    }
575243
public function parse(Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->entityLocation = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_COMMA);
        $this->latitude = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_COMMA);
        $this->longitude = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
507617
private function parse()
    {
        if (! $this->state = self::STATE_COMPLETE) {
            throw new QueryBuilderException("Query is not yet completed!");
        }

        if ($this->parser === null) {
            $this->parser = new Parser($this);
        }

        $this->parser->validate();

        return $this->parser;
    }
792412
private function getMimeTypeForParser($parser) {
        switch ($parser) {
            case self::PARSER_XML:
                return 'application/xml';
            case self::PARSER_XMLDTD:
                return 'application/xml-dtd';
            case self::PARSER_HTML:
            case self::PARSER_HTML5:
            case self::PARSER_HTML4:
            case self::PARSER_HTML4TR:
                return 'text/html';
        }
    }
534192
public static function fromParser(MangaGenreParser $parser): self
    {
        $instance = new self();
        $instance->itemCount = $parser->getCount();
        $instance->manga = $parser->getGenreManga();
        $instance->malUrl = new MalUrl(
            $parser->getName(),
            $parser->getUrl()
        );

        return $instance;
    }
411071
public static function fromParser(TopListItemParser $parser): self
    {
        $instance = new self();
        $instance->rank = $parser->getRank();
        $instance->malId = $parser->getMalUrl()->getMalId();
        $instance->title = $parser->getMalUrl()->getTitle();
        $instance->url = $parser->getMalUrl()->getUrl();
        $instance->type = $parser->getType();
        $instance->episodes = $parser->getEpisodes();
        $instance->startDate = $parser->getStartDate();
        $instance->endDate = $parser->getEndDate();
        $instance->members = $parser->getMembers();
        $instance->score = $parser->getScore();
        $instance->imageUrl = $parser->getImage();

        return $instance;
    }
760063
protected function getPickItemsHtml(Field $field, ValidationParser $parser)
    {
        $fields = '';

        if ($field->isBoolean()) {
            // At this point we know this is a boolean field, we only need one option
            $fields .= $this->getPickItemsHtmlField($field, $field->getTrueBooleanOption(), $parser) . PHP_EOL;
        } else {
            if (is_null($field->getOptionsByLang())) {
                throw new Exception('The field "' . $field->name . '" has no options!');
            }

            foreach ($field->getOptionsByLang() as $index => $option) {
                $fields .= $this->getPickItemsHtmlField($field, $option, $parser) . PHP_EOL;
            }
        }

        $this->wrapField($fields, $field, true, (($field->htmlType == 'checkbox') && !$field->isBoolean()) ? 'required' : '');

        return $fields;
    }
863050
public static function fromParser(Parser\Search\CharacterSearchListItemParser $parser): self
    {
        $instance = new self();

        $instance->url = $parser->getUrl();
        $instance->malId = \Jikan\Helper\Parser::idFromUrl($instance->url);
        $instance->imageUrl = $parser->getImageUrl();
        $instance->name = $parser->getName();
        $instance->alternativeNames = $parser->getAlternativeNames();
        $instance->anime = $parser->getAnime();
        $instance->manga = $parser->getManga();

        return $instance;
    }
638707
private function parse()
    {
        $types = [];

        foreach ($this->parameters as $parameter) {
            /** @var Query\Parameter $parameter */
            $types[$parameter->getName()] = $parameter->getType();
        }

        // Return previous parser result if the query and the filter collection are both clean
        if ($this->state === self::STATE_CLEAN && $this->parsedTypes === $types && $this->em->isFiltersStateClean()) {
            return $this->parserResult;
        }

        $this->state       = self::STATE_CLEAN;
        $this->parsedTypes = $types;

        // Check query cache.
        $queryCache = $this->getQueryCacheDriver();
        if (! ($this->useQueryCache && $queryCache)) {
            $parser = new Parser($this);

            $this->parserResult = $parser->parse();

            return $this->parserResult;
        }

        $hash   = $this->getQueryCacheId();
        $cached = $this->expireQueryCache ? false : $queryCache->fetch($hash);

        if ($cached instanceof ParserResult) {
            // Cache hit.
            $this->parserResult = $cached;

            return $this->parserResult;
        }

        // Cache miss.
        $parser = new Parser($this);

        $this->parserResult = $parser->parse();

        $queryCache->save($hash, $this->parserResult, $this->queryCacheTTL);

        return $this->parserResult;
    }
668481
public static function fromParser(SeasonListItemParser $parser): self
    {
        $instance = new self();
        $instance->year = $parser->getYear();
        $instance->seasons = $parser->getSeasons();

        return $instance;
    }
991175
public static function parser(ParserInterface $parser = null)
	{
		if($parser) {
			static::$parser = $parser;
		}
		elseif(!static::$parser) {
			static::$parser = new Annotation\KeyValuePairParser;
		}

		return static::$parser;
	}
42868
public static function fromParser(Parser\Search\AnimeSearchListItemParser $parser): self
    {
        $instance = new self();

        $instance->url = $parser->getUrl();
        $instance->malId = \Jikan\Helper\Parser::idFromUrl($instance->url);
        $instance->imageUrl = $parser->getImageUrl();
        $instance->title = $parser->getTitle();
        $instance->synopsis = $parser->getSynopsis();
        $instance->type = $parser->getType();
        $instance->episodes = $parser->getEpisodes();
        $instance->score = $parser->getScore();
        $instance->startDate = $parser->getStartDate();
        $instance->endDate = $parser->getEndDate();
        $instance->members = $parser->getMembers();
        $instance->rated = $parser->getRated();
        $instance->airing = $parser->isAiring();

        return $instance;
    }
1347105
public function getParser()
    {
        if ($this->parser == null) {
            $this->parser = $this->container->get('thelia.parser');

            // Define the current back-office template that should be used
            $this->parser->setTemplateDefinition(
                $this->parser->getTemplateHelper()->getActiveAdminTemplate()
            );
        }

        return $this->parser;
    }