class PackageManager (View source)

The default Flow Package Manager

Constants

PACKAGESTATE_FORMAT_VERSION

The current format version for PackageStates.php files

DEFAULT_PACKAGE_INFORMATION_CACHE_FILEPATH

The default package states

Properties

protected Bootstrap $bootstrap
protected PackageFactory $packageFactory
protected Dispatcher $dispatcher
protected array $packages

Array of available packages, indexed by package key (case sensitive)

protected array $packageKeys

A translation table between lower cased and upper camel cased package keys

protected array $composerNameToPackageKeyMap

A map between ComposerName and PackageKey, only available when scanAvailablePackages is run

protected string $packagesBasePath

Absolute path leading to the various package directories

protected string $packageInformationCacheFilePath
protected array $packageStatesConfiguration

Package states configuration as stored in the PackageStates.php file

protected array $settings
protected FlowPackageInterface[] $flowPackages

Methods

void
injectSettings(array $settings)

Inject settings into the package manager. Has to be called explicitly on object initialization as the package manager subpackage is excluded from proxy class building.

__construct(string $packageInformationCacheFilePath, string $packagesBasePath)

No description

void
initialize(Bootstrap $bootstrap)

Initializes the package manager

array
getFlowPackages()

Get only packages that implement the FlowPackageInterface for use in the Framework Array keys will be the respective package keys.

bool
isPackageAvailable(string $packageKey)

