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

Commit 413b4bf

Browse files
committed
Refactored to be compatible symfony/console 1.0
1 parent 260a664 commit 413b4bf

File tree

7 files changed

+70
-39
lines changed

7 files changed

+70
-39
lines changed

composer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
"description": " Build in commands for Selami.",
44
"type": "library",
55
"require": {
6-
"selami/console": "^0.3",
7-
"symfony/process": "^4.1"
6+
"php": "^7.2",
7+
"ext-json": "*",
8+
"symfony/console": "^4.2",
9+
"symfony/process": "^4.2",
10+
"selami/console": "^1.0"
11+
},
12+
"require-dev": {
13+
"squizlabs/php_codesniffer": "^3.3",
14+
"object-calisthenics/phpcs-calisthenics-rules": "^3.3"
815
},
916
"license": "MIT",
1017
"authors": [
@@ -18,5 +25,10 @@
1825
"psr-4": {
1926
"Selami\\Command\\": "src/"
2027
}
28+
},
29+
"scripts": {
30+
"phpcs": "vendor/bin/phpcs --standard=PSR2 src ",
31+
"phpcbf": "vendor/bin/phpcbf --standard=PSR2 src ",
32+
"phpcs-object-calisthenics": "vendor/bin/phpcs src -sp --standard=vendor/object-calisthenics/phpcs-calisthenics-rules/src/ObjectCalisthenics/ruleset.xml"
2133
}
2234
}

src/Cache/ClearAll.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
namespace Selami\Command\Cache;
55

6-
use Selami\Console\Command as SelamiCommand;
6+
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Exception\CommandNotFoundException;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Console\Input\ArrayInput;
1111
use Symfony\Component\Console\Exception\InvalidArgumentException;
1212

