Skip to content

Commit 57a8b31

Browse files
committed
Merged release/0.1.2 into master
2 parents 92fc52f + 244cbe5 commit 57a8b31

20 files changed

+313
-142
lines changed

bootstrap/function.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,55 @@ function test($output, $optional = null)
355355
}
356356
return $optional;
357357
}
358+
359+
/**
360+
* @param array $argv
361+
* @return array
362+
*/
363+
function argv(array $argv): array
364+
{
365+
array_shift($argv);
366+
367+
$parameters = [];
368+
foreach ($argv as $arg) {
369+
$parameter = explode('=', $arg);
370+
$value = $parameter[0];
371+
if (count($parameter) === 2) {
372+
$parameters[$value] = $parameter[1];
373+
continue;
374+
}
375+
$parameters[] = $value;
376+
}
377+
return $parameters;
378+
}
379+
380+
/**
381+
* @param string $camelCase
382+
* @return string
383+
*/
384+
function dasherize(string $camelCase): string
385+
{
386+
$dashes = preg_replace_callback('/([A-Z])/',
387+
create_function('$matches', 'return \'-\' . strtolower($matches[1]);'), $camelCase
388+
);
389+
return substr($dashes, 1);
390+
}
391+
392+
/**
393+
* @param string $dashes
394+
* @param bool $first
395+
* @return mixed
396+
* @SuppressWarnings("BooleanArgumentFlag")
397+
*/
398+
function camelize(string $dashes, $first = true): string
399+
{
400+
$camelCase = preg_replace_callback('/-(.)/',
401+
create_function('$matches', 'return strtoupper($matches[1]);'), $dashes
402+
);
403+
$case = 'strtoupper';
404+
if (!$first) {
405+
$case = 'strtolower';
406+
}
407+
$camelCase[0] = $case($camelCase[0]);
408+
return (string)$camelCase;
409+
}

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"homepage": "https://github.com/phpzm/core",
1212
"license": "MIT",
13-
"version": "0.1.1",
13+
"version": "0.1.2",
1414
"type": "package",
1515
"authors": [
1616
{"name": "William", "email": "wilcorrea@gmail.com"},
@@ -19,7 +19,6 @@
1919
"require": {
2020
"php": ">=7.0",
2121
"psr/http-message": "^1.0",
22-
"danielstjules/stringy": "^2.3",
2322
"phpmailer/phpmailer": "^5.2",
2423
"neitanod/forceutf8": "^2.0"
2524
},

src/Console/GeneratorService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ abstract class GeneratorService extends Service
2222

2323
/**
2424
* @param App $app
25+
* @param array $parameters
26+
* @SuppressWarnings("unused")
2527
*/
26-
public static function execute(App $app)
28+
public static function execute(App $app, array $parameters = [])
2729
{
2830
$option = '';
2931
do {

src/Console/HelpService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ abstract class HelpService extends Service
1212
{
1313
/**
1414
* @param App $app
15+
* @param array $parameters
1516
* @SuppressWarnings("unused")
1617
*/
17-
public static function execute(App $app)
18+
public static function execute(App $app, array $parameters = [])
1819
{
1920
echo " # HELP\n";
2021
echo " Choose one option:\n";

src/Console/MigratoryService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class MigratoryService extends Service
1414
{
1515
/**
1616
* @param App $app
17+
* @param array $parameters
1718
* @SuppressWarnings("unused")
1819
*/
19-
public static function execute(App $app)
20+
public static function execute(App $app, array $parameters = [])
2021
{
2122
// TODO: Implement execute() method.
2223
}

src/Console/RouteService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ abstract class RouteService extends Service
1414
{
1515
/**
1616
* @param App $app
17+
* @param array $parameters
18+
* @SuppressWarnings("unused")
1719
*/
18-
public static function execute(App $app)
20+
public static function execute(App $app, array $parameters = [])
1921
{
2022
$router = new Router($app::options('labels'), $app::options('type'));
2123

src/Console/Service.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class Service
1717

1818
/**
1919
* @param App $app
20+
* @param array $parameters
2021
*/
21-
abstract public static function execute(App $app);
22+
abstract public static function execute(App $app, array $parameters = []);
2223
}

src/Data/Validator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Simples\Core\Data\Validators\NumberValidator;
1010
use Simples\Core\Data\Validators\StringValidator;
1111
use Simples\Core\Helper\JSON;
12-
use Stringy\Stringy;
1312

1413
/**
1514
* Class Validator
@@ -75,7 +74,7 @@ public static function rule($criteria, $value): array
7574
*/
7675
public function apply(string $rule, $value, $options): bool
7776
{
78-
$method = (string)Stringy::create("is-{$rule}")->camelize();
77+
$method = camelize("is-{$rule}");
7978
if (method_exists($this, $method)) {
8079
return $this->$method($value, $options);
8180
}

src/Http/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ abstract class Controller
9393
* @param Match $match
9494
* @return $this
9595
*/
96-
public function __invoke(Request $request, Response $response, Match $match)
96+
public final function boot(Request $request, Response $response, Match $match)
9797
{
9898
$this->request = $request;
9999
$this->response = $response;

src/Kernel/App.php

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
namespace Simples\Core\Kernel;
44

55
use ErrorException;
6-
use Simples\Core\Console\ControllerService;
7-
use Simples\Core\Console\HelpService;
8-
use Simples\Core\Console\ModelService;
9-
use Simples\Core\Console\RepositoryService;
10-
use Simples\Core\Console\RouteService;
11-
use Simples\Core\Console\Service;
126
use Simples\Core\Http\Request;
137
use Simples\Core\Http\Response;
148
use Simples\Core\Persistence\Transaction;
@@ -137,40 +131,11 @@ public function http($output = true)
137131
/**
138132
* Handler to cli services, provide a interface to access services
139133
*
140-
* @param string $service The requested service
134+
* @param array $service The requested service
141135
*/
142-
public function cli($service)
136+
public function cli(array $service)
143137
{
144-
echo "@start/\n";
145-
echo "Press ^C or type 'exit' at any time to quit.\n";
146-
147-
do {
148-
switch ($service) {
149-
case 'route': {
150-
RouteService::execute($this);
151-
$service = '';
152-
break;
153-
}
154-
case 'model': {
155-
ModelService::execute($this);
156-
$service = '';
157-
break;
158-
}
159-
case 'controller':
160-
ControllerService::execute($this);
161-
$service = '';
162-
break;
163-
case 'repository':
164-
RepositoryService::execute($this);
165-
$service = '';
166-
break;
167-
};
168-
if (!$service || $service === 'help') {
169-
HelpService::execute($this);
170-
}
171-
172-
$service = read();
173-
} while (!in_array($service, Service::KILLERS));
138+
Console::handler($this, $service);
174139
}
175140

176141
/**

0 commit comments

Comments
 (0)