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
파일 보기 프로젝트 열기: philippbaschke/acf-pro-installer 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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