PHP Class Puli\Repository\AbstractJsonRepository

The generated JSON file is described by res/schema/repository-schema-1.0.json.
Since: 1.0
Author: Bernhard Schussek ([email protected])
Author: Titouan Galopin ([email protected])
Inheritance: extends AbstractEditableRepository, implements Psr\Log\LoggerAwareInterface
Afficher le fichier Open project: puli/repository Class Usage Examples

Protected Properties

Свойство Type Description
$baseDirectory string
$json array

Méthodes publiques

Méthode Description
__construct ( string $path, string $baseDirectory, boolean $validateJson = false, Puli\Repository\Api\ChangeStream\ChangeStream $changeStream = null ) Creates a new repository.
add ( $path, $resource )
clear ( )
contains ( $query, $language = 'glob' )
find ( $query, $language = 'glob' )
get ( $path )
hasChildren ( $path )
listChildren ( $path )
remove ( $query, $language = 'glob' )
setLogger ( Psr\Log\LoggerInterface $logger = null )

Méthodes protégées

Méthode Description
addFilesystemResource ( string $path, Puli\Repository\Api\Resource\FilesystemResource $resource ) Adds a filesystem resource to the JSON file.
createResource ( string $path, string | null $reference ) : Puli\Repository\Api\Resource\PuliResource Turns a reference into a resource.
flush ( ) Writes the JSON file.
getReferencesForGlob ( string $glob, integer $flags ) : string[] | null[] Returns the references matching a given Puli path glob.
getReferencesForPath ( string $path ) : string[] | null[] Returns the references for a given Puli path.
getReferencesForRegex ( string $staticPrefix, string $regex, integer $flags ) : string[] | null[] Returns the references matching a given Puli path regular expression.
getReferencesInDirectory ( string $path, integer $flags ) : string[] | null[] Returns the references in a given Puli path.
insertReference ( string $path, string | null $reference ) Inserts a path reference into the JSON file.
isFilesystemReference ( string $reference ) : boolean Returns whether a reference contains an absolute or relative filesystem path.
isLinkReference ( string $reference ) : boolean Returns whether a reference contains a link.
load ( ) Loads the JSON file.
log ( mixed $level, string $message ) Logs a message.
logReferenceNotFound ( string $path, string $reference, string $absoluteReference ) Logs a warning that a reference could not be found.
removeReferences ( string $glob ) Removes all path references matching the given glob from the JSON file.

Private Methods

Méthode Description
addResource ( string $path, Puli\Repository\Api\Resource\FilesystemResource | LinkResource $resource ) Adds a resource to the repository.
createResources ( array $references ) : array Turns a list of references into a list of resources.
ensureDirectoryExists ( string $path ) Adds all ancestor directories of a path to the repository.
getShortClassName ( string $className ) : string Returns the short name of a fully-qualified class name.

Method Details

__construct() public méthode

Creates a new repository.
public __construct ( string $path, string $baseDirectory, boolean $validateJson = false, Puli\Repository\Api\ChangeStream\ChangeStream $changeStream = null )
$path string The path to the JSON file. If relative, it must be relative to the base directory.
$baseDirectory string The base directory of the store. Paths inside that directory are stored as relative paths. Paths outside that directory are stored as absolute paths.
$validateJson boolean Whether to validate the JSON file against the schema. Slow but spots problems.
$changeStream Puli\Repository\Api\ChangeStream\ChangeStream If provided, the repository will append resource changes to this change stream.

add() public méthode

public add ( $path, $resource )

addFilesystemResource() protected méthode

Adds a filesystem resource to the JSON file.
protected addFilesystemResource ( string $path, Puli\Repository\Api\Resource\FilesystemResource $resource )
$path string The Puli path.
$resource Puli\Repository\Api\Resource\FilesystemResource The resource to add.

clear() public méthode

public clear ( )

contains() public méthode

public contains ( $query, $language = 'glob' )

createResource() protected méthode

Turns a reference into a resource.
protected createResource ( string $path, string | null $reference ) : Puli\Repository\Api\Resource\PuliResource
$path string The Puli path.
$reference string | null The reference.
Résultat Puli\Repository\Api\Resource\PuliResource The resource.