13-
class ClearAll extends SelamiCommand
13+
class ClearAll extends Command
1414
{
15-
1615
protected static $availableCommands = [
1716
'cache:clear-config',
1817
'cache:clear-routes',

src/Cache/ClearConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
namespace Selami\Command\Cache;
55

6-
use Selami\Console\Command as SelamiCommand;
6+
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
99
use Symfony\Component\Console\Exception\InvalidArgumentException;
1010

11-
class ClearConfig extends SelamiCommand
11+
class ClearConfig extends Command
1212
{
1313
/**
1414
* @inheritdoc

src/Cache/ClearRouteDispatcherData.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
namespace Selami\Command\Cache;
55

6-
use Selami\Console\Command as SelamiCommand;
6+
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
99
use Symfony\Component\Console\Exception\InvalidArgumentException;
10+
use function dirname;
1011

11-
class ClearRouteDispatcherData extends SelamiCommand
12+
class ClearRouteDispatcherData extends Command
1213
{
1314
/**
1415
* @inheritdoc
@@ -26,18 +27,14 @@ protected function configure() : void
2627
*/
2728
protected function execute(InputInterface $input, OutputInterface $output) : void
2829
{
29-
$config = $this->container->get('config');
30-
$routeCacheFile = $config['app']['cache_file'] ?? '';
31-
if (trim((string) $routeCacheFile) !== '') {
32-
$folder = dirname($routeCacheFile);
33-
$files = glob($folder . '/*fastroute.cache');
34-
$output->writeln('Fastroute cache files under ' . $folder . ' will be deleted.');
35-
foreach ($files as $file) {
36-
$unlinkResult = file_exists($file)
37-
? (unlink($file) === true) ? 'deleted.' : 'could\'t deleted'
38-
: ' file does not exist';
39-
$output->writeln($file . ' ' . $unlinkResult);
40-
}
41-
}
30+
$folder = dirname('cache');
31+
$files = glob($folder . '/*fastroute.cache');
32+
$output->writeln('FastRoute cache files under ' . $folder . ' will be deleted.');
33+
foreach ($files as $file) {
34+
$unlinkResult = file_exists($file)
35+
? (unlink($file) === true) ? 'deleted.' : 'could\'t deleted'
36+
: ' file does not exist';
37+
$output->writeln($file . ' ' . $unlinkResult);
38+
}
4239
}
4340
}

src/Cache/ClearViewData.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33

44
namespace Selami\Command\Cache;
55

6-
use Selami\Console\Command as SelamiCommand;
6+
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
99
use Symfony\Component\Console\Exception\InvalidArgumentException;
1010

11-
class ClearViewData extends SelamiCommand
11+
class ClearViewData extends Command
1212
{
13+
private $config;
14+
15+
public function __construct(array $config, ?string $name = null)
16+
{
17+
$this->config = $config;
18+
parent::__construct($name);
19+
}
20+
1321
/**
1422
* @inheritdoc
1523
* @throws InvalidArgumentException
@@ -26,12 +34,10 @@ protected function configure() : void
2634
*/
2735
protected function execute(InputInterface $input, OutputInterface $output) : void
2836
{
29-
$config = $this->container->get('config');
30-
$viewCachePath = $config['view'][$config['view']['type']]['cache'];
37+
$viewCachePath = $this->config[$this->config['type']]['cache'];
3138
$output->writeln('Files under '.$viewCachePath .' will be deleted.');
32-
if ( (string) $viewCachePath !== '') {
33-
$cachedViewFileFolders = glob($viewCachePath . '/*');
34-
foreach ($cachedViewFileFolders as $folder) {
39+
if ((string) $viewCachePath !== '') {
40+
foreach (glob($viewCachePath . '/*') as $folder) {
3541
$files = glob($folder . '/*');
3642
$output->writeln('Files under ' . $folder . ' will be deleted.');
3743
foreach ($files as $file) {
@@ -45,6 +51,5 @@ protected function execute(InputInterface $input, OutputInterface $output) : voi
4551
}
4652
}
4753
$output->writeln($viewCachePath .' emptied.');
48-
4954
}
5055
}

src/Info.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33

44
namespace Selami\Command;
55

6-
use Selami\Console\Command as SelamiCommand;
6+
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
99
use Symfony\Component\Console\Exception\InvalidArgumentException;
1010

11-
class Info extends SelamiCommand
11+
class Info extends Command
1212
{
13+
private $config;
14+
public function __construct(array $config, ?string $name = null)
15+
{
16+
$this->config = $config;
17+
parent::__construct($name);
18+
}
19+
1320
/**
1421
* @inheritdoc
1522
* @throws InvalidArgumentException
@@ -26,7 +33,6 @@ protected function configure() : void
2633
*/
2734
protected function execute(InputInterface $input, OutputInterface $output) : void
2835
{
29-
$config = $this->container->get(Config::class);
30-
$output->writeln(json_encode($config->toArray(), JSON_PRETTY_PRINT));
36+
$output->writeln(json_encode($this->config, JSON_PRETTY_PRINT));
3137
}
3238
}

src/Server/ServerRun.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,34 @@ protected function execute(InputInterface $input, OutputInterface $output) : voi
4343
$publicFolder = $input->getOption('public');
4444

4545
$output->writeln(' ');
46-
$output->writeln('<comment>-----------------------------SELAMI WEB SERVER-----------------------------------</comment>');
46+
$output->writeln(
47+
'<comment>-----------------------------'
48+
. 'SELAMI WEB SERVER'
49+
. '-----------------------------------</comment>'
50+
);
4751
$output->writeln(' ');
4852

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

5357
$output->writeln(' <comment>Available Options:</comment>');
54-
$output->writeln(' <info>--host </info> Sets host name. <comment>Default: 127.0.0.1</comment>');
55-
$output->writeln(' <info>--public</info> Sets public folder that server will be run. <comment>Default: ./public</comment>');
58+
$output->writeln(' <info>--host </info>'
59+
. ' Sets host name. <comment>Default: 127.0.0.1</comment>');
60+
$output->writeln(' <info>--public</info> '
61+
. 'Sets public folder that server will be run. <comment>Default: ./public</comment>');
5662
$output->writeln(' ');
5763

58-
$output->writeln('<comment>---------------------------------------------------------------------------------</comment>');
64+
$output->writeln('<comment>-------------------------------------------'
65+
. '--------------------------------------</comment>');
5966
$output->writeln(' ');
6067

61-
$output->writeln('Starting Selami Skeleton App local web server from port 8080 on 127.0.0.1 at '.$publicFolder);
68+
$output->writeln(
69+
sprintf(
70+
'Starting Selami Skeleton App local web server from port 8080 on 127.0.0.1 at %s',
71+
$publicFolder
72+
)
73+
);
6274
$process = new Process('php -S ' . $hostName . ':8080 -t ' . $publicFolder);
6375
$process->setTimeout(null);
6476
$process->run();

0 commit comments

Comments
 (0)