(Symfony3)鎖定文件調用控制檯命令安全性:從控制器操作檢查生產沒有發現響應
我與建立一些簡單的cron任務,爲我們的項目經理安全報告的想法玩弄,讓他們可以爲開發者安排升級時間(而我忘記手動運行它們)。
作爲一個非常基本的檢查,我會簡單地運行......
php bin/console security:check
...看什麼作曲家不得不說的漏洞。最終,我想將此輸出轉換爲電子郵件,或者在cron運行時將其發佈到冗餘通道或basecamp作業。
問題
當我運行從通過終端的命令它的偉大工程。在控制器內運行命令總是返回響應鎖定文件不存在。我假設這是參考項目根目錄下的composer.lock文件。我可以確認這個文件確實存在。
以下是我目前使用的控制器,這是從該調整:
http://symfony.com/doc/current/console/command_in_controller.html
<?php
namespace Treetop1500\SecurityReportBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class DefaultController extends Controller
{
public function indexAction($key)
{
if ($key != $this->getParameter('easy_cron_key')) {
throw new UnauthorizedHttpException("You are not authorized to access this page.");
}
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'security:check'
));
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();
// return new Response(""), if you used NullOutput()
return new Response($content);
}
}
$content
的值總是「鎖定文件不存在。」
我意識到可能有更好的工具和方法來做到這一點,但是我真的很想理解爲什麼這是從這個控制器動作產生的響應。感謝您看一看!
這實際上不起作用,並且產生錯誤'[Symfony的\元器件\控制檯\異常\ CommandNotFoundException]命令「安全性:檢查XXX/XXX /../ composer.lock「未定義。你的意思是其中之一?安全性:檢查安全性:編碼密碼「 –
我的不好,答案固定。 –