dco*_*bus 29 php curl composer-php
想知道是否可以composer使用一点PHP包装器从浏览器执行,因为我无法访问服务器的shell访问权限.
不确定你是否可以用cURL做到这一点?
End*_*del 38
Danack解决方案的另一种选择是将"composer/composer"依赖包含在您的内容中composer.json,并使用它的API,而不是从中提取内容composer.phar.
composer.json
...
"require-dev": {
"composer/composer": "dev-master",
}
...
Run Code Online (Sandbox Code Playgroud)
composer install手动运行,因此您可以在以下脚本中要求它:
composer_install.php
<?php
require 'vendor/autoload.php'; // require composer dependencies
use Composer\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
// Composer\Factory::getHomeDir() method
// needs COMPOSER_HOME environment variable set
putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer');
// 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.";
Run Code Online (Sandbox Code Playgroud)
从浏览器访问脚本时,该命令应按预期运行.
Dan*_*ack 27
是的,您可以使用一个小PHP包装器运行Composer.Phar文件中提供了所有Composer源代码,因此可以将其解压缩,然后在设置InputInterface之后运行它来替换Composer,期望命令通过命令行传入.
如果您设置这样的目录结构:
./project
./project/composer.json
./project/composer.lock
./project/webroot/composerExtractor.php
./project/var/
Run Code Online (Sandbox Code Playgroud)
将下面的代码放入composerExtractor.php,然后从Web浏览器运行它,Composer应该将所有库下载到:
./project/vendors/
Run Code Online (Sandbox Code Playgroud)
以及在该目录中生成类加载器文件.
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);
?>
Run Code Online (Sandbox Code Playgroud)
虽然这是可能的,但这并不是一个很棒的想法,但如果您不能使用能够为您提供ssh访问权限的主机,则可能是必要的.
我强烈建议至少为自己或办公室获取一个静态IP地址,然后限制只访问自己的IP,以及可能在服务器上运行后删除此脚本以防止它再次意外运行.
我认为在部署之前在托管源代码的机器上实际运行Composer会更好.
在将代码上传到主机之前,您可能会从某种版本控制中检出代码(或者甚至只是将它放在硬盘上).该机器应该composer install在上载之前安装Composer并执行.您无需公开生产机器即可下载所有内容.