想知道是否可以composer用一个小的PHP包装程序从浏览器中执行,因为我无权访问服务器的外壳程序。
composer
不确定是否可以使用cURL做到这一点?
是的,您可以使用一个小的PHP包装器来运行Composer。Phar文件中提供了所有Composer源代码,因此可以提取该源代码,然后在设置InputInterface替换Composer后运行它,并期望通过命令行传递命令。
如果您这样设置目录结构:
./project ./project/composer.json ./project/composer.lock ./project/webroot/composerExtractor.php ./project/var/
将下面的代码放入composerExtractor.php中,然后从Web浏览器中运行它,Composer应该将所有库下载到:
./project/vendors/
以及在该目录中生成类加载器文件。
composerExtractor.php
<?php define('EXTRACT_DIRECTORY', "../var/extractedComposer"); if (file_exists(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(EXTRACT_DIRECTORY); } //This requires the phar to have been extracted successfully. require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php'); //Use the Composer classes use Composer\Console\Application; use Composer\Command\UpdateCommand; use Symfony\Component\Console\Input\ArrayInput; // change out of the webroot so that the vendors file is not created in // a place that will be visible to the intahwebz chdir('../'); //Create the commands $input = new ArrayInput(array('command' => 'update')); //Create the application and run it with the commands $application = new Application(); $application->run($input); ?>
尽管这是可行的,但这不是一个好主意,但是如果您不能使用允许您使用ssh访问权限的主机,则可能有必要。
我强烈建议至少为您自己或您的办公室获取一个静态IP地址,然后限制对您自己IP的访问,以及可能在服务器上运行该脚本后删除此脚本,以防止再次意外运行。