Build a generic clause

@param  string $clauseName
@param  string $clausePrefix
@param  array $settings
@param  array $clauseParts
@return string
@access protected
961240
protected function buildClause(
        /*# string */ $clauseName,
        /*# string */ $clausePrefix,
        array $settings,
        array $clauseParts = []
    )/*# string */ {
        $clause = &$this->getClause($clauseName);
        foreach ($clause as $alias => $field) {
            $part =
                $this->quoteItem($field[0], $settings, $field[1]) .
                $this->quoteAlias($alias, $settings) .
                (isset($field[2]) ? (' ' . $field[2]) : '');
            $clauseParts[] = $part;
        }
        return $this->joinClause($clausePrefix, ',', $clauseParts, $settings);
    }
823980
public function getClause($clause)
    {
        if(!isset($this->clauses[$clause])) {
            throw new \RuntimeException(sprintf('Clause "%s" is not declared in Statement.', $clause));
        }
        return $this->clauses[$clause];
    }
1230711
private function buildExtensionSelect($alias, $extension, $propertyName, $locale, &$additionalFields)
    {
        $extension = $this->extensionManager->getExtension('all', $extension);
        $additionalFields[$locale][] = [
            'name' => $alias,
            'extension' => $extension,
            'property' => $propertyName,
        ];
    }
461226
private function addBinding($clause, $value)
	{
		$this->bindings[$clause][] = $value;

		return sprintf(':%s%d', $clause, count($this->bindings[$clause]));
	}
353098
public function make_section_constants($section) {
		if(!is_null($section) && strlen($section) && in_array($section, $this->get_valid_sections())) {
			foreach($this->fullConfig[$section] as $k=>$parsedValue) {
				//TODO: implement option to set a section/value as a CONSTANT
				$constantName = $k;
				if(!defined($constantName)) {
					define($constantName, $parsedValue);
				}
				
				$constantPlusSection = preg_replace('~\-~', '_', $section) .'-'. $constantName;
				if(!defined($constantPlusSection)) {
					define($constantPlusSection, $parsedValue);
				}
			}
		}
		else {
			throw new InvalidArgumentException("non-existent section, '". $section ."'");
		}
	}
525844
public function recurse($messageParts, $prefix = '', $index = 1, $fullPrefix = true)
    {

        foreach ($messageParts as $part) {

            $partNumber = $prefix . $index;

            if ($part->type == 0) {
                if ($part->subtype == 'PLAIN') {
                    $this->bodyPlain .= $this->getPart($partNumber, $part->encoding);
                } else {
                    $this->bodyHTML .= $this->getPart($partNumber, $part->encoding);
                }
            } elseif ($part->type == 2) {
                $msg = new self($this->conn, $this->messageNumber);
                $msg->getAttachments = $this->getAttachments;
                $msg->recurse($part->parts, $partNumber . '.', 0, false);
                $this->attachments[] = array(
                    'type' => $part->type,
                    'subtype' => $part->subtype,
                    'filename' => '',
                    'data' => $msg,
                    'inline' => false,
                );
            } elseif (isset($part->parts)) {
                if ($fullPrefix) {
                    $this->recurse($part->parts, $prefix . $index . '.');
                } else {
                    $this->recurse($part->parts, $prefix);
                }
            } elseif ($part->type > 2) {
                if (isset($part->id)) {
                    $id = str_replace(array('<', '>'), '', $part->id);
                    $this->attachments[$id] = array(
                        'type' => $part->type,
                        'subtype' => $part->subtype,
                        'filename' => $this->getFilenameFromPart($part),
                        'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '',
                        'inline' => true,
                    );
                } else {
                    $this->attachments[] = array(
                        'type' => $part->type,
                        'subtype' => $part->subtype,
                        'filename' => $this->getFilenameFromPart($part),
                        'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '',
                        'inline' => false,
                    );
                }
            }

            $index++;

        }

        return $this->attachments;

    }
