Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HtaccessAnalyzer.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\ObjectManagerInterface;
10 use Magento\Mtf\Util\Protocol\CurlInterface;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 
18 class HtaccessAnalyzer extends \Symfony\Component\Console\Command\Command
19 {
25  private $objectManager;
26 
32  private $commandPath = 'dev/tests/functional/utils/command.php?command=';
33 
39  private $curl;
40 
45  public function __construct(
46  ObjectManagerInterface $objectManager,
47  CurlTransport $curl
48  ) {
49  parent::__construct();
50  $this->objectManager = $objectManager;
51  $this->curl = $curl;
52  }
53 
59  protected function configure()
60  {
61  parent::configure();
62  $this->setName('troubleshooting:check-htaccess')
63  ->setDescription('Check .htaccess file is present. It is needed to run cli commands via browser url.');
64  }
65 
74  protected function execute(InputInterface $input, OutputInterface $output)
75  {
76  \PHPUnit\Util\Configuration::getInstance(MTF_PHPUNIT_FILE)->handlePHPConfiguration();
77  $output = $this->objectManager->create(
78  \Magento\Mtf\Console\Output::class,
79  ['output' => $output]
80  );
81  try {
82  $output->writeln("Checking .htaccess file...");
83  $this->curl->write($_ENV['app_frontend_url'] . $this->commandPath, [], CurlInterface::GET);
84  $this->curl->read();
85  $responseCode = $this->curl->getInfo(CURLINFO_HTTP_CODE);
86  if ($responseCode != 200) {
87  $message['error'][] = 'Your .htaccess file doesn\'t exist. '
88  . 'Please, create it from to .htaccess.sample.';
89  $output->outputMessages($message);
90  }
91  $this->curl->close();
92  } catch (\Exception $e) {
93  $output->outputMessages(['error' => [$e->getMessage()]]);
94  }
95  $output->writeln(".htaccess check finished.");
96  }
97 }
$objectManager
Definition: bootstrap.php:17
$message
__construct(ObjectManagerInterface $objectManager, CurlTransport $curl)
execute(InputInterface $input, OutputInterface $output)