Я пытаюсь разработать класс для установки или обновления всего или одного или нескольких librray.Но я заблокирован.
Я пытался начать с этого поста: Запустить композитор с помощью PHP-скрипта в браузере
Моя структура
/Shop/
/Shop/composer.json
/Shop/composer.lock
/Shop/includes/External/Vendor
/Shop/includes/Core
Примечание: все библиотеки находятся внутри /Shop/includes/External/Vendor
Класс, который я пытаюсь создать, позволяет мне установить библиотеку или обновить все или одну библиотеку
namespace Site\SiteAdmin;
use Site\Core;
use Composer\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
class Composer {
const EXTRACT_DIRECTORY = BASE_DIR . 'External';
public static function ComposerUpdate($libray = null) {
if (is_null(libray) {
if (file_exists(static::EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
echo 'Extracted autoload already exists. Skipping phar extraction as presumably it\'s already extracted.';
} else{
$composerPhar = new Phar('Composer.phar');
//php.ini setting phar.readonly must be set to 0
$composerPhar->extractTo(static::EXTRACT_DIRECTORY);
}
//This requires the phar to have been extracted successfully.
require_once (static::EXTRACT_DIRECTORY . '/vendor/autoload.php');
chdir(Core::getConfig('dir_root', 'Shop'));
//Create the commands
$input = new ArrayInput(['command' => 'update']);
//Create the application and run it with the commands
$application = new Application();
try {
$application->setAutoExit(false); // prevent `$application->run` method from exitting the script
$application->run($input);
} catch (\Exception $e) {
var_dump($e);
}
} else {
// update libray like phpmailer for example
}
}
// how to make this function to install a specific library like phpmailer for example
public function ComposerInstall($library) {
if (file_exists(static::EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted.";
} else{
$composerPhar = new Phar("Composer.phar");
//php.ini setting phar.readonly must be set to 0
$composerPhar->extractTo(static::EXTRACT_DIRECTORY);
}
//This requires the phar to have been extracted successfully.
require_once (static::EXTRACT_DIRECTORY.'/vendor/autoload.php');
// change out of the webroot so that the vendors file is not created in
// a place that will be visible to the intahwebz
chdir(Core::getConfig('dir_root', 'Shop'));
// call `composer install` command programmatically
$input = new ArrayInput(array('command' => 'install'));
$application = new Application();
$application->setAutoExit(false); // prevent `$application->run` method from exitting the script
$application->run($input);
echo "Done.";
}
}