是的,您可以使用一些PHP包装器来运行Composer。所有的Composer源代码都可以在Phar文件中使用,因此可以将其解压缩,然后您可以在设置InputInterface之后运行它来替换Composer,以期望通过命令行传递的命令。

如果您设置如下所示的目录结构:

./project

./project/composer.json

./project/composer.lock

./project/webroot/composerExtractor.php

./project/var/

将代码放在composerExtractor.php中,然后从Web浏览器运行,Composer应将所有库下载到:

./project/vendors/

以及在该目录中生成类加载器文件。

composerExtractor.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的访问,以及在服务器上运行后可能会删除此脚本,以防止其意外重新运行。

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