Execute the content queries.

This is tightly coupled to $this->getContent()

@see $this->getContent()

@param array $decoded

@return array
439419
protected function executeGetContentQueries($decoded)
    {
        // Perform actual queries and hydrate
        $totalResults = false;
        $results = false;
        foreach ($decoded['queries'] as $query) {
            $statement = sprintf(
                'SELECT %s.* %s %s %s',
                $query['tablename'],
                $query['from'],
                $query['where'],
                $query['order']
            );

            if ($decoded['self_paginated'] === true) {
                // self pagination requires an extra query to return the actual number of results
                if ($decoded['return_single'] === false) {
                    $countStatement = sprintf(
                        'SELECT COUNT(*) as count %s %s',
                        $query['from'],
                        $query['where']
                    );
                    $countRow = $this->app['db']->executeQuery($countStatement)->fetch();
                    $totalResults = $countRow['count'];
                }

                if (isset($decoded['parameters']['paging']) && $decoded['parameters']['paging'] === true) {
                    $offset = ($decoded['parameters']['page'] - 1) * $decoded['parameters']['limit'];
                } else {
                    $offset = null;
                }
                $limit = $decoded['parameters']['limit'];

                // @todo this will fail when actually using params on certain databases
                $statement = $this->app['db']->getDatabasePlatform()->modifyLimitQuery($statement, $limit, $offset);
            } elseif (!empty($decoded['parameters']['limit'])) {
                // If we're not paging, but we _did_ provide a limit.
                $limit = $decoded['parameters']['limit'];
                $statement = $this->app['db']->getDatabasePlatform()->modifyLimitQuery($statement, $limit);
            }

            if (!empty($decoded['parameters']['printquery'])) {
                // @todo formalize this
                echo nl2br(htmlentities($statement));
            }

            $rows = $this->app['db']->fetchAll($statement, $query['params']);

            // Convert the row 'arrays' into \Bolt\Legacy\Content objects.
            // Only get the Taxonomies and Relations if we have to.
            $rows = $this->hydrateRows($query['contenttype'], $rows, $decoded['hydrate']);

            if ($results === false) {
                $results = $rows;
            } else {
                // We can no longer maintain keys when merging subresults
                $results = array_merge($results, array_values($rows));
            }
        }

        if ($totalResults === false) {
            $totalResults = count($results);
        }

        return [$results, $totalResults];
    }
136559
protected function parse(string $urlencoded): array
    {
        $specifics = [];
        foreach (new URLSearchParams($urlencoded) as $name => $value) {
            $specifics[$name][] = $value;
        }
        return $specifics;
    }
342057
private function decodeArrayNode(\DOMNode $node): array
    {
        $data = [];
        foreach ($node->childNodes as $childNode) {
            if ($childNode instanceof \DOMText) {
                continue;
            }

            $data[] = $this->decodeNode($childNode);
        }

        return $data;
    }
998066
public static function decodeQueryString($source, $rfc = self::RFC_3986)
    {
        $ret = [];
        if ($source !== '') {
            $decode = self::getQueryStringDecoder($rfc);
            $queryPairs = explode('&', $source);
            foreach ($queryPairs as $pair) {
                $parts = explode('=', $pair, 2);
                $key = $decode($parts[0]);
                $value = (count($parts) === 1) ? true : $decode($parts[1]);
                Arr::addValue($ret, $key, $value);
            }
        }

        return $ret;
    }
608626
public function decode($encodedUuid)
    {
        $components = $this->extractComponents($encodedUuid);

        $this->swapFields($components);

        return $this->getBuilder()->build($this, $this->getFields($components));
    }
946803
public function getApiKey($decoded = false)
    {
        return ($decoded === false) ? $this->apiKey : base64_decode($this->apiKey);
    }
49873
public function decode($encodedValue)
    {
        $encryptedValue = base64_decode($encodedValue);
        $value = $this->getEncryptor()->decrypt($encryptedValue);

        return $value;
    }
