Orders the content with the given order by criteria

@param  array $tokens
@param  array $content
@return array
172926
public static function orderBy(array $tokens, array $content) {
        if (empty($tokens['ORDER'])) return $content;

        $sortingRules = array_map(function($token) use ($content) {
            return [
                end($token['no_quotes']['parts']),
                $token['direction']
            ];
        }, $tokens['ORDER']);

        $reducedSortingRules = array_reduce($sortingRules, 'array_merge', []);
        $sortArgs            = array_map(function($value) use ($content) {
            if ($value === 'ASC')  return SORT_ASC;
            if ($value === 'DESC') return SORT_DESC;

            $contents = [];
            foreach ($content as $c) array_push($contents, $c[$value]);
            return $contents;
        }, $reducedSortingRules);

        $sortArgs[] = &$content;
        call_user_func_array('array_multisort', $sortArgs);

        return end($sortArgs);
    }
867013
private function createResult(array $tokens, $requestMethod, $responseCode, array $content = null) {
        if($responseCode >= 400 && $responseCode < 600) return [];
        if ($requestMethod === HttpMethods::DELETE)     return [];
        $result = $requestMethod === HttpMethods::GET ? SelectResult::create($tokens, $content) : $content;
        krsort($result);

        return $result;
    }
161809
public static function create(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        if (empty($tokens['LIMIT'])) return [];

        $headers = [];
        array_push($headers, 'Limit: ' . $tokens['LIMIT']['rowcount']);
        if(empty($tokens['LIMIT']['offset'])) return $headers;
        array_push($headers, 'Offset: ' . $tokens['LIMIT']['offset']);
        return $headers;
    }
737977
public function getUnorderedChildrenUids(AbstractClassContent $content)
    {
        return $this->getEntityManager()
            ->getConnection()
            ->executeQuery('SELECT content_uid FROM content_has_subcontent WHERE parent_uid=?', array($content->getUid()))
            ->fetchAll(\PDO::FETCH_COLUMN);
    }
453455
function ininstance($content){
        if (strlen($content) < 10) { // State exit or missing parameter.
            return true;
        }
        // Strip off the instance: part and add the reminder to the parsed token array
        $param = trim(substr($content,9));
        $this->tokens[] = new search_token(TOKEN_INSTANCE,$param);
        return true;
    }
532
function indateto($content){
        if (strlen($content) < 8) { // State exit or missing parameter.
            return true;
        }
        // Strip off the dateto: part and add the reminder to the parsed token array
        $param = trim(substr($content,7));
        $this->tokens[] = new search_token(TOKEN_DATETO,$param);
        return true;
    }
23954
function prepareContents(tokens) {
	let contents = new Map

	for (let i = 0, len = tokens.length; i < len; i++) {
		let token = tokens[i]

		if (token.type === 'element' && token.name === 'eh-content') {
			// Find attribute 'name'
			let name = getNameAttributeValue(token),
				arr = getArr(name)

			for (let j = 0, len2 = token.children.length; j < len2; j++) {
				arr.push(token.children[j])
			}
		} else {
			getArr('').push(token)
		}
	}

	/**
	 * @param {string} name
	 * @returns {Array<Token>}
	 */
	function getArr(name) {
		if (!contents.has(name)) {
			let arr = []
			contents.set(name, arr)
			return arr
		}
		return contents.get(name)
	}

	return contents
}
1089875
public function closure($content = null)
    {
        $this->addNewToSequence("open");

        if (!empty($content)) {
            if ($content instanceof TokenSequencer) {
                $this->mergeSequence($content->getSequence());
            } elseif ($content instanceOf Token) {
                $this->addToSequence($content);
            } elseif (is_array($content)) {
                foreach ($content as $subContent) {
                    $this->addMixedContentToSequence($subContent);
                }
            } else {
                $this->val($content);
            }
        }

        $this->addNewToSequence("close");

        return $this;
    }
728203
public function orderBy($fields)
    {
        if (!is_array($fields)) {
            $fields = $this->splitParts($fields);
        }

        foreach ($fields as $k => $field) {
            if (preg_match('#^(.*?)\s+(asc|desc)$#i', $field, $matches)) {
                $fields[$k] = $this->db->quoteColumn($matches[1]) . ' ' . $matches[2];
            } else {
                $fields[$k] = $this->db->quoteColumn($field);
            }
        }

        $this->query['order'] = implode(',', $fields);

        return $this;
    }
448134
public function apply(array &$tokens)
		{
		$r = 0;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			if (get_class($tokens[$i]) === "CssCommentToken")
				{
				$tokens[$i] = null;
				$r++;
				}
			}
		return $r;
		}
