ContentQueryParser
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
Constructor.
Internal method to initialise the default handlers.
Sets the input query.
Sets the input parameters to handle.
Sets a single input parameter.
Parse a query.
Parses the content area of the query string.
Internal method that takes the 'query' part of the input and parses it into one of the various operations supported.
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'.
This runs the callbacks attached to each directive command.
Gets the content repository.
No description
Returns the parsed content types.
Returns the parsed operation.
Returns the parsed identifier.
Returns a directive from the parsed list.
Sets a directive for the named key.
Returns the handler for the named directive.
Returns boolean for existence of handler.
Adds a handler for the named directive.
Adds a handler AND operation for the named operation.
Returns a handler for the named operation.
Returns a service for the named operation.
Returns the current parameters.
Helper method to check if parameters are set for a specific key.
Returns a single named parameter.
Runs the query and fetches the results.
Getter to return the currently registered operations.
Adds a new operation to the list supported.
Removes an operation from the list supported.
No description
Details
__construct(RequestStack $requestStack, ContentRepository $repo, Config $config, LocaleHelper $localeHelper, Environment $twig, Notifications $notifications, Version $version, QueryInterface|null $queryHandler = null)
Constructor.
protected 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.
protected void
parseContent()
Parses the content area of the query string.
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.
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.
void
runDirectives(QueryInterface $query, array $skipDirective = [])
This runs the callbacks attached to each directive command.
void
setScope(QueryScopeInterface $scope)
void
runScopes(QueryInterface $query)
ContentRepository
getContentRepository()
Gets the content repository.
void
setContentTypes(array $contentTypes)
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.
QueryInterface
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.