Skip to content

Commit

Permalink
Save repository file path in attribute
Browse files Browse the repository at this point in the history
PHP 5.5 does not allow generated constants and would fail on
__DIR__ . '...'. To avoid this error, the file path is moved into an
attribute that is initialized in the constructor.

See: http://stackoverflow.com/a/24547704
  • Loading branch information
PhilippBaschke committed Apr 14, 2016
1 parent d4875cb commit 44caa57
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ACFProInstaller/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ class Plugin implements PluginInterface
*
* It is based on the recommended approach from the ACF support forum.
* @url https://gist.github.com/dmalatesta/4fae4490caef712a51bf
*
* @access protected
* @var string
*/
const REPOSITORY_FILE = __DIR__ . '/repository.json';
protected $repositoryFile;

/**
* Constructor
*
* Set up the path to the repository file when the Plugin is created.
*/
public function __construct()
{
$this->repositoryFile = __DIR__.DIRECTORY_SEPARATOR.'repository.json';
}

public function activate(Composer $composer, IOInterface $io)
{
$config = json_decode(file_get_contents(self::REPOSITORY_FILE), true);
$config = json_decode(file_get_contents($this->repositoryFile), true);
$repository = $composer->getRepositoryManager()
->createRepository($config['type'], $config);
$composer->getRepositoryManager()->prependRepository($repository);
Expand Down

0 comments on commit 44caa57

Please sign in to comment.