PHP Class JamesMoss\Flywheel\Repository

Analageous to a table in a traditional RDBMS, a repository is a siloed collection where documents live.
Show file Open project: jamesmoss/flywheel Class Usage Examples

Protected Properties

Property Type Description
$documentClass
$formatter
$name
$path
$queryClass

Public Methods

Method Description
__construct ( string $name, Config $config ) Constructor
delete ( mixed $id ) : boolean Delete a document from the repository using its ID.
findAll ( ) : array Returns all the documents within this repo.
findById ( string $id ) : Document | boolean Returns a single document based on it's ID
getAllFiles ( ) : array Get an array containing the path of all files in this repository
getFilename ( string $id ) : string Gets just the filename for a document based on it's ID.
getName ( ) : string Returns the name of this repository
getPath ( ) : string Returns the filesystem path of this repository.
getPathForDocument ( string $id ) : string Get the filesystem path for a document based on it's ID.
query ( ) : Query A factory method that initialises and returns an instance of a Query object.
store ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean Store a Document in the repository.
update ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean Store a Document in the repository, but only if it already exists. The document must have an ID.

Protected Methods

Method Description
generateId ( ) : string Generates a random, unique ID for a document. The result is returned in base62. This keeps it shorted but still human readable if shared in URLs.
getIdFromPath ( string $path, string $ext ) : string Get a document's ID base on its filesystem path
validateId ( string $id ) : boolean Checks to see if a document ID is valid
validateName ( string $name ) : boolean Validates the name of the repo to ensure it can be stored in the filesystem.
write ( string $path, string $contents ) : boolean Writes data to the filesystem.

Method Details

__construct() public method

Constructor
public __construct ( string $name, Config $config )
$name string The name of the repository. Must match /[A-Za-z0-9_-]{1,63}+/
$config Config The config to use for this repo

delete() public method

Delete a document from the repository using its ID.
public delete ( mixed $id ) : boolean
$id mixed The ID of the document (or the document itself) to delete
return boolean True if deleted, false if not.

findAll() public method

Returns all the documents within this repo.
public findAll ( ) : array
return array An array of Documents.

findById() public method

Returns a single document based on it's ID
public findById ( string $id ) : Document | boolean
$id string The ID of the document to find
return Document | boolean The document if it exists, false if not.

generateId() protected method

Generates a random, unique ID for a document. The result is returned in base62. This keeps it shorted but still human readable if shared in URLs.
protected generateId ( ) : string
return string The generated ID.

getAllFiles() public method

Get an array containing the path of all files in this repository
public getAllFiles ( ) : array
return array An array, item is a file

getFilename() public method

Gets just the filename for a document based on it's ID.
public getFilename ( string $id ) : string
$id string The ID of the document.
return string The filename of the document, including extension.

getIdFromPath() protected method

Get a document's ID base on its filesystem path
protected getIdFromPath ( string $path, string $ext ) : string
$path string The full path to the file (including file extension)
$ext string The file extension (without the period)
return string The ID of the document

getName() public method

Returns the name of this repository
public getName ( ) : string
return string The name of the repo

getPath() public method

Returns the filesystem path of this repository.
public getPath ( ) : string
return string The path where documents are stored.

getPathForDocument() public method

Get the filesystem path for a document based on it's ID.
public getPathForDocument ( string $id ) : string
$id string The ID of the document.
return string The full filesystem path of the document.

query() public method

A factory method that initialises and returns an instance of a Query object.
public query ( ) : Query
return Query A new Query class for this repo.

store() public method

Store a Document in the repository.
public store ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean
$document JamesMoss\Flywheel\DocumentInterface The document to store
return boolean True if stored, otherwise false

update() public method

Store a Document in the repository, but only if it already exists. The document must have an ID.
public update ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean
$document JamesMoss\Flywheel\DocumentInterface The document to store
return boolean True if stored, otherwise false

validateId() protected method

Checks to see if a document ID is valid
protected validateId ( string $id ) : boolean
$id string The ID to check
return boolean True if valid, otherwise false

validateName() protected method

Validates the name of the repo to ensure it can be stored in the filesystem.
protected validateName ( string $name ) : boolean
$name string The name to validate against
return boolean Returns true if valid. Throws an exception if not.

write() protected method

Writes data to the filesystem.
protected write ( string $path, string $contents ) : boolean
$path string The absolute file path to write to
$contents string The contents of the file to write
return boolean Returns true if write was successful, false if not.

Property Details

$documentClass protected property

protected $documentClass

$formatter protected property

protected $formatter

$name protected property

protected $name

$path protected property

protected $path

$queryClass protected property

protected $queryClass