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
ファイルを表示 Open project: puli/repository Class Usage Examples

Protected Properties

Property Type Description
$baseDirectory string
$json array

Public Methods

Method 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 )

Protected Methods

Method 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

Method 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 method

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 method

public add ( $path, $resource )

addFilesystemResource() protected method

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 method

public clear ( )

contains() public method

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

createResource() protected method

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.
return Puli\Repository\Api\Resource\PuliResource The resource.

find() public method

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

flush() protected method

Writes the JSON file.
protected flush ( )

get() public method

public get ( $path )

getReferencesForGlob() abstract protected method

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.
return string[] | null[] A one-level array of references with Puli paths as keys.

getReferencesForPath() abstract protected method

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.
return string[] | null[] A one-level array of references with Puli paths as keys. The array has at most one entry.

getReferencesForRegex() abstract protected method

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.
return string[] | null[] A one-level array of references with Puli paths as keys.

getReferencesInDirectory() abstract protected method

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.
return string[] | null[] A one-level array of references with Puli paths as keys.

hasChildren() public method

public hasChildren ( $path )

insertReference() abstract protected method

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 method

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

isLinkReference() protected method

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

listChildren() public method

public listChildren ( $path )

load() protected method

Loads the JSON file.
protected load ( )

log() protected method

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 method

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 method

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

removeReferences() abstract protected method

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 method

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

Property Details

$baseDirectory protected_oe property

protected string $baseDirectory
return string

$json protected_oe property

protected array $json
return array