UnitTestPackageManager

class \TYPO3\CMS\Core\Package\UnitTestPackageManager

Extends
PackageManager

This is an intermediate package manager that loads all extensions that are present in one of the package base paths, so that the class loader can find the classes of all tests, whether the according extension is active in the installation itself or not.

Table of Contents

Properties

$activePackages  : array
List of active packages as package key => package object
$availablePackagesScanned  : bool
$composerNameToPackageKeyMap  : array
A map between ComposerName and PackageKey, only available when scanAvailablePackages is run
$dependencyOrderingService  : DependencyOrderingService
$packageAliasMap  : array
$packageCache  : PackageCacheInterface
$packagePathMatchRegex  : string|null
The regex to match paths with EXT:{package/key}
$packages  : PackageInterface[]
Array of available packages, indexed by package key
$packagesBasePath  : string
Absolute path leading to the various package directories
$packagesBasePaths  : array
$packageStatesConfiguration  : array
Package states configuration as stored in the PackageStates.php file
$packageStatesPathAndFilename  : string

Methods

__construct()  : mixed
activatePackage()  : mixed
deactivatePackage()  : mixed
Deactivates a package and updates the packagestates configuration
deletePackage()  : mixed
Removes a package from the file system.
extractPackageKeyFromPackagePath()  : string
Extracts the package key from a path in the form EXT:vendor/package/Path/To/Resource
getActivePackages()  : PackageInterface[]
Returns an array of \TYPO3\CMS\Core\Package objects of all active packages.
getAvailablePackages()  : PackageInterface[]
Returns an array of \TYPO3\CMS\Core\Package objects of all available packages.
getCacheIdentifier()  : string|null
getComposerManifest()  : stdClass
Returns contents of Composer manifest as a stdObject
getPackage()  : PackageInterface
Returns a PackageInterface object for the specified package.
getPackageKeyFromComposerName()  : string
Resolves a TYPO3 package key from a composer package name.
initialize()  : mixed
Initializes the package manager
isPackageActive()  : bool
Returns TRUE if a package is activated or FALSE if it's not.
isPackageAvailable()  : bool
Returns TRUE if a package is available (the package's files exist in the packages directory) or FALSE if it's not. If a package is available it doesn't mean necessarily that it's active!
isPackageKeyValid()  : bool
Check the conformance of the given package key
packagesMayHaveChanged()  : void
Event listener to retrigger scanning of available packages.
registerPackage()  : PackageInterface
Register a native TYPO3 package
reloadPackageInformation()  : mixed
Reloads a package and its information
resolvePackagePath()  : string
Resolves a path in the form EXT:vendor/package/Path/To/Resource to an absolute filesystem path
scanAvailablePackages()  : mixed
Scans all directories in the packages directories for available packages.
setPackageCache()  : mixed
unregisterPackage()  : mixed
Unregisters a package from the list of available packages
warmupCaches()  : void
addDependencyToFrameworkToAllExtensions()  : array
Adds all root packages of current dependency graph as dependency to all extensions
buildDependencyGraph()  : array
Builds the dependency graph for all packages
convertConfigurationForGraph()  : array
Convert the package configuration into a dependency definition
findFrameworkPackages()  : array
getDependencyArrayForPackage()  : array|null
Returns an array of dependent package keys for the given package. It will do this recursively, so dependencies of dependent packages will also be in the result.
getExtensionEmConf()  : array|null
Fetches MetaData information from ext_emconf.php, used for resolving dependencies as well.
getPackageBasePaths()  : array
The order of paths is crucial for allowing overriding of system extension by local extensions.
getPackageKeyFromManifest()  : string
Resolves package key from Composer manifest
getSuggestionArrayForPackage()  : array|null
Returns an array of suggested package keys for the given package.
hasSubDirectories()  : bool
Returns true if the given path has valid subdirectories, false otherwise.
initializePackageObjects()  : mixed
Initializes activePackages property
isComposerDependency()  : bool
Checks whether the given package name is a Composer dependency.
isPackageRegistered()  : bool
Returns TRUE if a package was already registered or FALSE if it's not.
loadPackageManagerStatesFromCache()  : mixed
Attempts to load the package manager states from cache
loadPackageStates()  : mixed
Loads the states of available packages from the PackageStates.php file.
mapExtensionManagerConfigurationToComposerManifest()  : stdClass
Fetches information from ext_emconf.php and maps it so it is treated as it would come from composer.json
registerActivePackage()  : mixed
registerPackagesFromConfiguration()  : mixed
Requires and registers all packages which were defined in packageStatesConfiguration
registerTransientClassLoadingInformationForPackage()  : mixed
resolvePackageDependencies()  : array
Resolves the dependent packages from the meta data of all packages recursively. The resolved direct or indirect dependencies of each package will put into the package states configuration array.
savePackageStates()  : mixed
Saves the current content of $this->packageStatesConfiguration to the PackageStates.php file.
saveToPackageCache()  : void
Saves the current state of all relevant information in the package cache
scanPackagePathsForExtensions()  : array
Fetches all directories from sysext/global/local locations and checks if the extension contains an ext_emconf.php
setComposerManifestValueIfEmpty()  : stdClass
sortActivePackagesByDependencies()  : array
Orders all active packages by comparing their dependencies. By this, the packages and package configurations arrays holds all packages in the correct initialization order.
sortAndSavePackageStates()  : mixed
Overwrite the original method to avoid resolving dependencies (which we do not need) and saving the PackageStates.php file (which we do not want), when calling scanAvailablePackages()
sortPackageStatesConfigurationByDependency()  : array
unregisterPackageByPackageKey()  : mixed
Unregisters a package from the list of available packages

Properties

$activePackages

List of active packages as package key => package object

protected array $activePackages = []

$availablePackagesScanned

protected bool $availablePackagesScanned = false

$composerNameToPackageKeyMap

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

protected array $composerNameToPackageKeyMap = []

$packageAliasMap

protected array $packageAliasMap = []

$packagePathMatchRegex

The regex to match paths with EXT:{package/key}

protected string|null $packagePathMatchRegex

$packagesBasePath

Absolute path leading to the various package directories

protected string $packagesBasePath

$packagesBasePaths

protected array $packagesBasePaths = []

$packageStatesConfiguration

Package states configuration as stored in the PackageStates.php file

protected array $packageStatesConfiguration = []

$packageStatesPathAndFilename

protected string $packageStatesPathAndFilename

Methods

__construct()

public __construct(DependencyOrderingService $dependencyOrderingService[, string|null $packageStatesPathAndFilename = null ][, string|null $packagesBasePath = null ]) : mixed

Parameters

$dependencyOrderingService : DependencyOrderingService
$packageStatesPathAndFilename : string|null = null
$packagesBasePath : string|null = null

activatePackage()

public activatePackage(string $packageKey) : mixed

Parameters

$packageKey : string

extractPackageKeyFromPackagePath()

Extracts the package key from a path in the form EXT:vendor/package/Path/To/Resource

public extractPackageKeyFromPackagePath(string $path) : string

Parameters

$path : string

Tags

throws
UnknownPackageException
throws
UnknownPackagePathException

Return values

string

getActivePackages()

Returns an array of \TYPO3\CMS\Core\Package objects of all active packages.

public getActivePackages() : PackageInterface[]

A package is active, if it is available and has been activated in the package manager settings.

Return values

PackageInterface[]

getAvailablePackages()

Returns an array of \TYPO3\CMS\Core\Package objects of all available packages.

public getAvailablePackages() : PackageInterface[]

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

Return values

PackageInterface[] —

Array of PackageInterface

getCacheIdentifier()

public getCacheIdentifier() : string|null

Return values

string|null

getComposerManifest()

Returns contents of Composer manifest as a stdObject

public getComposerManifest(string $manifestPath[, bool $ignoreExtEmConf = false ]) : stdClass

Parameters

$manifestPath : string
$ignoreExtEmConf : bool = false

Tags

throws
InvalidPackageManifestException

Return values

stdClass

getPackage()

Returns a PackageInterface object for the specified package.

public getPackage(string $packageKey) : PackageInterface

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

Parameters

$packageKey : string

Tags

throws
UnknownPackageException

if the specified package is not known

Return values

PackageInterface —

The requested package object

getPackageKeyFromComposerName()

Resolves a TYPO3 package key from a composer package name.

public getPackageKeyFromComposerName(string $composerName) : string

Parameters

$composerName : string

Return values

string

initialize()

Initializes the package manager

public initialize() : mixed

isPackageActive()

Returns TRUE if a package is activated or FALSE if it's not.

public isPackageActive(string $packageKey) : bool

Parameters

$packageKey : string

The key of the package to check

Return values

bool —

TRUE if package is active, otherwise FALSE

isPackageAvailable()

Returns TRUE if a package is available (the package's files exist in the packages directory) or FALSE if it's not. If a package is available it doesn't mean necessarily that it's active!

public isPackageAvailable(string $packageKey) : bool

Parameters

$packageKey : string

The key of the package to check

Return values

bool —

TRUE if the package is available, otherwise FALSE

isPackageKeyValid()

Check the conformance of the given package key

public isPackageKeyValid(string $packageKey) : bool

Parameters

$packageKey : string

The package key to validate

Return values

bool —

If the package key is valid, returns TRUE otherwise FALSE

reloadPackageInformation()

Reloads a package and its information

public reloadPackageInformation(string $packageKey) : mixed

Parameters

$packageKey : string

Tags

throws
InvalidPackageStateException

if the package isn't available

scanAvailablePackages()

Scans all directories in the packages directories for available packages.

public scanAvailablePackages() : mixed

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

addDependencyToFrameworkToAllExtensions()

Adds all root packages of current dependency graph as dependency to all extensions

protected addDependencyToFrameworkToAllExtensions(array $packageStateConfiguration, array $rootPackageKeys) : array

This ensures that the framework extensions (aka sysext) are always loaded first, before any other external extension.

Parameters

$packageStateConfiguration : array
$rootPackageKeys : array

Return values

array

buildDependencyGraph()

Builds the dependency graph for all packages

protected buildDependencyGraph(array $packageStateConfiguration) : array

This method also introduces dependencies among the dependencies to ensure the loading order is exactly as specified in the list.

Parameters

$packageStateConfiguration : array

Return values

array

convertConfigurationForGraph()

Convert the package configuration into a dependency definition

protected convertConfigurationForGraph(array $packageStatesConfiguration, array $packageKeys) : array

This converts "dependencies" and "suggestions" to "after" syntax for the usage in DependencyOrderingService

Parameters

$packageStatesConfiguration : array
$packageKeys : array

Tags

throws
UnexpectedValueException

Return values

array

findFrameworkPackages()

protected findFrameworkPackages(array $packageStateConfiguration) : array

Parameters

$packageStateConfiguration : array

Return values

array

getDependencyArrayForPackage()

Returns an array of dependent package keys for the given package. It will do this recursively, so dependencies of dependent packages will also be in the result.

protected getDependencyArrayForPackage(string $packageKey[, array &$dependentPackageKeys = [] ][, array $trace = [] ]) : array|null

Parameters

$packageKey : string

The package key to fetch the dependencies for

$dependentPackageKeys : array = []
$trace : array = []

An array of already visited package keys, to detect circular dependencies

Tags

throws
InvalidPackageKeyException

Return values

array|null —

An array of direct or indirect dependent packages

getExtensionEmConf()

Fetches MetaData information from ext_emconf.php, used for resolving dependencies as well.

protected getExtensionEmConf(string $packagePath, string $packageKey) : array|null

Parameters

$packagePath : string
$packageKey : string

Tags

throws
InvalidPackageManifestException

Return values

array|null —

if no ext_emconf.php was found, or the contents of the ext_emconf.php file.

getPackageBasePaths()

The order of paths is crucial for allowing overriding of system extension by local extensions.

protected getPackageBasePaths() : array

Pay attention if you change order of the paths here.

Return values

array

getPackageKeyFromManifest()

Resolves package key from Composer manifest

protected getPackageKeyFromManifest(object $manifest, string $packagePath) : string

If it is a TYPO3 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

$manifest : object
$packagePath : string

Tags

throws
InvalidPackageManifestException

Return values

string

getSuggestionArrayForPackage()

Returns an array of suggested package keys for the given package.

protected getSuggestionArrayForPackage(string $packageKey) : array|null

Parameters

$packageKey : string

The package key to fetch the suggestions for

Return values

array|null —

An array of directly suggested packages

hasSubDirectories()

Returns true if the given path has valid subdirectories, false otherwise.

protected hasSubDirectories(string $path) : bool

Parameters

$path : string

Return values

bool

initializePackageObjects()

Initializes activePackages property

protected initializePackageObjects() : mixed

Saves PackageStates.php if list of required extensions has changed.

isComposerDependency()

Checks whether the given package name is a Composer dependency.

protected isComposerDependency(string $packageName) : bool

In non Composer mode this is always false

Parameters

$packageName : string

Return values

bool

isPackageRegistered()

Returns TRUE if a package was already registered or FALSE if it's not.

protected isPackageRegistered(string $packageKey) : bool

Parameters

$packageKey : string

Return values

bool

loadPackageStates()

Loads the states of available packages from the PackageStates.php file.

protected loadPackageStates() : mixed

The result is stored in $this->packageStatesConfiguration.

Tags

throws
PackageStatesUnavailableException

mapExtensionManagerConfigurationToComposerManifest()

Fetches information from ext_emconf.php and maps it so it is treated as it would come from composer.json

protected mapExtensionManagerConfigurationToComposerManifest(string $packageKey, array $extensionManagerConfiguration, stdClass $composerManifest) : stdClass

Parameters

$packageKey : string
$extensionManagerConfiguration : array
$composerManifest : stdClass

Tags

throws
InvalidPackageManifestException

Return values

stdClass

registerPackagesFromConfiguration()

Requires and registers all packages which were defined in packageStatesConfiguration

protected registerPackagesFromConfiguration(array $packages[, bool $registerOnlyNewPackages = false ]) : mixed

Parameters

$packages : array
$registerOnlyNewPackages : bool = false

Tags

throws
InvalidPackageStateException
throws
PackageStatesFileNotWritableException

resolvePackageDependencies()

Resolves the dependent packages from the meta data of all packages recursively. The resolved direct or indirect dependencies of each package will put into the package states configuration array.

protected resolvePackageDependencies(array $packageConfig) : array

Parameters

$packageConfig : array

Return values

array

saveToPackageCache()

Saves the current state of all relevant information in the package cache

protected saveToPackageCache() : void

scanPackagePathsForExtensions()

Fetches all directories from sysext/global/local locations and checks if the extension contains an ext_emconf.php

protected scanPackagePathsForExtensions() : array

Return values

array

setComposerManifestValueIfEmpty()

protected setComposerManifestValueIfEmpty(stdClass $manifest, string $property, mixed $value) : stdClass

Parameters

$manifest : stdClass
$property : string
$value : mixed

Return values

stdClass

sortActivePackagesByDependencies()

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

protected sortActivePackagesByDependencies() : array

Return values

array

sortAndSavePackageStates()

Overwrite the original method to avoid resolving dependencies (which we do not need) and saving the PackageStates.php file (which we do not want), when calling scanAvailablePackages()

protected sortAndSavePackageStates() : mixed

sortPackageStatesConfigurationByDependency()

protected sortPackageStatesConfigurationByDependency(array $packageStatesConfiguration) : array

Parameters

$packageStatesConfiguration : array

Tags

throws
UnexpectedValueException

Return values

array —

Returns the packageStatesConfiguration sorted by dependencies

unregisterPackageByPackageKey()

Unregisters a package from the list of available packages

protected unregisterPackageByPackageKey(string $packageKey) : mixed

Parameters

$packageKey : string

Package Key of the package to be unregistered

On this page