find() public méthode

public find ( $query, $language = 'glob' )

flush() protected méthode

Writes the JSON file.
protected flush ( )

get() public méthode

public get ( $path )

getReferencesForGlob() abstract protected méthode

Each reference returned by this method can be: * null * a link starting with @ * an absolute filesystem path The keys of the returned array are Puli paths. Their order is undefined. The flag STOP_ON_FIRST may be used to stop the search at the first result.
abstract protected getReferencesForGlob ( string $glob, integer $flags ) : string[] | null[]
$glob string The glob.
$flags integer A bitwise combination of the flag constants in this class.
Résultat string[] | null[] A one-level array of references with Puli paths as keys.

getReferencesForPath() abstract protected méthode

Each reference returned by this method can be: * null * a link starting with @ * an absolute filesystem path The result has either one entry or none, if no path was found. The key of the single entry is the path passed to this method.
abstract protected getReferencesForPath ( string $path ) : string[] | null[]
$path string The Puli path.
Résultat string[] | null[] A one-level array of references with Puli paths as keys. The array has at most one entry.

getReferencesForRegex() abstract protected méthode

Each reference returned by this method can be: * null * a link starting with @ * an absolute filesystem path The keys of the returned array are Puli paths. Their order is undefined. The flag STOP_ON_FIRST may be used to stop the search at the first result.
abstract protected getReferencesForRegex ( string $staticPrefix, string $regex, integer $flags ) : string[] | null[]
$staticPrefix string The static prefix of all Puli paths matching the regular expression.
$regex string The regular expression.
$flags integer A bitwise combination of the flag constants in this class.
Résultat string[] | null[] A one-level array of references with Puli paths as keys.

getReferencesInDirectory() abstract protected méthode

Each reference returned by this method can be: * null * a link starting with @ * an absolute filesystem path The keys of the returned array are Puli paths. Their order is undefined. The flag STOP_ON_FIRST may be used to stop the search at the first result.
abstract protected getReferencesInDirectory ( string $path, integer $flags ) : string[] | null[]
$path string The Puli path.
$flags integer A bitwise combination of the flag constants in this class.
Résultat string[] | null[] A one-level array of references with Puli paths as keys.

hasChildren() public méthode

public hasChildren ( $path )

insertReference() abstract protected méthode

The path reference can be: * a link starting with @ * an absolute filesystem path
abstract protected insertReference ( string $path, string | null $reference )
$path string The Puli path.
$reference string | null The path reference.

isFilesystemReference() protected méthode

Returns whether a reference contains an absolute or relative filesystem path.
protected isFilesystemReference ( string $reference ) : boolean
$reference string The reference.
Résultat boolean Whether the reference contains a filesystem path.

isLinkReference() protected méthode

Returns whether a reference contains a link.
protected isLinkReference ( string $reference ) : boolean
$reference string The reference.
Résultat boolean Whether the reference contains a link.

listChildren() public méthode

public listChildren ( $path )

load() protected méthode

Loads the JSON file.
protected load ( )

log() protected méthode

Logs a message.
protected log ( mixed $level, string $message )
$level mixed One of the level constants in {@link LogLevel}.
$message string The message.

logReferenceNotFound() protected méthode

Logs a warning that a reference could not be found.
protected logReferenceNotFound ( string $path, string $reference, string $absoluteReference )
$path string The Puli path of a path mapping.
$reference string The reference that was not found.
$absoluteReference string The absolute filesystem path of the reference.

remove() public méthode

public remove ( $query, $language = 'glob' )

removeReferences() abstract protected méthode

Removes all path references matching the given glob from the JSON file.
abstract protected removeReferences ( string $glob )
$glob string The glob for a list of Puli paths.

setLogger() public méthode

public setLogger ( Psr\Log\LoggerInterface $logger = null )
$logger Psr\Log\LoggerInterface

Property Details

$baseDirectory protected_oe property

protected string $baseDirectory
Résultat string

$json protected_oe property

protected array $json
Résultat array