Skip to content

Commit 8c30135

Browse files
lablnetMaikuolan
andauthored
console (#325)
* console * update * update * fix typo * Update Console.php * fix styleci complains * fix styleci complains * update * update * update * StyleCI fixes. (#343) * update * update * parse flags Co-authored-by: Caleb Mazalevskis <maikuolan@gmail.com>
1 parent 9f0edfc commit 8c30135

File tree

15 files changed

+1350
-164
lines changed

15 files changed

+1350
-164
lines changed

src/Console/Code.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Console/Colorize.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Zest Framework.
5+
*
6+
* @author Muhammad Umer Farooq (Malik) <mumerfarooqlablnet01@gmail.com>
7+
*
8+
* @link https://github.com/zestframework/Zest_Framework
9+
*
10+
* @author Muhammad Umer Farooq <lablnet01@gmail.com>
11+
* @author-profile https://www.facebook.com/Muhammadumerfarooq01/
12+
*
13+
* For the full copyright and license information, please view the LICENSE
14+
* file that was distributed with this source code.
15+
*
16+
* @license MIT
17+
*/
18+
19+
namespace Zest\Console;
20+
21+
use Zest\Data\Arrays;
22+
23+
class Colorize
24+
{
25+
/**
26+
* Foregroud colors.
27+
*
28+
* @since 3.0.0
29+
*
30+
* @var array
31+
*/
32+
public $styles = [
33+
'bold' => '1m',
34+
'faded' => '2m',
35+
'underlined' => '4m',
36+
'blinking' => '5m',
37+
'reversed' => '7m',
38+
'hidden' => '8m',
39+
'red' => '31m',
40+
'green' => '32m',
41+
'yellow' => '33m',
42+
'blue' => '34m',
43+
'magenta' => '35m',
44+
'cyan' => '36m',
45+
'light_gray' => '37m',
46+
'dark_gray' => '90m',
47+
'white' => '0m',
48+
'bg:red' => '41m',
49+
'bg:green' => '42m',
50+
'bg:yellow' => '53m',
51+
'bg:blue' => '44m',
52+
'bg:magenta' => '45m',
53+
'bg:cyan' => '46m',
54+
'bg:light_gray' => '47m',
55+
'bg:dark_gray' => '100m',
56+
'bg:white' => '0m',
57+
];
58+
59+
/**
60+
* Get the color by key.
61+
*
62+
* @param string $color Color key
63+
* @param bool $background
64+
*
65+
* @since 3.0.0
66+
*
67+
* @var string
68+
*/
69+
public function get(string $style)
70+
{
71+
if (Arrays::has($this->styles, $style, '.')) {
72+
return Arrays::get($this->styles, $style, '.');
73+
}
74+
}
75+
}

src/Console/Command.php

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Zest Framework.
5+
*
6+
* @author Muhammad Umer Farooq (Malik) <mumerfarooqlablnet01@gmail.com>
7+
*
8+
* @link https://github.com/zestframework/Zest_Framework
9+
*
10+
* @author Muhammad Umer Farooq <lablnet01@gmail.com>
11+
* @author-profile https://www.facebook.com/Muhammadumerfarooq01/
12+
*
13+
* For the full copyright and license information, please view the LICENSE
14+
* file that was distributed with this source code.
15+
*
16+
* @license MIT
17+
*/
18+
19+
namespace Zest\Console;
20+
21+
abstract class Command
22+
{
23+
/**
24+
* Sign of the command.
25+
*
26+
* @since 3.0.0
27+
*
28+
* @var string
29+
*/
30+
protected $sign;
31+
32+
/**
33+
* Description of the command.
34+
*
35+
* @since 3.0.0
36+
*
37+
* @var string
38+
*/
39+
protected $description;
40+
41+
/**
42+
* Should the command hidden form list.
43+
*
44+
* @since 3.0.0
45+
*
46+
* @var bool
47+
*/
48+
protected $hidden = false;
49+
50+
/**
51+
* Accpet flag parameter in command.
52+
*
53+
* @since 3.0.0
54+
*
55+
* @var array
56+
*/
57+
protected $flags = [];
58+
59+
/**
60+
* Create a new command instance.
61+
*
62+
* @return void
63+
*/
64+
public function __construct()
65+
{
66+
//todo
67+
}
68+
69+
/**
70+
* Get hidden.
71+
*
72+
* @return string
73+
*/
74+
public function getHidden(): bool
75+
{
76+
return $this->hidden;
77+
}
78+
79+
/**
80+
* Get sign.
81+
*
82+
* @return string
83+
*/
84+
public function getSign(): string
85+
{
86+
return $this->sign ?? '';
87+
}
88+
89+
/**
90+
* Get description.
91+
*
92+
* @return string
93+
*/
94+
public function getDescription(): string
95+
{
96+
return $this->description ?? '';
97+
}
98+
99+
/**
100+
* Get flags.
101+
*
102+
* @return array
103+
*/
104+
public function getFlags(): array
105+
{
106+
return $this->flags ?? [];
107+
}
108+
109+
/**
110+
* Function to handle the class.
111+
*
112+
* @param string $str
113+
* @param bool $newLine
114+
*
115+
* @return void
116+
*/
117+
public function write(string $str, bool $newLine = true)
118+
{
119+
(new Output())->write($str, $newLine);
120+
}
121+
122+
/**
123+
* Prompt user for input.
124+
*
125+
* @param string $str
126+
*
127+
* @return void
128+
*/
129+
public function ask(string $str)
130+
{
131+
$this->write("<white>$str</white>", false);
132+
133+
return (new Input())->ask();
134+
}
135+
136+
/**
137+
* Terminate the console.
138+
*
139+
* @return void
140+
*/
141+
public function terminate(): void
142+
{
143+
exit();
144+
}
145+
146+
/**
147+
* Function to handle the class.
148+
*
149+
* @param \Zest\Console\Output $output
150+
* @param \Zest\Console\Input $input
151+
* @param array $param
152+
*
153+
* @return void
154+
*/
155+
abstract public function handle(Output $output, Input $input, $prams = []): void;
156+
}

src/Console/Commands.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Zest Framework.
5+
*
6+
* @author Muhammad Umer Farooq (Malik) <mumerfarooqlablnet01@gmail.com>
7+
*
8+
* @link https://github.com/zestframework/Zest_Framework
9+
*
10+
* @author Muhammad Umer Farooq <lablnet01@gmail.com>
11+
* @author-profile https://www.facebook.com/Muhammadumerfarooq01/
12+
*
13+
* For the full copyright and license information, please view the LICENSE
14+
* file that was distributed with this source code.
15+
*
16+
* @license MIT
17+
*/
18+
19+
namespace Zest\Console;
20+
21+
class Commands
22+
{
23+
/**
24+
* Internal commands.
25+
*
26+
* @since 3.0.0
27+
*
28+
* @var array
29+
*/
30+
protected $commands = [
31+
['version', \Zest\Console\Commands\Version::class],
32+
['list', \Zest\Console\Commands\ListCmd::class],
33+
['make:controller', \Zest\Console\Commands\Controller::class],
34+
['clear:cache', \Zest\Console\Commands\Cache::class],
35+
['serve', \Zest\Console\Commands\ServeCommand::class],
36+
37+
];
38+
39+
/**
40+
* Get commands.
41+
*
42+
* @since 3.0.0
43+
*
44+
* @var array
45+
*/
46+
public function getCommands(): array
47+
{
48+
return $this->commands;
49+
}
50+
}

0 commit comments

Comments
 (0)