FileDatasource
extends Datasource
in package
implements
DatasourceInterface
File based datasource.
Interfaces, Classes and Traits
Table of Contents
- $basePath : string
- The local path where the datasource can be found.
- $emitterEventCollection : array<string|int, mixed>
- $emitterEventSorted : array<string|int, mixed>
- $emitterSingleEventCollection : array<string|int, mixed>
- $files : Filesystem
- The filesystem instance.
- $forceDeleting : bool
- $postProcessor : Processor
- The query post processor implementation.
- __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() : bool
- Run a delete statement against the 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
- getBasePath() : string
- Returns the base path for this datasource.
- getPathsCacheKey() : string
- Generate a paths cache key unique to this datasource
- getPostProcessor() : Processor
- Get the query post processor used by the connection.
- insert() : bool
- Creates a new template.
- lastModified() : int
- Run a delete statement against the datasource.
- makeCacheKey() : string
- Generate a cache key unique to this datasource.
- select() : array<string|int, mixed>
- Returns all templates.
- selectOne() : mixed
- Returns a single template.
- unbindEvent() : self
- Destroys an event binding.
- update() : int
- Updates an existing template.
- emitterEventSortEvents() : array<string|int, mixed>
- Sort the listeners for a given event by priority.
- makeFilePath() : string
- Helper to make file path.
- validateDirectoryForSave() : void
- Ensure the requested file can be created in the requested directory.
Properties
$basePath
The local path where the datasource can be found.
protected
string
$basePath
$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.
$files
The filesystem instance.
protected
Filesystem
$files
$forceDeleting
protected
bool
$forceDeleting
= false
Indicates if the record is currently being force deleted.
$postProcessor
The query post processor implementation.
protected
Processor
$postProcessor
Methods
__construct()
Create a new datasource instance.
public
__construct(string $basePath, Filesystem $files) : void
Parameters
- $basePath : string
- $files : Filesystem
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.
public
delete(string $dirName, string $fileName, string $extension) : bool
Parameters
- $dirName : string
- $fileName : string
- $extension : string
Return values
bool —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)]
getBasePath()
Returns the base path for this datasource.
public
getBasePath() : string
Return values
string —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 —insert()
Creates a new template.
public
insert(string $dirName, string $fileName, string $extension, string $content) : bool
Parameters
- $dirName : string
- $fileName : string
- $extension : string
- $content : string
Return values
bool —lastModified()
Run a delete statement against the datasource.
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 —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 —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 —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> —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 —validateDirectoryForSave()
Ensure the requested file can be created in the requested directory.
protected
validateDirectoryForSave(string $dirName, string $fileName, string $extension) : void
Parameters
- $dirName : string
- $fileName : string
- $extension : string