class ContentQueryParser (View source)

Handler class to convert the DSL for content queries into an object representation.

Properties

protected ContentRepository $repo
protected string $query
protected array $params
protected array $contentTypes
protected string $operation
protected string $identifier
protected array $operations
protected array $directives
protected callable[] $directiveHandlers
protected callable[] $handlers
protected QueryInterface[] $services
protected QueryScopeInterface $scope

Methods

__construct(RequestStack $requestStack, ContentRepository $repo, Config $config, LocaleHelper $localeHelper, Environment $twig, Notifications $notifications, Version $version, QueryInterface|null $queryHandler = null)

Constructor.

void
setupDefaults()

Internal method to initialise the default handlers.

void
setQuery(string $query)

Sets the input query.

void
setParameters(array $params)

Sets the input parameters to handle.

void
setParameter($param, $value)

Sets a single input parameter.

void
parse()

Parse a query.

void
parseContent()

Parses the content area of the query string.

void
parseOperation()

Internal method that takes the 'query' part of the input and parses it into one of the various operations supported.

void
parseDirectives()

Directives are all of the other parameters supported by Bolt that do not relate to an actual filter query. Some examples include 'printquery', 'limit', 'order' or 'returnsingle'.

void
runDirectives(QueryInterface $query, array $skipDirective = [])

This runs the callbacks attached to each directive command.

void
setScope(QueryScopeInterface $scope)

No description

void
runScopes(QueryInterface $query)

No description

getContentRepository()

Gets the content repository.

void
setContentTypes(array $contentTypes)

No description

array
getContentTypes()

Returns the parsed content types.

string
getOperation()

Returns the parsed operation.

string
getIdentifier()

Returns the parsed identifier.

getDirective(string|int|bool|null $key)

Returns a directive from the parsed list.

void
setDirective(string $key, $value)

Sets a directive for the named key.

callable
getDirectiveHandler(string $key)

Returns the handler for the named directive.

bool
hasDirectiveHandler(string $key)

Returns boolean for existence of handler.

void
addDirectiveHandler(string $key, callable|null $callback = null)

Adds a handler for the named directive.

void
addHandler(string $operation, callable $callback)

Adds a handler AND operation for the named operation.

callable
getHandler(string $operation)

Returns a handler for the named operation.

void
addService(string $operation, QueryInterface $service)

Adds a service for the named operation.

getService(string $operation)

Returns a service for the named operation.

array
getParameters()

Returns the current parameters.

bool
hasParameter(string $param)

Helper method to check if parameters are set for a specific key.

array
getParameter(string $param)

Returns a single named parameter.

Pagerfanta|Content|null
fetch()

Runs the query and fetches the results.

array
getOperations()

Getter to return the currently registered operations.

void
addOperation(string $operation)

Adds a new operation to the list supported.

void
removeOperation(string $operation)

Removes an operation from the list supported.

Request|null
getRequest()

No description

Details

__construct(RequestStack $requestStack, ContentRepository $repo, Config $config, LocaleHelper $localeHelper, Environment $twig, Notifications $notifications, Version $version, QueryInterface|null $queryHandler = null)

Constructor.

Parameters

RequestStack $requestStack
ContentRepository $repo
Config $config
LocaleHelper $localeHelper
Environment $twig
Notifications $notifications
Version $version
QueryInterface|null $queryHandler

protected void setupDefaults()

Internal method to initialise the default handlers.

Return Value

void

void setQuery(string $query)

Sets the input query.

Parameters

string $query

Return Value

void

void setParameters(array $params)

Sets the input parameters to handle.

Parameters

array $params

Return Value

void

void setParameter($param, $value)

Sets a single input parameter.

Parameters

$param
$value

Return Value

void

void parse()

Parse a query.

Return Value

void

protected void parseContent()

Parses the content area of the query string.

Return Value

void

protected void parseOperation()

Internal method that takes the 'query' part of the input and parses it into one of the various operations supported.

A simple select operation will just contain the ContentType eg 'pages' but additional operations can be triggered using the '/' separator.

Return Value

void

protected void parseDirectives()

Directives are all of the other parameters supported by Bolt that do not relate to an actual filter query. Some examples include 'printquery', 'limit', 'order' or 'returnsingle'.

All these need to parsed and taken out of the params that are sent to the query.

Return Value

void

void runDirectives(QueryInterface $query, array $skipDirective = [])

This runs the callbacks attached to each directive command.

Parameters

QueryInterface $query
array $skipDirective

Return Value

void

void setScope(QueryScopeInterface $scope)

Parameters

QueryScopeInterface $scope

Return Value

void

void runScopes(QueryInterface $query)

Parameters

QueryInterface $query

Return Value

void

ContentRepository getContentRepository()

Gets the content repository.

Return Value

ContentRepository

void setContentTypes(array $contentTypes)

Parameters

array $contentTypes

Return Value

void

array getContentTypes()

Returns the parsed content types.

Return Value

array

string getOperation()

Returns the parsed operation.

Return Value

string

string getIdentifier()

Returns the parsed identifier.

Return Value

string

getDirective(string|int|bool|null $key)

Returns a directive from the parsed list.

Parameters

string|int|bool|null $key

void setDirective(string $key, $value)

Sets a directive for the named key.

Parameters

string $key
$value

Return Value

void

callable getDirectiveHandler(string $key)

Returns the handler for the named directive.

Parameters

string $key

Return Value

callable

bool hasDirectiveHandler(string $key)

Returns boolean for existence of handler.

Parameters

string $key

Return Value

bool

void addDirectiveHandler(string $key, callable|null $callback = null)

Adds a handler for the named directive.

Parameters

string $key
callable|null $callback

Return Value

void

void addHandler(string $operation, callable $callback)

Adds a handler AND operation for the named operation.

Parameters

string $operation
callable $callback

Return Value

void

callable getHandler(string $operation)

Returns a handler for the named operation.

Parameters

string $operation

Return Value

callable

void addService(string $operation, QueryInterface $service)

Adds a service for the named operation.

Parameters

string $operation
QueryInterface $service

Return Value

void

QueryInterface getService(string $operation)

Returns a service for the named operation.

Parameters

string $operation

Return Value

QueryInterface

array getParameters()

Returns the current parameters.

Return Value

array

bool hasParameter(string $param)

Helper method to check if parameters are set for a specific key.

Parameters

string $param

Return Value

bool

array getParameter(string $param)

Returns a single named parameter.

Parameters

string $param

Return Value

array

Pagerfanta|Content|null fetch()

Runs the query and fetches the results.

Return Value

Pagerfanta|Content|null

array getOperations()

Getter to return the currently registered operations.

Return Value

array

void addOperation(string $operation)

Adds a new operation to the list supported.

Parameters

string $operation name of operation to parse for

Return Value

void

void removeOperation(string $operation)

Removes an operation from the list supported.

Parameters

string $operation name of operation to remove

Return Value

void

Request|null getRequest()

Return Value

Request|null