Last active
August 10, 2022 14:12
-
-
Save kyletaylored/e7482dd1a61f97188b647a43b6bbf531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"autoload": { | |
"classmap": [ | |
"scripts/composer/PrivateAuth.php" | |
] | |
}, | |
"scripts": { | |
"loadPrivateAuth": "Project\\composer\\ComposerPrivateAuth::loadComposerSecrets", | |
"pre-install-cmd": "@loadPrivateAuth", | |
"pre-update-cmd": "@loadPrivateAuth" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Project\composer\ComposerPrivateAuth. | |
*/ | |
namespace Project\composer; | |
use Composer\Script\Event; | |
class ComposerPrivateAuth | |
{ | |
/** | |
* Load environmental variables from private path. | |
*/ | |
public static function loadComposerSecrets(Event $event): | |
void | |
{ | |
// Load config into composer | |
$PACKAGIST_HOST = getenv('PACKAGIST_HOST'); | |
$PACKAGIST_USER = getenv('PACKAGIST_USER'); | |
$PACKAGIST_PASSWORD = getenv('PACKAGIST_PASSWORD'); | |
$config = ["type" => "composer", "url" => "https://$PACKAGIST_USER:$PACKAGIST_PASSWORD@$PACKAGIST_HOST"]; | |
// Add auth to repositories. | |
$repositoryManager = $event->getComposer() | |
->getRepositoryManager(); | |
$repository = $repositoryManager->createRepository('composer', $config, $PACKAGIST_HOST); | |
$repositoryManager->prependRepository($repository); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment