PHP Class PhilippBaschke\ACFProInstaller\Plugin

The WordPress plugin Advanced Custom Fields PRO (ACF PRO) does not offer a way to install it via composer natively. This plugin uses a 'package' repository (user supplied) that downloads the correct version from the ACF site using the version number from that repository and a license key from the ENVIRONMENT or an .env file. With this plugin user no longer need to expose their license key in composer.json.
Inheritance: implements Composer\Plugin\PluginInterface, implements Composer\EventDispatcher\EventSubscriberInterface
Afficher le fichier Open project: philippbaschke/acf-pro-installer Class Usage Examples

Protected Properties

Свойство Type Description
$composer Composer\Composer
$io Composer\IO\IOInterface

Méthodes publiques

Méthode Description
activate ( Composer\Composer $composer, Composer\IO\IOInterface $io ) The function that is called when the plugin is activated
addKey ( Composer\Plugin\PreFileDownloadEvent $event ) Add the key from the environment to the event url
addVersion ( Composer\Installer\PackageEvent $event ) Add the version to the package url
getSubscribedEvents ( ) : array Subscribe this Plugin to relevant Events

Méthodes protégées

Méthode Description
addParameterToUrl ( string $url, string $parameter, string $value ) : string Add a parameter to the given url
getKeyFromEnv ( ) : string Get the ACF PRO key from the environment
getPackageFromOperation ( Composer\DependencyResolver\Operation\OperationInterface $operation ) : PackageInterface Get the package from a given operation
isAcfProPackageUrl ( $url ) : boolean Test if the given url is the ACF PRO download url
loadDotEnv ( ) Make environment variables in .env available if .env exists
removeParameterFromUrl ( string $url, string $parameter ) : string Remove a given parameter from the given url
validateVersion ( string $version ) : string Validate that the version is an exact major.minor.patch.optional version

Method Details

activate() public méthode

Makes composer and io available because they are needed in the addKey method.
public activate ( Composer\Composer $composer, Composer\IO\IOInterface $io )
$composer Composer\Composer The composer object
$io Composer\IO\IOInterface Not used

addKey() public méthode

The key is not added to the package because it would show up in the composer.lock file in this case. A custom file system is used to swap out the ACF PRO url with a url that contains the key.
public addKey ( Composer\Plugin\PreFileDownloadEvent $event )
$event Composer\Plugin\PreFileDownloadEvent The event that called this method

addParameterToUrl() protected méthode

Adds the given parameter at the end of the given url. It only works with urls that already have parameters (e.g. test.com?p=true) because it uses & as a separation character.
protected addParameterToUrl ( string $url, string $parameter, string $value ) : string
$url string The url that should be appended
$parameter string The name of the parameter
$value string The value of the parameter
Résultat string The url appended with ¶meter=value

addVersion() public méthode

The version needs to be added in the PRE_PACKAGE_INSTALL/UPDATE event to make sure that different version save different urls in composer.lock. Composer would load any available version from cache although the version numbers might differ (because they have the same url).
public addVersion ( Composer\Installer\PackageEvent $event )
$event Composer\Installer\PackageEvent The event that called the method

getKeyFromEnv() protected méthode

Loads the .env file that is in the same directory as composer.json and gets the key from the environment variable KEY_ENV_VARIABLE. Already set variables will not be overwritten by the variables in .env
protected getKeyFromEnv ( ) : string
Résultat string The key from the environment

getPackageFromOperation() protected méthode

Is needed because update operations don't have a getPackage method
protected getPackageFromOperation ( Composer\DependencyResolver\Operation\OperationInterface $operation ) : PackageInterface
$operation Composer\DependencyResolver\Operation\OperationInterface The operation
Résultat PackageInterface The package of the operation

getSubscribedEvents() public static méthode

Pre Install/Update: The version needs to be added to the url (will show up in composer.lock) Pre Download: The key needs to be added to the url (will not show up in composer.lock)
public static getSubscribedEvents ( ) : array
Résultat array An array of events that the plugin subscribes to

isAcfProPackageUrl() protected méthode

Test if the given url is the ACF PRO download url
protected isAcfProPackageUrl ( $url ) : boolean
Résultat boolean

loadDotEnv() protected méthode

getcwd() returns the directory of composer.json.
protected loadDotEnv ( )

removeParameterFromUrl() protected méthode

Removes ¶meter=value from the given url. Only works with urls that have multiple parameters and the parameter that should be removed is not the first (because of the & character).
protected removeParameterFromUrl ( string $url, string $parameter ) : string
$url string The url where the parameter should be removed
$parameter string The name of the parameter
Résultat string The url with the ¶meter=value removed

validateVersion() protected méthode

The url to download the code for the package only works with exact version numbers with 3 or 4 digits: e.g. 1.2.3 or 1.2.3.4
protected validateVersion ( string $version ) : string
$version string The version that should be validated
Résultat string The valid version

Property Details

$composer protected_oe property

protected Composer,Composer $composer
Résultat Composer\Composer

$io protected_oe property

protected IOInterface,Composer\IO $io
Résultat Composer\IO\IOInterface