PHP Class JamesMoss\Flywheel\Repository

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

Protected Properties

Свойство Type Description
$documentClass
$formatter
$name
$path
$queryClass

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

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
Résultat boolean True if deleted, false if not.

findAll() public méthode

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

findById() public méthode

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

generateId() protected méthode

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
Résultat string The generated ID.

getAllFiles() public méthode

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

getFilename() public méthode

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

getIdFromPath() protected méthode

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)
Résultat string The ID of the document

getName() public méthode

Returns the name of this repository
public getName ( ) : string
Résultat string The name of the repo

getPath() public méthode

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

getPathForDocument() public méthode

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

query() public méthode

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

store() public méthode

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

update() public méthode

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
Résultat boolean True if stored, otherwise false

validateId() protected méthode

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

validateName() protected méthode

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
Résultat boolean Returns true if valid. Throws an exception if not.

write() protected méthode

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
Résultat boolean Returns true if write was successful, false if not.

Property Details

$documentClass protected_oe property

protected $documentClass

$formatter protected_oe property

protected $formatter

$name protected_oe property

protected $name

$path protected_oe property

protected $path

$queryClass protected_oe property

protected $queryClass