Cms\Classes\AutoDatasource

Source: ~/modules/cms/classes/AutoDatasource.php

Extends:

Implements:

Datasource that loads from other data sources automatically

Public properties

public string $activeDatasourceKey

The key for the datasource to perform CRUD operations on

Protected properties

protected array $datasources

The available datasource instances

protected array $pathCache

Local cache of paths available in the datasources

protected boolean $allowCacheRefreshes

Flag on whether the cache should respect refresh requests

Show inherited protected properties

Inherited protected properties

Public methods

public void __construct(array $datasources)

Create a new datasource instance.

Parameters
  • array $datasources - Array of datasources to utilize. Lower indexes = higher priority ['datasourceName' => $datasource]

public int delete(string $dirName, string $fileName, string $extension)

Run a delete statement against the datasource, only runs delete on active datasource

Parameters
  • string $dirName
  • string $fileName
  • string $extension

public array getAvailablePaths()

Get all available paths within this datastore

public string getPathsCacheKey()

Generate a paths cache key unique to this datasource

public void getSourcePaths(string $source)

Get the available paths for the specified datasource key

Parameters
  • string $source - The string key of the datasource to check

public bool insert(string $dirName, string $fileName, string $extension, string $content)

Creates a new template, only inserts to the active datasource

Parameters
  • string $dirName
  • string $fileName
  • string $extension
  • string $content

public int lastModified(string $dirName, string $fileName, string $extension)

Return the last modified date of an object

Parameters
  • string $dirName
  • string $fileName
  • string $extension

public string makeCacheKey(string $name='')

Generate a cache key unique to this datasource.

Parameters
  • string $name

public void pushToSource(Model $model, string $source)

Push the provided model to the specified datasource

Parameters
  • Model $model - The Halcyon Model to push
  • string $source - The string key of the datasource to use

public void removeFromSource(Model $model, string $source)

Remove the provided model from the specified datasource

Parameters
  • Model $model - The Halcyon model to remove
  • string $source - The string key of the datasource to use

public array select(string $dirName, array $options=array())

Returns all templates.

Parameters
  • string $dirName
  • array $options - 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 ];

public mixed selectOne(string $dirName, string $fileName, string $extension)

Returns a single template.

Parameters
  • string $dirName
  • string $fileName
  • string $extension

public boolean sourceHasModel(string $source, Model $model)

Check to see if the specified datasource has the provided Halcyon Model

Parameters
  • string $source - The string key of the datasource to check
  • Model $model - The Halcyon Model to check for

public int update(string $dirName, string $fileName, string $extension, string $content, string $oldFileName=NULL, string $oldExtension=NULL)

Updates an existing template.

Parameters
  • string $dirName
  • string $fileName
  • string $extension
  • string $content
  • string $oldFileName - Defaults to null
  • string $oldExtension - Defaults to null

Show inherited public methods

Inherited public methods

Protected methods

protected DatasourceInterface getActiveDatasource()

Get the datasource for use with CRUD operations

protected Datasource getDatasourceForPath(string $path)

Get the appropriate datasource for the provided path

Parameters
  • string $path

protected array getValidPaths(string $dirName, array $options=array())

Get all valid paths for the provided directory, removing any paths marked as deleted

Parameters
  • string $dirName
  • array $options - 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 ];

protected string makeFilePath(string $dirName, string $fileName, string $extension)

Helper to make file path.

Parameters
  • string $dirName
  • string $fileName
  • string $extension

protected void populateCache(boolean $refresh=false)

Populate the local cache of paths available in each datasource

Parameters
  • boolean $refresh - Default false, set to true to force the cache to be rebuilt

Show inherited protected methods

Inherited protected methods