PhilippBaschke\ACFProInstaller\Plugin::addKey PHP Method

addKey() public method

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
    public function addKey(PreFileDownloadEvent $event)
    {
        $processedUrl = $event->getProcessedUrl();
        if ($this->isAcfProPackageUrl($processedUrl)) {
            $rfs = $event->getRemoteFilesystem();
            $acfRfs = new RemoteFilesystem($this->addParameterToUrl($processedUrl, 'k', $this->getKeyFromEnv()), $this->io, $this->composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled());
            $event->setRemoteFilesystem($acfRfs);
        }
    }

Usage Example

 public function testOnlyAddKeyOnAcfUrl()
 {
     // Make key available in the ENVIRONMENT
     putenv(self::KEY_ENV_VARIABLE . '=KEY');
     // Mock an Event
     $event = $this->getMockBuilder('Composer\\Plugin\\PreFileDownloadEvent')->disableOriginalConstructor()->setMethods(['getProcessedUrl', 'getRemoteFilesystem', 'setRemoteFilesystem'])->getMock();
     $event->expects($this->once())->method('getProcessedUrl')->willReturn('another-url');
     $event->expects($this->never())->method('getRemoteFilesystem');
     $event->expects($this->never())->method('setRemoteFilesystem');
     // Call addKey
     $plugin = new Plugin();
     $plugin->addKey($event);
 }