\QuickApps\Core\PackagePackageFactory

Used to create package objects.

In QuickAppsCMS plugins and themes are internally handled as "packages", there exists a few packages types, for example third-party libraries which are installed through composer's install command. Each package type is represented by its own class, QuickAppsCMS comes with a few of this classes: PluginPackage, LibraryPackage, ThirdPartyPackage and GenericPackage. These classes provides a set of useful methods for interacting with QuickAppsCMS.

This class automatically tries to determinate the best package type based on its name using what we call "detectors" methods. This class comes with a few built-in detector methods which are described below, however more detectors can be registered (or overwrite existing ones) using the addDetector() method. A "detector" is a simple callable function which based on a given package name it should return an object representing that package if the given package name matches the type of package the detector represents. For example:

Registering detectors:

PackageFactory::addDetector('myVendorPlugin', function ($packageName) {
    list($vendor, $package) = packageSplit($packageName);
    if ($vendor == 'my-vendor-plugin') {
        return new MyVendorPackage($package, "/path/to/{$package}/")
    }
});

In this example we are using our own MyVendorPackage class for representing packages created by my-vendor-plugin.

Built-in detectors:

  • plugin: For packages representing QuickAppsCMS plugins.

  • library: For packages representing PHP extension libraries or PHP itself, for example: ext-intl, php, ext-zlib, etc

  • thirdParty: For packages representing third-party libraries installed using composer, for example: nesbot/carbon, robmorgan/phinx, etc.

Detection order:

Detectors methods are invoked in the order they were registered, if one detector fails to detect a package the next registered detector will be used, and so on. By default GenricPackage will be used if all detectors fails to detect the given package name.

Summary

Methods
Properties
Constants
create()
addDetector()
detectors()
No public properties found
No constants found
_init()
_getPlugin()
_getLibrary()
_getThirdParty()
$_detectors
$_initialized
N/A
No private methods found
No private properties found
N/A

Properties

$_detectors

$_detectors : array

List of detectors methods indexed as `name` => `callable`.

Type

array

$_initialized

$_initialized : boolean

Indicates if default detectors were initialized.

Type

boolean

Methods

create()

create(string $package) : \QuickApps\Core\Package\BasePackage

Given a full package name, returns an instance of an object representing that package.

If no matching package is found, GenericPackage will be used by default.

Parameters

string $package

Full package name. e.g. vendor-name/package-name

Returns

\QuickApps\Core\Package\BasePackage

addDetector()

addDetector(string $name, callable $method) : void

Registers a new package detection method.

Callable function should return an object package extending QuickApp\Core\Package\BasePackage class on success.

Parameters

string $name

The name for this detector

callable $method

The callable method

detectors()

detectors() : array

Gets a list of all registered detectors.

Returns

array

_init()

_init() : void

Initializes this class.

_getPlugin()

_getPlugin(string $package) : boolean|\QuickApps\Core\Package\PluginPackage

Tries to get a QuickAppsCMS plugin.

Parameters

string $package

Full package name

Returns

boolean|\QuickApps\Core\Package\PluginPackage

_getLibrary()

_getLibrary(string $package) : boolean|\QuickApps\Core\Package\LibraryPackage

Tries to get package that represents a PHP library.

Parameters

string $package

Full package name

Returns

boolean|\QuickApps\Core\Package\LibraryPackage

_getThirdParty()

_getThirdParty(string $package) : boolean|\QuickApps\Core\Package\ThirdPartyPackage

Tries to get package that represents a third party library.

  • Package must exists on VENDOR_PATH/vendor-name/package-name/.
  • Its composer.json file must exists as well.
  • Package must be registered on Composer's "installed.json" file.

Parameters

string $package

Full package name

Returns

boolean|\QuickApps\Core\Package\ThirdPartyPackage