Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Refactored to be compatible symfony/console 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Dec 1, 2018
1 parent 260a664 commit 413b4bf
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 39 deletions.
16 changes: 14 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
"description": " Build in commands for Selami.",
"type": "library",
"require": {
"selami/console": "^0.3",
"symfony/process": "^4.1"
"php": "^7.2",
"ext-json": "*",
"symfony/console": "^4.2",
"symfony/process": "^4.2",
"selami/console": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3",
"object-calisthenics/phpcs-calisthenics-rules": "^3.3"
},
"license": "MIT",
"authors": [
Expand All @@ -18,5 +25,10 @@
"psr-4": {
"Selami\\Command\\": "src/"
}
},
"scripts": {
"phpcs": "vendor/bin/phpcs --standard=PSR2 src ",
"phpcbf": "vendor/bin/phpcbf --standard=PSR2 src ",
"phpcs-object-calisthenics": "vendor/bin/phpcs src -sp --standard=vendor/object-calisthenics/phpcs-calisthenics-rules/src/ObjectCalisthenics/ruleset.xml"
}
}
5 changes: 2 additions & 3 deletions src/Cache/ClearAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

namespace Selami\Command\Cache;

use Selami\Console\Command as SelamiCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Exception\InvalidArgumentException;

class ClearAll extends SelamiCommand
class ClearAll extends Command
{

protected static $availableCommands = [
'cache:clear-config',
'cache:clear-routes',
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/ClearConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Selami\Command\Cache;

use Selami\Console\Command as SelamiCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;

class ClearConfig extends SelamiCommand
class ClearConfig extends Command
{
/**
* @inheritdoc
Expand Down
27 changes: 12 additions & 15 deletions src/Cache/ClearRouteDispatcherData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

namespace Selami\Command\Cache;

use Selami\Console\Command as SelamiCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use function dirname;

class ClearRouteDispatcherData extends SelamiCommand
class ClearRouteDispatcherData extends Command
{
/**
* @inheritdoc
Expand All @@ -26,18 +27,14 @@ protected function configure() : void
*/
protected function execute(InputInterface $input, OutputInterface $output) : void
{
$config = $this->container->get('config');
$routeCacheFile = $config['app']['cache_file'] ?? '';
if (trim((string) $routeCacheFile) !== '') {
$folder = dirname($routeCacheFile);
$files = glob($folder . '/*fastroute.cache');
$output->writeln('Fastroute cache files under ' . $folder . ' will be deleted.');
foreach ($files as $file) {
$unlinkResult = file_exists($file)
? (unlink($file) === true) ? 'deleted.' : 'could\'t deleted'
: ' file does not exist';
$output->writeln($file . ' ' . $unlinkResult);
}
}
$folder = dirname('cache');
$files = glob($folder . '/*fastroute.cache');
$output->writeln('FastRoute cache files under ' . $folder . ' will be deleted.');
foreach ($files as $file) {
$unlinkResult = file_exists($file)
? (unlink($file) === true) ? 'deleted.' : 'could\'t deleted'
: ' file does not exist';
$output->writeln($file . ' ' . $unlinkResult);
}
}
}
21 changes: 13 additions & 8 deletions src/Cache/ClearViewData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

namespace Selami\Command\Cache;

use Selami\Console\Command as SelamiCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;

class ClearViewData extends SelamiCommand
class ClearViewData extends Command
{
private $config;

public function __construct(array $config, ?string $name = null)
{
$this->config = $config;
parent::__construct($name);
}

/**
* @inheritdoc
* @throws InvalidArgumentException
Expand All @@ -26,12 +34,10 @@ protected function configure() : void
*/
protected function execute(InputInterface $input, OutputInterface $output) : void
{
$config = $this->container->get('config');
$viewCachePath = $config['view'][$config['view']['type']]['cache'];
$viewCachePath = $this->config[$this->config['type']]['cache'];
$output->writeln('Files under '.$viewCachePath .' will be deleted.');
if ( (string) $viewCachePath !== '') {
$cachedViewFileFolders = glob($viewCachePath . '/*');
foreach ($cachedViewFileFolders as $folder) {
if ((string) $viewCachePath !== '') {
foreach (glob($viewCachePath . '/*') as $folder) {
$files = glob($folder . '/*');
$output->writeln('Files under ' . $folder . ' will be deleted.');
foreach ($files as $file) {
Expand All @@ -45,6 +51,5 @@ protected function execute(InputInterface $input, OutputInterface $output) : voi
}
}
$output->writeln($viewCachePath .' emptied.');

}
}
14 changes: 10 additions & 4 deletions src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

namespace Selami\Command;

use Selami\Console\Command as SelamiCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;

class Info extends SelamiCommand
class Info extends Command
{
private $config;
public function __construct(array $config, ?string $name = null)
{
$this->config = $config;
parent::__construct($name);
}

/**
* @inheritdoc
* @throws InvalidArgumentException
Expand All @@ -26,7 +33,6 @@ protected function configure() : void
*/
protected function execute(InputInterface $input, OutputInterface $output) : void
{
$config = $this->container->get(Config::class);
$output->writeln(json_encode($config->toArray(), JSON_PRETTY_PRINT));
$output->writeln(json_encode($this->config, JSON_PRETTY_PRINT));
}
}
22 changes: 17 additions & 5 deletions src/Server/ServerRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,34 @@ protected function execute(InputInterface $input, OutputInterface $output) : voi
$publicFolder = $input->getOption('public');

$output->writeln(' ');
$output->writeln('<comment>-----------------------------SELAMI WEB SERVER-----------------------------------</comment>');
$output->writeln(
'<comment>-----------------------------'
. 'SELAMI WEB SERVER'
. '-----------------------------------</comment>'
);
$output->writeln(' ');

$output->writeln(' <comment>Usage:</comment>');
$output->writeln(' selami server:run [options]');
$output->writeln(' ');

$output->writeln(' <comment>Available Options:</comment>');
$output->writeln(' <info>--host </info> Sets host name. <comment>Default: 127.0.0.1</comment>');
$output->writeln(' <info>--public</info> Sets public folder that server will be run. <comment>Default: ./public</comment>');
$output->writeln(' <info>--host </info>'
. ' Sets host name. <comment>Default: 127.0.0.1</comment>');
$output->writeln(' <info>--public</info> '
. 'Sets public folder that server will be run. <comment>Default: ./public</comment>');
$output->writeln(' ');

$output->writeln('<comment>---------------------------------------------------------------------------------</comment>');
$output->writeln('<comment>-------------------------------------------'
. '--------------------------------------</comment>');
$output->writeln(' ');

$output->writeln('Starting Selami Skeleton App local web server from port 8080 on 127.0.0.1 at '.$publicFolder);
$output->writeln(
sprintf(
'Starting Selami Skeleton App local web server from port 8080 on 127.0.0.1 at %s',
$publicFolder
)
);
$process = new Process('php -S ' . $hostName . ':8080 -t ' . $publicFolder);
$process->setTimeout(null);
$process->run();
Expand Down

0 comments on commit 413b4bf

Please sign in to comment.