AutoDatasource
extends Datasource
in package
implements
DatasourceInterface
Datasource that loads from other data sources automatically
Tags
Interfaces, Classes and Traits
Table of Contents
- $activeDatasourceKey : string
- $allowCacheRefreshes : bool
- $datasources : array<string|int, mixed>
- $emitterEventCollection : array<string|int, mixed>
- $emitterEventSorted : array<string|int, mixed>
- $emitterSingleEventCollection : array<string|int, mixed>
- $forceDeleting : bool
- $pathCache : array<string|int, mixed>
- $postProcessor : Processor
- The query post processor implementation.
- $singleDatasourceMode : bool
- __construct() : void
- Create a new datasource instance.
- bindEvent() : self
- Create a new event binding.
- bindEventOnce() : self
- Create a new event binding that fires once only
- delete() : int
- Run a delete statement against the datasource, only runs delete on active datasource
- fireEvent() : array<string|int, mixed>
- Fire an event and call the listeners.
- forceDelete() : void
- Force the deletion of a record against the datasource
- getAvailablePaths() : array<string|int, mixed>
- Get all available paths within this datastore
- getPathsCacheKey() : string
- Generate a paths cache key unique to this datasource
- getPostProcessor() : Processor
- Get the query post processor used by the connection.
- getSourcePaths() : void
- Get the available paths for the specified datasource key
- insert() : bool
- Creates a new template, only inserts to the active datasource
- lastModified() : int
- Return the last modified date of an object
- makeCacheKey() : string
- Generate a cache key unique to this datasource.
- pushToSource() : void
- Push the provided model to the specified datasource
- removeFromSource() : void
- Remove the provided model from the specified datasource
- select() : array<string|int, mixed>
- Returns all templates.
- selectOne() : mixed
- Returns a single template.
- sourceHasModel() : bool
- Check to see if the specified datasource has the provided Halcyon Model
- unbindEvent() : self
- Destroys an event binding.
- update() : int
- Updates an existing template.
- usingSource() : mixed
- Forces all operations in a provided closure to run within a selected datasource.
- emitterEventSortEvents() : array<string|int, mixed>
- Sort the listeners for a given event by priority.
- getActiveDatasource() : DatasourceInterface
- Get the datasource for use with CRUD operations
- getDatasourceForPath() : Datasource
- Get the appropriate datasource for the provided path
- getValidPaths() : array<string|int, mixed>
- Get all valid paths for the provided directory, removing any paths marked as deleted
- makeFilePath() : string
- Helper to make file path.
- populateCache() : void
- Populate the local cache of paths available in each datasource
Properties
$activeDatasourceKey
public
string
$activeDatasourceKey
= ''
The key for the datasource to perform CRUD operations on
$allowCacheRefreshes
protected
bool
$allowCacheRefreshes
= true
Flag on whether the cache should respect refresh requests
$datasources
protected
array<string|int, mixed>
$datasources
= []
The available datasource instances
$emitterEventCollection
protected
array<string|int, mixed>
$emitterEventCollection
= []
Collection of registered events.
$emitterEventSorted
protected
array<string|int, mixed>
$emitterEventSorted
= []
Sorted collection of events.
$emitterSingleEventCollection
protected
array<string|int, mixed>
$emitterSingleEventCollection
= []
Collection of registered events to be fired once only.
$forceDeleting
protected
bool
$forceDeleting
= false
Indicates if the record is currently being force deleted.
$pathCache
protected
array<string|int, mixed>
$pathCache
= []
Local cache of paths available in the datasources
$postProcessor
The query post processor implementation.
protected
Processor
$postProcessor
$singleDatasourceMode
protected
bool
$singleDatasourceMode
= false
Flag to indicate that we're in "single datasource mode"
Methods
__construct()
Create a new datasource instance.
public
__construct(array<string|int, mixed> $datasources) : void
Parameters
- $datasources : array<string|int, mixed>
-
Array of datasources to utilize. Lower indexes = higher priority ['datasourceName' => $datasource]
Return values
void —bindEvent()
Create a new event binding.
public
bindEvent(mixed $event, mixed $callback, mixed $priority) : self
Parameters
- $event : mixed
- $callback : mixed
- $priority : mixed
Return values
self —bindEventOnce()
Create a new event binding that fires once only
public
bindEventOnce(mixed $event, mixed $callback) : self
Parameters
- $event : mixed
- $callback : mixed
Return values
self —delete()
Run a delete statement against the datasource, only runs delete on active datasource
public
delete(string $dirName, string $fileName, string $extension) : int
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
int —fireEvent()
Fire an event and call the listeners.
public
fireEvent(string $event[, array<string|int, mixed> $params = [] ][, bool $halt = false ]) : array<string|int, mixed>
Parameters
- $event : string
-
Event name
- $params : array<string|int, mixed> = []
-
Event parameters
- $halt : bool = false
-
Halt after first non-null result
Return values
array<string|int, mixed> —Collection of event results / Or single result (if halted)
forceDelete()
Force the deletion of a record against the datasource
public
forceDelete(string $dirName, string $fileName, string $extension) : void
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
void —getAvailablePaths()
Get all available paths within this datastore
public
getAvailablePaths() : array<string|int, mixed>
Return values
array<string|int, mixed> —$paths ['path/to/file1.md' => true (path can be handled and exists), 'path/to/file2.md' => false (path can be handled but doesn't exist)]
getPathsCacheKey()
Generate a paths cache key unique to this datasource
public
getPathsCacheKey() : string
Return values
string —getPostProcessor()
Get the query post processor used by the connection.
public
getPostProcessor() : Processor
Return values
Processor —getSourcePaths()
Get the available paths for the specified datasource key
public
getSourcePaths(string $source) : void
Parameters
- $source : string
-
The string key of the datasource to check
Return values
void —insert()
Creates a new template, only inserts to the active datasource
public
insert(string $dirName, string $fileName, string $extension, string $content) : bool
Parameters
- $dirName : string
- $fileName : string
- $extension : string
- $content : string
Return values
bool —lastModified()
Return the last modified date of an object
public
lastModified(string $dirName, string $fileName, string $extension) : int
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
int —makeCacheKey()
Generate a cache key unique to this datasource.
public
makeCacheKey([string $name = '' ]) : string
Parameters
- $name : string = ''
Return values
string —pushToSource()
Push the provided model to the specified datasource
public
pushToSource(Model $model, string $source) : void
Parameters
- $model : Model
-
The Halcyon Model to push
- $source : string
-
The string key of the datasource to use
Return values
void —removeFromSource()
Remove the provided model from the specified datasource
public
removeFromSource(Model $model, string $source) : void
Parameters
- $model : Model
-
The Halcyon model to remove
- $source : string
-
The string key of the datasource to use
Return values
void —select()
Returns all templates.
public
select(string $dirName[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $dirName : string
- $options : array<string|int, mixed> = []
-
Array of options, [ 'columns' => ['fileName', 'mtime', 'content'], // Only return specific columns 'extensions' => ['htm', 'md', 'twig'], // Extensions to search for 'fileMatch' => '*gr[ae]y', // Shell matching pattern to match the filename against using the fnmatch function 'orders' => false // Not implemented 'limit' => false // Not implemented 'offset' => false // Not implemented ];
Return values
array<string|int, mixed> —selectOne()
Returns a single template.
public
selectOne(string $dirName, string $fileName, string $extension) : mixed
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
mixed —sourceHasModel()
Check to see if the specified datasource has the provided Halcyon Model
public
sourceHasModel(string $source, Model $model) : bool
Parameters
- $source : string
-
The string key of the datasource to check
- $model : Model
-
The Halcyon Model to check for
Return values
bool —unbindEvent()
Destroys an event binding.
public
unbindEvent([string $event = null ]) : self
Parameters
- $event : string = null
-
Event to destroy
Return values
self —update()
Updates an existing template.
public
update(string $dirName, string $fileName, string $extension, string $content[, string $oldFileName = null ][, string $oldExtension = null ]) : int
Parameters
- $dirName : string
- $fileName : string
- $extension : string
- $content : string
- $oldFileName : string = null
-
Defaults to null
- $oldExtension : string = null
-
Defaults to null
Return values
int —usingSource()
Forces all operations in a provided closure to run within a selected datasource.
public
usingSource(string $source, Closure $closure) : mixed
Parameters
- $source : string
- $closure : Closure
Return values
mixed —emitterEventSortEvents()
Sort the listeners for a given event by priority.
protected
emitterEventSortEvents(string $eventName) : array<string|int, mixed>
Parameters
- $eventName : string
Return values
array<string|int, mixed> —getActiveDatasource()
Get the datasource for use with CRUD operations
protected
getActiveDatasource() : DatasourceInterface
Return values
DatasourceInterface —getDatasourceForPath()
Get the appropriate datasource for the provided path
protected
getDatasourceForPath(string $path) : Datasource
Parameters
- $path : string
Return values
Datasource —getValidPaths()
Get all valid paths for the provided directory, removing any paths marked as deleted
protected
getValidPaths(string $dirName[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $dirName : string
- $options : array<string|int, mixed> = []
-
Array of options, [ 'extensions' => ['htm', 'md', 'twig'], // Extensions to search for 'fileMatch' => '*gr[ae]y', // Shell matching pattern to match the filename against using the fnmatch function ];
Return values
array<string|int, mixed> —$paths ["$dirName/path/1.md", "$dirName/path/2.md"]
makeFilePath()
Helper to make file path.
protected
makeFilePath(string $dirName, string $fileName, string $extension) : string
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
string —populateCache()
Populate the local cache of paths available in each datasource
protected
populateCache([bool $refresh = false ]) : void
Parameters
- $refresh : bool = false
-
Default false, set to true to force the cache to be rebuilt