207524
private function getTokens($content)
    {
        // fetch non-empty lines
        $lines = preg_split('/\r\n|\r|\n/', $content, -1, PREG_SPLIT_NO_EMPTY);
        $tokens = array();
        foreach ($lines as $line) {
            // throwing tokens after '#' sign
            $commentCharPosition = strpos($line, "#");
            $lineWithoutComments = ($commentCharPosition === false) ? $line : substr($line, 0, strpos($line, "#"));
            // storing current line tokens
            if ($lineWithoutComments) {
                $tokens = array_merge($tokens, preg_split('/\s+/', $lineWithoutComments, -1, PREG_SPLIT_NO_EMPTY));
            }
        }
        return $tokens;
    }
475682
public static function alias(array $tokens) {
        $column     = self::column($tokens, new MetaData());
        $tableAlias = Table::alias($tokens);

        return empty($tableAlias) ? $column : $tableAlias . '.' . $column;
    }
1131442
public function apply(array &$tokens)
		{
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			$current	= get_class($tokens[$i]);
			$next		= isset($tokens[$i+1]) ? get_class($tokens[$i+1]) : false;
			if (($current === "CssRulesetDeclarationToken" && $next === "CssRulesetEndToken") ||
				($current === "CssAtFontFaceDeclarationToken" && $next === "CssAtFontFaceEndToken") || 
				($current === "CssAtPageDeclarationToken" && $next === "CssAtPageEndToken"))
				{
				$tokens[$i]->IsLast = true;
				}
			}
		return 0;
		}
1142271
protected function handleEntryState($content, $position, TokenList $tokenList) {
        $tokenList->addToken($this->name . self::OPEN, $position);

        $tokenList->addToken($this->name . '_HEADER_OPEN', $position)
            ->set('align', $this->colAlign);
        $tokenList->addToken($this->name . '_ROW_OPEN', $position);

        list(, $cols, $delimiters) = explode("\n", $content);
        $cols = explode('|', trim($cols, '|'));
        $delimiters = explode('|', trim($delimiters, '|'));

        foreach ($delimiters as &$delimiter) {
            $delimiter = trim($delimiter);
            if ($delimiter[0] === ':' && $delimiter[strlen($delimiter) - 1] === ':') {
                $delimiter = 'center';
            } elseif ($delimiter[0] === ':') {
                $delimiter = 'left';
            } elseif ($delimiter[strlen($delimiter) - 1] === ':') {
                $delimiter = 'right';
            } else {
                $delimiter = null;
            }
        }

        $this->colAlign = $delimiters;

        foreach ($cols as $i => $col) {
            $token = $tokenList->addToken($this->name . '_HEAD_COLL_OPEN', $position);
            if (isset($this->colAlign[$i]) && $this->colAlign[$i] !== null) {
                $token->set('align', $this->colAlign[$i]);
            }

            $this->parseCol($col, $tokenList);

            $tokenList->addToken($this->name . '_HEAD_COLL_CLOSE', $position);
        }

        $tokenList->addToken($this->name . '_ROW_CLOSE', $position);
        $tokenList->addToken($this->name . '_HEADER_CLOSE', $position)
            ->set('align', $this->colAlign);
    }
504438
public static function parameters($tokenId, array $tokens) {
		$params = array();
		if ($tokens[$tokenId]['id'] !== T_FUNCTION) {
			throw new \Exception('Cannot call params on non function');
		}
		$foundOpen = false;
		$total = count($tokens);
		for ($key = $tokenId; $key <= $total; $key++) {
			$token = $tokens[$key];
			if ($foundOpen) {
				if ($token['content'] === ')') {
					break;
				} elseif ($token['id'] === T_VARIABLE) {
					$params[] = $key;
				}
			} elseif ($token['content'] === '(') {
				$foundOpen = true;
			}
		}
		return $params;
	}
1086930
public function indexContent(Content $content)
    {
        $document = $this->mapper->mapContent($content);

        $this->gateway->index($document);
    }
328769
protected function handleSingleState($content, $position, TokenList $tokenList) {
        preg_match('/!\\[((?:\\\\.|[^]\\\\])+)\\][\\t ]*\\[((?:\\\\.|[^]\\\\])*)\\]/', $content, $matches);
        $reference = strtolower(empty($matches[2]) ? $matches[1] : $matches[2]);

        $referenceTokens = $tokenList->getTokensByCallback(function (Token $token) use ($reference) {
            return $token->getName() === ReferenceRule::NAME && $token->get('reference', null) === $reference;
        });

        if (($referenceToken = reset($referenceTokens)) !== false) {
            $referenceToken->set('used', true);
            $reference = $referenceToken;
        }

        $tokenList->addToken($this->name, $position)
            ->set('match', $content)
            ->set('alt', $matches[1])
            ->set('reference', $reference);
    }