Skip to content

Commit

Permalink
initial work on command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
aheinze committed Feb 5, 2022
1 parent c2e778e commit 00b8593
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
50 changes: 50 additions & 0 deletions modules/App/Command/FlushTmp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class FlushTmp extends Command {

protected static $defaultName = 'app:flush:tmp';
protected $app = null;

public function __construct(\Lime\App $app) {
$this->app = $app;
parent::__construct();
}

protected function configure(): void {
$this->setHelp('This command empties the /storage/tmp folder');
}

protected function execute(InputInterface $input, OutputInterface $output): int {

$dirs = ['#cache:','#tmp:'];

foreach ($dirs as $dir) {

$path = $this->app->path($dir);
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);

foreach ($files as $file) {

if (!$file->isFile()) continue;
if (preg_match('/(\.gitkeep|\.gitignore|index\.html)$/', $file)) continue;

@unlink($file->getRealPath());
}

$this->app->helper('fs')->removeEmptySubFolders($path);
}

if (function_exists('opcache_reset')) {
opcache_reset();
}

$output->writeln('<info>Tmp folder was flushed!</info>');
return Command::SUCCESS;
}
}
12 changes: 9 additions & 3 deletions modules/App/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
$this->helpers['i18n'] = 'App\\Helper\\i18n';
$this->helpers['rspc'] = 'App\\Helper\\ResponseCache';

include_once(__DIR__.'/functions.php');

// events

$this->on('app.admin.init', function() {
include(__DIR__.'/admin.php');
}, 1000);
Expand All @@ -24,9 +28,11 @@

}, 1000);

include_once(__DIR__.'/functions.php');

// events
$this->on('app.user.disguise', function(array &$user) {
unset($user['password'], $user['apiKey'], $user['_reset_token']);
});

$this->on('app.cli.init', function($cli) {
$app = $this;
include(__DIR__.'/cli.php');
});
7 changes: 7 additions & 0 deletions modules/App/cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if (!isset($cli, $app) || PHP_SAPI !== 'cli') {
return;
}

$cli->add(new App\Command\FlushTmp($app));
24 changes: 22 additions & 2 deletions tower
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#!/usr/bin/env php
<?php

if (PHP_SAPI !== 'cli') {
exit('Script needs to be run from Command Line Interface (cli)');
}

define('APP_CLI', true);

require __DIR__.'/bootstrap.php';

use Symfony\Component\Console\Application;

$app = Cockpit::instance();
$cli = new Application("Tower - {$app['app.name']}", $app['app.version']);
$cli = new Application("
_|_|_| _| _| _|
_| _|_| _|_|_| _| _| _|_|_| _|_|_|_|
_| _| _| _| _|_| _| _| _| _|
_| _| _| _| _| _| _| _| _| _|
_|_|_| _|_| _|_|_| _| _| _|_|_| _| _|_|
_|
_|
_|_|_|_|_|
_| _|_| _| _| _| _|_| _| _|_|
_| _| _| _| _| _| _|_|_|_| _|_|
_| _| _| _| _| _| _| _| _|
_| _|_| _| _| _|_|_| _|
{$app['app.name']} Tower", $app['app.version']);

$app->trigger('cli.bootstrap', [$cli]);
$app->trigger('app.cli.init', [$cli]);

$cli->run();

0 comments on commit 00b8593

Please sign in to comment.