Returns true if a package is available (the package's files exist in the packages directory) or false if it's not.

string
getPackagesBasePath()

Returns the base path for packages

getPackage(string $packageKey)

Returns a PackageInterface object for the specified package.

array
getAvailablePackages()

Returns an array of PackageInterface objects of all available packages.

array
getFrozenPackages()

Returns an array of PackageInterface objects of all frozen packages.

array
getFilteredPackages(string $packageState = 'available', string $packageType = null)

Returns an array of PackageInterface objects of all packages that match the given package state, path, and type filters. All three filters must match, if given.

array
filterPackagesByType(array $packages, string $packageType)

Returns an array of PackageInterface objects in the given array of packages that are of the specified package type.

createPackage(string $packageKey, array $manifest = [], string $packagesPath = null)

Create a package, given the package key

void
movePackage(string $fromAbsolutePath, string $toAbsolutePath)

Moves a package from one path to another.

void
freezePackage(string $packageKey)

Freezes a package

bool
isPackageFrozen(string $packageKey)

Tells if a package is frozen

void
unfreezePackage(string $packageKey)

Unfreezes a package

void
refreezePackage(string $packageKey)

Refreezes a package

array
rescanPackages()

Rescans available packages, order and write a new PackageStates file.

array
getCurrentPackageStates()

Loads the states of available packages from the PackageStates.php file and initialises a package scan if the file was not found or the configuration format was not current.

array
loadPackageStates()

Load the current package states

array
scanAvailablePackages()

Scans all directories in the packages directories for available packages.

Generator|null
findComposerPackagesInPath(string $startingDirectory)

Recursively traverses directories from the given starting points and returns all folder paths that contain a composer.json and which does NOT have the key "extra.neos.is-merged-repository" set, as that indicates a composer package that joins several "real" packages together.

array
preparePackageStateConfiguration(string $packageKey, string $packagePath, array $composerManifest)

No description

void
registerPackagesFromConfiguration(array $packageStatesConfiguration)

Requires and registers all packages which were defined in packageStatesConfiguration

void
registerPackageFromStateConfiguration(string $composerName, array $packageStateConfiguration)

Registers a package under the given composer name with the configuration.

array
sortAndSavePackageStates(array $packageStates)

Takes the given packageStatesConfiguration, sorts it by dependencies, saves it and returns the ordered list

void
savePackageStates(array $orderedPackageStates)

Save the given (ordered) array of package states data

array
sortAvailablePackagesByDependencies(array $packageStates)

Orders all packages by comparing their dependencies. By this, the packages and package configurations arrays holds all packages in the correct initialization order.

array
collectPackageManifestData(array $packageStates)

Collects the manifest data for all packages in the given package states array

string|false
getCaseSensitivePackageKey(string $unknownCasedPackageKey)

Returns the correctly cased version of the given package key or false if no such package is available.

string
getPackageKeyFromComposerName(string $composerName)

Resolves a Flow package key from a composer package name.

bool
isPackageKeyValid(string $packageKey)

Check the conformance of the given package key

string
getPackageKeyFromManifest(array $manifest, string $packagePath)

Resolves package key from Composer manifest

string
derivePackageKey(string $composerName, string $packageType = null, string $packagePath = '', string $autoloadNamespace = null)

Derive a flow package key from the given information.

void
emitPackageStatesUpdated()

Emits a signal when package states have been changed (e.g. when a package was created)

Details

void injectSettings(array $settings)

Inject settings into the package manager. Has to be called explicitly on object initialization as the package manager subpackage is excluded from proxy class building.

Parameters

array $settings

Return Value

void

__construct(string $packageInformationCacheFilePath, string $packagesBasePath)

No description

Parameters

string $packageInformationCacheFilePath
string $packagesBasePath

void initialize(Bootstrap $bootstrap)

Initializes the package manager

Parameters

Bootstrap $bootstrap

The current bootstrap

Return Value

void

Exceptions

Exception
CorruptPackageException
FilesException
InvalidConfigurationException

array getFlowPackages()

internal  
 

Get only packages that implement the FlowPackageInterface for use in the Framework Array keys will be the respective package keys.

Return Value

array

bool isPackageAvailable(string $packageKey)

Returns true if a package is available (the package's files exist in the packages directory) or false if it's not.

Parameters

string $packageKey

The key of the package to check

Return Value

bool

true if the package is available, otherwise false

string getPackagesBasePath()

Returns the base path for packages

Return Value

string

PackageInterface getPackage(string $packageKey)

Returns a PackageInterface object for the specified package.

Parameters

string $packageKey

Return Value

PackageInterface

The requested package object

Exceptions

UnknownPackageException

array getAvailablePackages()

Returns an array of PackageInterface objects of all available packages.

A package is available, if the package directory contains valid meta information.

Return Value

array

array getFrozenPackages()

Returns an array of PackageInterface objects of all frozen packages.

A frozen package is not considered by file monitoring and provides some precompiled reflection data in order to improve performance.

Return Value

array

array getFilteredPackages(string $packageState = 'available', string $packageType = null)

Returns an array of PackageInterface objects of all packages that match the given package state, path, and type filters. All three filters must match, if given.

Parameters

string $packageState

defaults to available

string $packageType

Return Value

array

Exceptions

InvalidPackageStateException

protected array filterPackagesByType(array $packages, string $packageType)

Returns an array of PackageInterface objects in the given array of packages that are of the specified package type.

Parameters

array $packages

Array of PackageInterface objects to be filtered

string $packageType

Filter out anything that's not of this packageType

Return Value

array

PackageInterface createPackage(string $packageKey, array $manifest = [], string $packagesPath = null)

Create a package, given the package key

Parameters

string $packageKey

The package key of the new package

array $manifest

A composer manifest as associative array.

string $packagesPath

If specified, the package will be created in this path, otherwise the default "Application" directory is used

Return Value

PackageInterface

The newly created package

Exceptions

Exception
CorruptPackageException
InvalidPackageKeyException
PackageKeyAlreadyExistsException
FilesException
InvalidConfigurationException

protected void movePackage(string $fromAbsolutePath, string $toAbsolutePath)

Moves a package from one path to another.

Parameters

string $fromAbsolutePath
string $toAbsolutePath

Return Value

void

Exceptions

FilesException

void freezePackage(string $packageKey)

Freezes a package

Parameters

string $packageKey

The package to freeze

Return Value

void

Exceptions

PackageStatesFileNotWritableException
UnknownPackageException
Exception
FilesException

bool isPackageFrozen(string $packageKey)

Tells if a package is frozen

Parameters

string $packageKey

The package to check

Return Value

bool

void unfreezePackage(string $packageKey)

Unfreezes a package

Parameters

string $packageKey

The package to unfreeze

Return Value

void

Exceptions

PackageStatesFileNotWritableException
Exception
FilesException

void refreezePackage(string $packageKey)

Refreezes a package

Parameters

string $packageKey

The package to refreeze

Return Value

void

Exceptions

Exception

array rescanPackages()

Rescans available packages, order and write a new PackageStates file.

Return Value

array

The found and sorted package states.

Exceptions

Exception
InvalidConfigurationException
FilesException

protected array getCurrentPackageStates()

Loads the states of available packages from the PackageStates.php file and initialises a package scan if the file was not found or the configuration format was not current.

protected array loadPackageStates()

Load the current package states

Return Value

array

protected array scanAvailablePackages()

Scans all directories in the packages directories for available packages.

For each package a Package object is created and stored in $this->packages.

Return Value

array

Exceptions

Exception
InvalidConfigurationException

protected Generator|null findComposerPackagesInPath(string $startingDirectory)

Recursively traverses directories from the given starting points and returns all folder paths that contain a composer.json and which does NOT have the key "extra.neos.is-merged-repository" set, as that indicates a composer package that joins several "real" packages together.

In case a "is-merged-repository" is found the traversal continues inside.

Parameters

string $startingDirectory

Return Value

Generator|null

protected array preparePackageStateConfiguration(string $packageKey, string $packagePath, array $composerManifest)

No description

Parameters

string $packageKey
string $packagePath
array $composerManifest

Return Value

array

Exceptions

CorruptPackageException
InvalidPackagePathException

protected void registerPackagesFromConfiguration(array $packageStatesConfiguration)

Requires and registers all packages which were defined in packageStatesConfiguration

Parameters

array $packageStatesConfiguration

Return Value

void

Exceptions

CorruptPackageException

protected void registerPackageFromStateConfiguration(string $composerName, array $packageStateConfiguration)

Registers a package under the given composer name with the configuration.

This uses the PackageFactory to create the Package instance and sets it to all relevant data arrays.

Parameters

string $composerName
array $packageStateConfiguration

Return Value

void

Exceptions

CorruptPackageException

protected array sortAndSavePackageStates(array $packageStates)

Takes the given packageStatesConfiguration, sorts it by dependencies, saves it and returns the ordered list

Parameters

array $packageStates

Return Value

array

Exceptions

PackageStatesFileNotWritableException
FilesException

protected void savePackageStates(array $orderedPackageStates)

Save the given (ordered) array of package states data

Parameters

array $orderedPackageStates

Return Value

void

Exceptions

PackageStatesFileNotWritableException
FilesException

protected array sortAvailablePackagesByDependencies(array $packageStates)

Orders all packages by comparing their dependencies. By this, the packages and package configurations arrays holds all packages in the correct initialization order.

Parameters

array $packageStates

The unordered package states

Return Value

array

ordered package states.

protected array collectPackageManifestData(array $packageStates)

Collects the manifest data for all packages in the given package states array

Parameters

array $packageStates

Return Value

array

string|false getCaseSensitivePackageKey(string $unknownCasedPackageKey)

Returns the correctly cased version of the given package key or false if no such package is available.

Parameters

string $unknownCasedPackageKey

The package key to convert

Return Value

string|false

The upper camel cased package key or false if no such package exists

string getPackageKeyFromComposerName(string $composerName)

Resolves a Flow package key from a composer package name.

Parameters

string $composerName

Return Value

string

Exceptions

InvalidPackageStateException

bool isPackageKeyValid(string $packageKey)

Check the conformance of the given package key

Parameters

string $packageKey

The package key to validate

Return Value

bool

If the package key is valid, returns true otherwise false

protected string getPackageKeyFromManifest(array $manifest, string $packagePath)

Resolves package key from Composer manifest

If it is a Flow package the name of the containing directory will be used.

Else if the composer name of the package matches the first part of the lowercased namespace of the package, the mixed case version of the composer name / namespace will be used, with backslashes replaced by dots.

Else the composer name will be used with the slash replaced by a dot

Parameters

array $manifest
string $packagePath

Return Value

string

protected string derivePackageKey(string $composerName, string $packageType = null, string $packagePath = '', string $autoloadNamespace = null)

Derive a flow package key from the given information.

The order of importance is:

  • package install path
  • first found autoload namespace
  • composer name

Parameters

string $composerName
string $packageType
string $packagePath
string $autoloadNamespace

Return Value

string

protected void emitPackageStatesUpdated()

Emits a signal when package states have been changed (e.g. when a package was created)

The advice is not proxyable, so the signal is dispatched manually here.

Return Value

void

Exceptions

Exception
InvalidSlotException