826585
public function toQuery( $variableSet, $factVariableBinding )
	{
		$clauses = array();

		// Include the qnames if being called as part of a boolean filter or there are qname expressions
		if ( $this->inBoolean || $this->qnameExpressions )
		foreach ( $this->qnames as $clark )
		{
			$qname = qname( $clark );
			$clauses[] = "(fn:node-name(.) eq fn:QName('{$qname->namespaceURI}','{$qname->localName}'))";
		}

		foreach ( $this->qnameExpressions as $qnameExpression )
		{
			$clauses[] = "(fn:node-name(.) eq $qnameExpression)";
		}

		if ( ! $clauses )
		{
			return null;
		}

		$query = implode( " or ", $clauses );
		return count( $clauses ) > 1 ? "($query)" : $query;
	}
1083924
protected function buildSql(array $settings)/*# : string */
    {
        $result = $this->getType(); // type
        $settings['join'] = $settings['seperator'] . $settings['indent'];

        $result .= $this->buildBeforeAfter('AFTER', 'TYPE', $settings); // hint
        foreach ($this->getConfigs() as $pos => $prefix) {
            // before
            $result .= $this->buildBeforeAfter('BEFORE', $pos, $settings);

            $method = 'build' . ucfirst(strtolower($pos));
            $result .= $this->{$method}($prefix, $settings);

            // after
            $result .= $this->buildBeforeAfter('AFTER', $pos, $settings);
        }

        $result .= $this->buildBeforeAfter('AFTER', 'STMT', $settings);
        return $result;
    }
1332638
protected function buildQuery( QuoteInterface $db, $filterComponents )
    {

        // primary keys
        $filterTags = array();
        $dataTypes = $this->dataTypesGet();

        // have we got components that we can't handle
        if( $dataTypesMissing = array_diff( array_keys( $filterComponents ), array_keys( $dataTypes ) ) ) {
            throw new \LogicException(
                sprintf(
                    "The following keys `%s` don't exist in %s. You can't find a entity with this.",
                    implode(',', $dataTypesMissing ),
                    $this->table
                )
            );
        }

        // add the datatype tag to the filter component
        foreach( $filterComponents as $name => $component ) {
            $component->tag = $dataTypes[$name]->toQueryTag();
        }

        $data = array();

        # system column tableoid can tell us which table a row comes from
        # http://www.postgresql.org/docs/9.1/static/ddl-inherit.html
        $sql = sprintf(
            "SELECT * FROM ONLY %s %s",
            $db->quoteIdent( $this->table ),
            $this->buildQueryWhereClause( $db, $filterComponents, $data )
        );

        $query = new Query( $sql, $data );

        return $query;

    }
643670
public function getSettings(string $pattern, array $settings = []) : array
    {
        // The pattern has been pre-quoted on generation to speed up the pattern search,
        // but for this check we need the unquoted version
        $unquotedPattern = $this->quoter->pregUnQuote($pattern);

        // Try to get settings for the pattern
        $addedSettings = $this->getIniPart($unquotedPattern);

        // set some additional data
        if (0 === count($settings)) {
            // The optimization with replaced digits get can now result in setting searches, for which we
            // won't find a result - so only add the pattern information, is settings have been found.
            //
            // If not an empty array will be returned and the calling function can easily check if a pattern
            // has been found.
            if (0 < count($addedSettings)) {
                $settings['browser_name_regex'] = '/^' . $pattern . '$/';
                $settings['browser_name_pattern'] = $unquotedPattern;
            }
        }

        // check if parent pattern set, only keep the first one
        $parentPattern = null;

        if (isset($addedSettings['Parent'])) {
            $parentPattern = $addedSettings['Parent'];

            if (isset($settings['Parent'])) {
                unset($addedSettings['Parent']);
            }
        }

        // merge settings
        $settings += $addedSettings;

        if (is_string($parentPattern)) {
            return $this->getSettings($this->quoter->pregQuote($parentPattern), $settings);
        }

        return $settings;
    }
