PHP Класс 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.
Наследование: implements Composer\Plugin\PluginInterface, implements Composer\EventDispatcher\EventSubscriberInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$composer Composer\Composer
$io Composer\IO\IOInterface

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
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

Описание методов

activate() публичный Метод

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() публичный Метод

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() защищенный Метод

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
Результат string The url appended with ¶meter=value

addVersion() публичный Метод

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() защищенный Метод

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
Результат string The key from the environment

getPackageFromOperation() защищенный Метод

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
Результат PackageInterface The package of the operation

getSubscribedEvents() публичный статический Метод

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
Результат array An array of events that the plugin subscribes to

isAcfProPackageUrl() защищенный Метод

Test if the given url is the ACF PRO download url
protected isAcfProPackageUrl ( $url ) : boolean
Результат boolean

loadDotEnv() защищенный Метод

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

removeParameterFromUrl() защищенный Метод

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
Результат string The url with the ¶meter=value removed

validateVersion() защищенный Метод

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
Результат string The valid version

Описание свойств

$composer защищенное свойство

protected Composer,Composer $composer
Результат Composer\Composer

$io защищенное свойство

protected IOInterface,Composer\IO $io
Результат Composer\IO\IOInterface