Skip to content

Commit

Permalink
Merge pull request #2 from dreadnip/vanilla
Browse files Browse the repository at this point in the history
Refactor to vanilla PHP
  • Loading branch information
Sander authored Mar 25, 2023
2 parents 125dc94 + a7620be commit 8f43368
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
60 changes: 26 additions & 34 deletions bin/chop
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,37 @@

declare(strict_types=1);

if (php_sapi_name() !== 'cli') {
exit;
}

foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
$loaded = true;
break;
}
}

use Chop\Kernel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;

(new SingleCommandApplication())
->addArgument('fcgi', InputArgument::OPTIONAL, 'Path to a socket file or network address.')
->addOption('quiet', 'q')
->setCode(function (InputInterface $input, OutputInterface $output) {
$output->writeln('Running in ' . __DIR__ . ' on ' . PHP_VERSION);

$kernel = new Kernel($input->getArgument('fcgi'));

$status = $kernel->reset();

if (!$status) {
if (!$input->getOption('quiet')) {
$output->writeln('<error>OPcache disabled</error>');
}

return Command::FAILURE;
}

if (!$input->getOption('quiet')) {
$output->writeln(sprintf('<info>OPcache cleared (%s)</info>',
$kernel->connection->getSocketAddress()
));
}

return Command::SUCCESS;
})
->run();

$fcgiArgumentPassed = array_search('--fcgi', $argv);

if (false !== $fcgiArgumentPassed) {
$fcgi = $argv[$fcgiArgumentPassed + 1];
}

$kernel = new Kernel($fcgi ?? null);
$status = $kernel->reset();

if (true === in_array('-q', $argv)) {
exit;
}

if (!$status) {
echo 'OPcache disabled' . PHP_EOL;
} else {
echo sprintf(
'OPcache cleared (%s)',
$kernel->connection->getSocketAddress()
) . PHP_EOL;
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "dreadnip/chop",
"description": "Clear opcache through php-fpm",
"require": {
"php": "^8.1",
"symfony/console": "^6.2",
"php": "^8.0",
"hollodotme/fast-cgi-client": "^3.1"
},
"require-dev": {
Expand Down

0 comments on commit 8f43368

Please sign in to comment.