541225
private function addBindings($clause, array $values)
	{
		$result = [];

		foreach ($values as $key => $value) {
			$result[$key] = $this->addBinding($clause, $value);
		}

		return $result;
	}
282983
protected function joinClause(
        /*# : string */ $prefix,
        /*# : string */ $seperator,
        array $clause,
        array $settings
    )/*# : string */ {
        if (empty($clause)) {
            return '';
        } else {
            $sepr = $settings['seperator'];
            $join = $settings['join'];
            $pref = empty($prefix) ? $join : ($sepr . $prefix . $join);
            return $pref . join($seperator . $join, $clause);
        }
    }
1362216
public function renderPartial($partialName, $sectionName, array $variables)
    {
        if (!isset($this->partialIdentifierCache[$partialName])) {
            $this->partialIdentifierCache[$partialName] = $this->getPartialIdentifier($partialName);
        }
        $partialIdentifier = $this->partialIdentifierCache[$partialName];

        if ($this->templateCompiler->has($partialIdentifier)) {
            $parsedPartial = $this->templateCompiler->get($partialIdentifier);
        } else {
            $this->templateParser->setConfiguration($this->buildParserConfiguration());
            $parsedPartial = $this->templateParser->parse($this->getPartialSource($partialName));
            if ($parsedPartial->isCompilable()) {
                $this->templateCompiler->store($partialIdentifier, $parsedPartial);
            }
        }

        /** @var $variableContainer TemplateVariableContainer **/
        $variableContainer = $this->objectManager->get(\TYPO3\Fluid\Core\ViewHelper\TemplateVariableContainer::class, $variables);
        $renderingContext = clone $this->getCurrentRenderingContext();
        $renderingContext->injectTemplateVariableContainer($variableContainer);

        $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
        if ($sectionName !== null) {
            $output = $this->renderSection($sectionName, $variables);
        } else {
            $output = $parsedPartial->render($renderingContext);
        }
        $this->stopRendering();

        return $output;
    }
9021
public function bindValues(
        /*# string */ $sql,
        array &$bindings,
        array $settings
    )/*# : string */ {
        // make sure escape function ok
        $this->setEscapeCallable($settings['escapeFunction']);

        // replace each placeholder with corresponding ?/:name/value
        return preg_replace_callback(
            '/\b__PHQUERY_[^_]++__\b/',
            function ($m) use (&$bindings, $settings) {
                return $this->replacePlaceholders($m[0], $bindings, $settings);
            },
            $sql
        );
    }
1126433
private function section($sectionName)
    {
        if (!\array_key_exists($sectionName, $this->sectionList)) {
            throw new TplException(sprintf('section "%s" does not exist', $sectionName));
        }

        return $this->sectionList[$sectionName];
    }
957431
public function addClause(Clause $clause)
    {
        $classname = array_pop(explode('\\', get_class($clause)));
        $this->clauses[$classname] = $clause;

        return $this;
    }
812558
public function buildLimitFragment(SQLSelect $query, array &$parameters)
    {
        $nl = $this->getSeparator();

        // Ensure limit is given
        $limit = $query->getLimit();
        if (empty($limit)) {
            return '';
        }

        // For literal values return this as the limit SQL
        if (!is_array($limit)) {
            return "{$nl}LIMIT $limit";
        }

        // Assert that the array version provides the 'limit' key
        if (!isset($limit['limit']) || !is_numeric($limit['limit'])) {
            throw new InvalidArgumentException(
                'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: ' . var_export($limit, true)
            );
        }

        // Format the array limit, given an optional start key
        $clause = "{$nl}LIMIT {$limit['limit']}";
        if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) {
            $clause .= " OFFSET {$limit['start']}";
        }
        return $clause;
    }