PHP Класс JamesMoss\Flywheel\Repository

Analageous to a table in a traditional RDBMS, a repository is a siloed collection where documents live.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$documentClass
$formatter
$name
$path
$queryClass

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

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
Результат boolean True if deleted, false if not.

findAll() публичный Метод

Returns all the documents within this repo.
public findAll ( ) : array
Результат array An array of Documents.

findById() публичный Метод

Returns a single document based on it's ID
public findById ( string $id ) : Document | boolean
$id string The ID of the document to find
Результат Document | boolean The document if it exists, false if not.

generateId() защищенный Метод

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
Результат string The generated ID.

getAllFiles() публичный Метод

Get an array containing the path of all files in this repository
public getAllFiles ( ) : array
Результат array An array, item is a file

getFilename() публичный Метод

Gets just the filename for a document based on it's ID.
public getFilename ( string $id ) : string
$id string The ID of the document.
Результат string The filename of the document, including extension.

getIdFromPath() защищенный Метод

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)
Результат string The ID of the document

getName() публичный Метод

Returns the name of this repository
public getName ( ) : string
Результат string The name of the repo

getPath() публичный Метод

Returns the filesystem path of this repository.
public getPath ( ) : string
Результат string The path where documents are stored.

getPathForDocument() публичный Метод

Get the filesystem path for a document based on it's ID.
public getPathForDocument ( string $id ) : string
$id string The ID of the document.
Результат string The full filesystem path of the document.

query() публичный Метод

A factory method that initialises and returns an instance of a Query object.
public query ( ) : Query
Результат Query A new Query class for this repo.

store() публичный Метод

Store a Document in the repository.
public store ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean
$document JamesMoss\Flywheel\DocumentInterface The document to store
Результат boolean True if stored, otherwise false

update() публичный Метод

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
Результат boolean True if stored, otherwise false

validateId() защищенный Метод

Checks to see if a document ID is valid
protected validateId ( string $id ) : boolean
$id string The ID to check
Результат boolean True if valid, otherwise false

validateName() защищенный Метод

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
Результат boolean Returns true if valid. Throws an exception if not.

write() защищенный Метод

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
Результат boolean Returns true if write was successful, false if not.

Описание свойств

$documentClass защищенное свойство

protected $documentClass

$formatter защищенное свойство

protected $formatter

$name защищенное свойство

protected $name

$path защищенное свойство

protected $path

$queryClass защищенное свойство

protected $queryClass