Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart the process with a different configuration #91

Merged
merged 4 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"amphp/parallel-functions": "^0.1.2",
"beberlei/assert": "^2.8",
"composer/composer": "^1.6",
"composer/xdebug-handler": "dev-master",
"herrera-io/annotations": "~1.0",
"humbug/php-scoper": "^1.0@dev",
"justinrainbow/json-schema": "^5.2",
Expand All @@ -37,7 +38,7 @@
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.2",
"infection/infection": "^0.7.0",
"infection/infection": "^0.8",
"mikey179/vfsStream": "^1.1",
"phpunit/phpunit": "^7.0",
"symfony/var-dumper": "^3.4 || ^4.0"
Expand Down
58 changes: 52 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
bootstrap="tests/bootstrap.php"
colors="true">

<php>
<env name="BOX_ALLOW_XDEBUG" value="1"/>
</php>

<testsuites>
<testsuite name="Box Test Suite">
<directory>tests/</directory>
Expand Down
5 changes: 5 additions & 0 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

use Amp\MultiReasonException;
use Assert\Assertion;
use function ini_get;
use KevinGH\Box\Box;
use KevinGH\Box\Compactor;
use KevinGH\Box\Configuration;
use KevinGH\Box\Console\Logger\BuildLogger;
use KevinGH\Box\MapFile;
use KevinGH\Box\PhpSettingsHandler;
use KevinGH\Box\StubGenerator;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -96,6 +99,8 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): void
{
(new PhpSettingsHandler(new ConsoleLogger($output)))->check();

if (true === $input->getOption(self::DEBUG_OPTION)) {
enable_debug();
}
Expand Down
70 changes: 70 additions & 0 deletions src/PhpSettingsHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <kevin@herrera.io>
* Théo Fidry <theo.fidry@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace KevinGH\Box;

use Composer\XdebugHandler\XdebugHandler;
use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use const FILE_APPEND;
use const PHP_EOL;
use function file_put_contents;

final class PhpSettingsHandler extends XdebugHandler
{
private $logger;
private $required;

/**
* {@inheritdoc}
*/
public function __construct(LoggerInterface $logger)
{
parent::__construct('box', '--ansi');

$this->setLogger($logger);
$this->logger = $logger;

$this->required = (bool) ini_get('phar.readonly');
}

/**
* {@inheritdoc}
*/
protected function requiresRestart($isLoaded)
{
return $this->required || $isLoaded;
}

/**
* {@inheritdoc}
*/
protected function restart($command): void
{
if ($this->required) {
if (false === @file_put_contents($this->tmpIni, 'phar.readonly=0'.PHP_EOL, FILE_APPEND)) {
throw new IOException(
sprintf('Failed to write file "%s".', $this->tmpIni),
0,
null,
$this->tmpIni
);
}

$this->logger->debug('Configured `phar.readonly=0`');
}

parent::restart($command);
}
}