src/mako/database/query/compilers/Compiler.php
protected function subquery(Subquery $subquery, bool $enclose = true): string
	{
		$query = $subquery->getQuery();

		if($query instanceof Closure)
		{
			$builder = $query;

			$query = $this->query->newInstance()->inSubqueryContext();

			$builder($query);
		}

		$query = $query->getCompiler()->select();

		$this->params = array_merge($this->params, $query['params']);

		if($enclose)
		{
			$query['sql'] = '(' . $query['sql'] . ')';
		}

		if(($alias = $subquery->getAlias()) !== null)
		{
			$query['sql'] .= ' AS ' . $this->escapeIdentifier($alias);
		}

		return $query['sql'];
	}
protected function subquery(Subquery $subquery, bool $enclose = true): string
	{
		$query = $subquery->getQuery();

		if($query instanceof Closure)
		{
			$builder = $query;

			$query = $this->query->newInstance()->inSubqueryContext();

			$builder($query);
		}

		$query = $query->getCompiler()->select();

		$this->params = array_merge($this->params, $query['params']);

		if($enclose)
		{
			$query['sql'] = '(' . $query['sql'] . ')';
		}

		if(($alias = $subquery->getAlias()) !== null)
		{
			$query['sql'] .= ' AS ' . $this->escapeIdentifier($alias);
		}

		return $query['sql'];
	}
protected function subquery ( Subquery $ subquery , bool $ enclose = true ) : string { $ query = $ subquery -> getQuery ( ) ; if ( $ query instanceof Closure ) { $ builder = $ query ; $ query = $ this -> query -> newInstance ( ) -> inSubqueryContext ( ) ; $ builder ( $ query ) ; } $ query = $ query -> getCompiler ( ) -> select ( ) ; $ this -> params = array_merge ( $ this -> params , $ query [ 'params' ] ) ; if ( $ enclose ) { $ query [ 'sql' ] = '(' . $ query [ 'sql' ] . ')' ; } if ( ( $ alias = $ subquery -> getAlias ( ) ) !== null ) { $ query [ 'sql' ] .= ' AS ' . $ this -> escapeIdentifier ( $ alias ) ; } return $ query [ 'sql' ] ; }
Compiles subquery, merges parameters and returns subquery SQL.

@param  \mako\database\query\Subquery $subquery Subquery container
@param  bool                          $enclose  Should the subquery be enclosed in parentheses?
@return string
Compiles subquery merges parameters and returns subquery SQL .