527734
public function decode($encrypted)
    {

        //$cipher_all = explode("/", $cipher_in);
        //$cipher = $cipher_all[0];

        $blocks = explode("|x", $encrypted);
        $delimiter = array_search("::", $blocks);


        $cipherStream = array_slice($blocks, 0, (int)$delimiter);


        unset($blocks[(int)$delimiter]);
        unset($blocks[(int)$delimiter + 1]);

        $publicKeyArray = array_slice($blocks, (int)$delimiter);

        $publicKey = implode('', $publicKeyArray);
        $privateKey = $this->key;

        $hashKey = sha1($privateKey . "+" . (string)$publicKey);
        $hashArray = str_split($hashKey);

        $counter = 0;
        for ($i = 0; $i < sizeof($cipherStream); $i++) {
            if ($counter > 40)
                $counter = 0;
            $cryptChar = hexdec($cipherStream[$i]) - ord((string)$hashArray[$counter]);
            $cryptChar -= floor($cryptChar / 127) * 127;
            $cipherText[$i] = chr($cryptChar);
            $counter++;
        }

        $plaintext = implode("", $cipherText);

        return $plaintext;
    }
1112058
public function asArray(bool $decodeJSON = true) : array
    {
        if(!$decodeJSON) {
            return $this->_data;
        }

        $return = [];
        foreach($this->_data as $key => $value) {
            $decoded = json_decode($value);

            $return[$key] = $decoded;
            if(
                !is_array($decoded)  &&
                !is_object($decoded)
            ) {
                $return[$key] = $value;
            }
        }

        return $return;
    }
540145
public function decode(string $json): array
    {
        $decoded = \json_decode($json, true);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new DecodingException(\json_last_error_msg(), \json_last_error());
        }
        return $decoded;
    }
592606
public static function encode($decoded)
    {
        switch(gettype($decoded))
        {
            case "integer":
                return self::encodeInteger($decoded);

            case "double":
                return self::encodeDouble($decoded);

            case "boolean":
                return self::encodeBoolean($decoded);

            case "string":
                return self::encodeString($decoded);

            case "array":
                // If the array doesn't have sequential keys from 0 to n then assume we are dealing with a map
                if (array_keys($decoded) !== range (0, count($decoded) - 1))
                {
                    return self::encodeMap($decoded);
                }
                // Otherwise it's a sequence
                else
                {
                    return self::encodeSequence($decoded);
                }

            case "NULL":
                return self::encodeNull();

            case "unknown type":
                return self::encodeUndefined();

            case "object":
                return self::encode(self::objectToMap($decoded));
        }

        // Unknown type, just return null
        return null;
    }
1276095
public function getResponseBody($decode = true)
    {
        $data = $this->response->getBody();
        return $decode === true ? json_decode($data) : $data;
    }
631255
public static function getContent(ResponseInterface $response)
    {
        if ($response->getStatusCode() === 204) {
            return [];
        }

        $body = (string) $response->getBody();

        if (!$body) {
            return [];
        }

        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
            throw new DecodingFailedException('The content type header was not application/json.');
        }

        return self::jsonDecode($body);
    }
1163236
protected function decodeHeader()
    {
        if (isset($this->header->subject)) {
            $this->header->subject = $this->mimeHeaderDecode($this->header->subject);
        }
        if (isset($this->header->details->subject)) {
            $this->header->details->subject = $this->mimeHeaderDecode($this->header->details->subject);
        }
        if (isset($this->header->details->Subject)) {
            $this->header->details->Subject = $this->mimeHeaderDecode($this->header->details->Subject);
        }
        if (isset($this->header->from)) {
            $this->header->from = $this->mimeHeaderDecode($this->header->from);
        }
        if (isset($this->header->to)) {
            $this->header->to = $this->mimeHeaderDecode($this->header->to);
        }
    }
929358
private static function processSectionContents(array $contents)
    {
        $result = array();
        
        // loop through each line and convert it to an array
        foreach ($contents as $path => $value) {
            // convert all a.b.c.d to multi-dimensional arrays
            $process = self::processContentEntry($path, $value);
            
            // merge the current line with all previous ones
            $result = self::arrayMergeRecursive($result, $process);
        }
        
        return $result;
    }
1049363
public function decodeHttpQuery()
    {
        $values = [];

        foreach ($this->getRequest()->query->all() as $key => $parameter) {
            if (strpos($key, self::PAGE) === 0) {
                $chunks = explode('_', $key);
                $contextId = end($chunks);
                $pager = new Pager($this);
                $pager->setFor($contextId)->setCurrent($parameter);
                $values[$key] = $pager;
            }
        }

        return $values;
    }
325139
protected function getContents()
    {
        // Cancel if the file doesn't exist
        if (!$this->getFilesystem()->has($this->getFilepath())) {
            return [];
        }

        // Get and parse file
        if ($this->contents === null) {
            $this->contents = $this->getFilesystem()->read($this->getFilepath());
            $this->contents = json_decode($this->contents, true);
        }

        return (array) $this->contents;
    }