Builder

Query builder

 class Winter\Storm\Halcyon\Builder

Properties

public $columns : array | null

The columns that should be returned.

public $extensions : array | null

Filter the query by these file extensions.

public $fileMatch : string | null

Match files using the specified pattern.

public $from : string | null

The directory name which the query is targeting.

public $limit : int | null

The maximum number of records to return.

public $offset : int | null

The number of records to skip.

public $orders : array | null

The orderings for the query.

public $selectSingle : array | null

Query should pluck a single record.

protected $cacheDriver : string | null

The cache driver to be used.

protected $cacheKey : string | null

The key that should be used when caching the query.

protected $cacheMinutes : int | null

The number of minutes to cache the query.

protected $cacheTags : array | null

The tags for the query cache.

protected $datasource : Winter\Storm\Halcyon\Datasource\DatasourceInterface

The datasource instance.

protected $loadedFromCache : bool

Internal variable to specify if the record was loaded from cache.

protected $model : Winter\Storm\Halcyon\Model

The model being queried.

protected $processor : Winter\Storm\Halcyon\Processors\Processor

The datasource query post processor instance.

Methods

public __call (string $method, array $parameters) : void

Handle dynamic method calls into the method.

Parameters
Property Description
$method
string
$parameters
array
Returns
void

public __construct (Winter\Storm\Halcyon\Datasource\DatasourceInterface $datasource, Winter\Storm\Halcyon\Processors\Processor $processor) : void

Create a new query builder instance.

Parameters
Property Description
$datasource
Winter\Storm\Halcyon\Datasource\DatasourceInterface
$processor
Winter\Storm\Halcyon\Processors\Processor
Returns
void

public cacheDriver (string $cacheDriver) : $this

Indicate that the results, if cached, should use the given cache driver.

Parameters
Property Description
$cacheDriver
string
Returns
$this

public cacheTags (array | mixed $cacheTags) : $this

Indicate that the results, if cached, should use the given cache tags.

Parameters
Property Description
$cacheTags
array | mixed
Returns
$this

public static clearInternalCache ()

Clears the internal request-level object cache.

Returns
mixed

public delete () : bool

Delete a record from the database.

Returns
bool

public find (string $fileName) : mixed | static

Find a single template by its file name.

Parameters
Property Description
$fileName
string
Returns
mixed | static

public first () : mixed | static

Execute the query and get the first result.

Returns
mixed | static

public from (string $dirName) : $this

Set the directory name which the query is targeting.

Parameters
Property Description
$dirName
string
Returns
$this

public generateCacheKey () : string

Generate the unique cache key for the query.

Returns
string

public get (array $columns = ["*"]) : Winter\Storm\Halcyon\Collection

Execute the query as a "select" statement.

Parameters
Property Description
$columns
array
Returns

public getCacheKey () : string

Get a unique cache key for the complete query.

Returns
string

public getCached (array $columns = ["*"]) : array

Execute the query as a cached "select" statement.

Parameters
Property Description
$columns
array
Returns
array

public getFresh (array $columns = ["*"]) : Winter\Storm\Halcyon\Collection | static[]

Execute the query as a fresh "select" statement.

Parameters
Property Description
$columns
array
Returns

public getModel () : Winter\Storm\Halcyon\Model

Get the model instance being queried.

Returns

public getModels (array $results) : \Winter\Storm\Halcyon\Model[]

Get the hydrated models.

Parameters
Property Description
$results
array
Returns
\Winter\Storm\Halcyon\Model[]

public insert (array $values) : integer

Insert a new record into the datasource.

Parameters
Property Description
$values
array

The values to store in the model.

Returns
integer

The filesize of the created model file.

public lastModified () : int

Returns the last modified time of the object.

Returns
int

public limit (int $value) : $this

Set the "limit" value of the query.

Parameters
Property Description
$value
int
Returns
$this

public lists (string $column, string $key = null) : array

Get an array with the values of a given column.

Parameters
Property Description
$column
string
$key
string
Returns
array

public offset (int $value) : $this

Set the "offset" value of the query.

Parameters
Property Description
$value
int
Returns
$this

public remember (DateTime | int $minutes, string $key = null) : $this

Indicate that the query results should be cached.

Parameters
Property Description
$minutes
DateTime | int
$key
string
Returns
$this

public rememberForever (string $key = null) : $this

Indicate that the query results should be cached forever.

Parameters
Property Description
$key
string
Returns
$this

public setModel (Winter\Storm\Halcyon\Model $model) : $this

Set a model instance for the model being queried.

Parameters
Property Description
$model
Winter\Storm\Halcyon\Model
Returns
$this

public skip (int $value) : Winter\Storm\Halcyon\Builder | static

Alias to set the "offset" value of the query.

Parameters
Property Description
$value
int
Returns

public take (int $value) : Winter\Storm\Halcyon\Builder | static

Alias to set the "limit" value of the query.

Parameters
Property Description
$value
int
Returns

public toCompiled () : string

Get the compiled file content representation of the query.

Returns
string

public update (array $values = []) : integer

Update a record in the datasource.

Parameters
Property Description
$values
array

The values to store in the model.

Returns
integer

The filesize of the created model file.

public whereFileName (string $fileName) : $this

Switches mode to select a single template by its name.

Parameters
Property Description
$fileName
string
Returns
$this

protected getCache () : Illuminate\Contracts\Cache\Repository

Get the cache object with tags assigned, if applicable.

Returns
Illuminate\Contracts\Cache\Repository

protected getCacheCallback (string | array $columns) : Closure

Get the Closure callback used when caching queries.

Parameters
Property Description
$columns
string | array
Returns
Closure

protected isCacheBusted (array $result) : bool

Returns true if the cache for the file is busted. This only applies to single record selection.

Parameters
Property Description
$result
array
Returns
bool

protected processInitCacheData (Winter\Storm\Halcyon\Collection | array $data) : Winter\Storm\Halcyon\Collection | array

Initialize the cache data of each record.

Parameters
Property Description
$data
Returns

protected runSelect () : array

Run the query as a "select" statement against the datasource.

Returns
array

protected validateFileName (string $fileName = null)

Validate the supplied filename, extension and path.

Parameters
Property Description
$fileName
string
Returns
mixed

protected validateFileNameExtension (string $fileName, array $allowedExtensions) : void

Validates whether a file has an allowed extension.

Parameters
Property Description
$fileName
string

Specifies a path to validate

$allowedExtensions
array

A list of allowed file extensions

Returns
void

protected validateFileNamePath (string $filePath, integer $maxNesting = 2) : bool

Validates a template path.

Template directory and file names can contain only alphanumeric symbols, dashes and dots.

Parameters
Property Description
$filePath
string

Specifies a path to validate

$maxNesting
integer

Specifies the maximum allowed nesting level

Returns
bool

protected validateFileNamePattern (string $fileName) : bool

Validates a template file or directory name.

template file names can contain only alphanumeric symbols, dashes, underscores and dots.

Parameters
Property Description
$fileName
string

Specifies a path to validate

Returns
bool

Returns true if the file name is valid. Otherwise returns false.

Copyright © 2024 Winter CMS