Skip to content

Commit 396265d

Browse files
committed
commander bugs fixing
1 parent 3cff6ae commit 396265d

File tree

7 files changed

+55
-52
lines changed

7 files changed

+55
-52
lines changed

src/Cli/Abstracts/AbstractCommander.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ protected function __callOptions()
275275
*/
276276
public function execute()
277277
{
278-
$this->optionHelp();
278+
$this->__callOptions();
279279
}
280280

281281
// ------------------------------------------------------------------------

src/Cli/Router.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// ------------------------------------------------------------------------
1717

1818
use O2System\Kernel\Cli\Router\DataStructures\Commander;
19+
use O2System\Spl\Traits\Collectors\FilePathCollectorTrait;
1920

2021
/**
2122
* Class Router
@@ -24,6 +25,8 @@
2425
*/
2526
class Router
2627
{
28+
use FilePathCollectorTrait;
29+
2730
/**
2831
* Router::$string
2932
*
@@ -51,6 +54,13 @@ class Router
5154
*/
5255
protected $commander;
5356

57+
// -----------------------------------------------------------------------
58+
59+
public function __construct()
60+
{
61+
$this->setFileDirName('Commanders');
62+
}
63+
5464
// -----------------------------------------------------------------------
5565

5666
/**
@@ -149,12 +159,8 @@ protected function parseCommands(array $commands)
149159
{
150160
$numCommands = count($commands);
151161
$commanderRegistry = null;
152-
$commandersDirectories = [
153-
defined('PATH_REACTOR') ? PATH_REACTOR . 'Cli' . DIRECTORY_SEPARATOR . 'Commanders' . DIRECTORY_SEPARATOR : PATH_FRAMEWORK . 'Cli' . DIRECTORY_SEPARATOR . 'Commanders' . DIRECTORY_SEPARATOR,
154-
PATH_APP . 'Commanders' . DIRECTORY_SEPARATOR
155-
];
156162

157-
$commandersDirectories = modules()->getDirs('Commanders');
163+
$commandersDirectories = $this->getFilePaths(true);
158164

159165
for ($i = 0; $i <= $numCommands; $i++) {
160166
$routedCommands = array_slice($commands, 0, ($numCommands - $i));

src/Http/Message/Uri.php

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,24 @@ public function __construct($httpStringRequest = null)
132132

133133
$this->domain = new Domain($httpStringRequest);
134134

135-
if (isset($parseUrl[ 'path' ])) {
136-
$xRequest = explode('/', $parseUrl[ 'path' ]);
135+
if (isset($parseUrl['path'])) {
136+
$xRequest = explode('/', $parseUrl['path']);
137137
$this->path = implode('/', array_slice($xRequest, 1));
138138
}
139139

140140
if (strpos($this->path, '.php') !== false) {
141141
$xPath = explode('.php', $this->path);
142-
$xPath = explode('/', trim($xPath[ 0 ], '/'));
142+
$xPath = explode('/', trim($xPath[0], '/'));
143143
array_pop($xPath);
144144

145145
$this->path = empty($xPath) ? null : implode('/', $xPath);
146146
}
147147

148-
$this->query = isset($parseUrl[ 'query' ]) ? $parseUrl[ 'query' ] : null;
149-
$this->username = isset($parseUrl[ 'user' ]) ? $parseUrl[ 'user' ] : null;
150-
$this->password = isset($parseUrl[ 'pass' ]) ? $parseUrl[ 'pass' ] : null;
151-
$this->port = isset($parseUrl[ 'port' ]) ? $parseUrl[ 'port' ] : 80;
152-
$this->fragment = isset($parseUrl[ 'fragment' ]) ? $parseUrl[ 'fragment' ] : null;
148+
$this->query = isset($parseUrl['query']) ? $parseUrl['query'] : null;
149+
$this->username = isset($parseUrl['user']) ? $parseUrl['user'] : null;
150+
$this->password = isset($parseUrl['pass']) ? $parseUrl['pass'] : null;
151+
$this->port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
152+
$this->fragment = isset($parseUrl['fragment']) ? $parseUrl['fragment'] : null;
153153

154154
$this->segments = new Segments($this->path);
155155
} else {
@@ -159,47 +159,41 @@ public function __construct($httpStringRequest = null)
159159
/**
160160
* Define Uri Attribute
161161
*/
162-
if (strpos($_SERVER[ 'PHP_SELF' ], '/@') !== false) {
163-
$xPhpSelf = explode('/@', $_SERVER[ 'PHP_SELF' ]);
162+
if (strpos($_SERVER['PHP_SELF'], '/@') !== false) {
163+
$xPhpSelf = explode('/@', $_SERVER['PHP_SELF']);
164164

165-
$this->attribute = '@' . $xPhpSelf[ 1 ];
165+
$this->attribute = '@' . $xPhpSelf[1];
166166

167167
if (strpos($this->attribute, '/') !== false) {
168168
$xAttribute = explode('/', $this->attribute);
169169

170-
$this->attribute = $xAttribute[ 0 ];
170+
$this->attribute = $xAttribute[0];
171171
}
172172
}
173173

174174
/**
175175
* Define Uri User and Password
176176
*/
177-
if (preg_match("/[a-zA-Z0-9]+[@][a-zA-Z0-9]+/", $_SERVER[ 'PHP_SELF' ], $usernamePassword)) {
178-
$xUsernamePassword = explode('@', $usernamePassword[ 0 ]);
179-
$this->username = $xUsernamePassword[ 0 ];
180-
$this->password = $xUsernamePassword[ 1 ];
177+
if (preg_match("/[a-zA-Z0-9]+[@][a-zA-Z0-9]+/", $_SERVER['PHP_SELF'], $usernamePassword)) {
178+
$xUsernamePassword = explode('@', $usernamePassword[0]);
179+
$this->username = $xUsernamePassword[0];
180+
$this->password = $xUsernamePassword[1];
181181
}
182182

183183
/**
184184
* Define Uri Path
185185
*/
186-
$xPath = explode('.php', $_SERVER[ 'PHP_SELF' ]);
187-
$xPath = explode('/', trim($xPath[ 0 ], '/'));
188-
array_pop($xPath);
189-
190-
if(class_exists('O2System\Framework', false)) {
191-
if(!empty($xPath)) {
192-
$app = studlycase($xPath[0]);
193-
if(is_file(PATH_APP . $app . DIRECTORY_SEPARATOR . 'app.json')) {
194-
unset($xPath[0]);
195-
}
186+
if (!is_file(input()->server('DOCUMENT_ROOT') . input()->server('PHP_SELF'))) {
187+
$this->path = null;
188+
} else {
189+
$this->path = input()->server('PHP_SELF');
190+
191+
if ($this->path === '/index.php') {
192+
$this->path = null;
196193
}
197194
}
198195

199-
$this->path = empty($xPath) ? null : implode('/', $xPath) . '/';
200-
201-
$this->query = isset($_SERVER[ 'QUERY_STRING' ]) ? $_SERVER[ 'QUERY_STRING' ] : null;
202-
196+
$this->query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
203197
}
204198
}
205199

@@ -244,7 +238,7 @@ public function withSegments(Segments $segments)
244238
*/
245239
public function addSegments($segments)
246240
{
247-
if ( ! $segments instanceof Segments) {
241+
if (!$segments instanceof Segments) {
248242
$segments = new Segments($segments);
249243
}
250244

@@ -310,11 +304,11 @@ public function getAuthority()
310304

311305
$authority = $this->getHost();
312306

313-
if ( ! empty($this->getUserInfo())) {
307+
if (!empty($this->getUserInfo())) {
314308
$authority = $this->getUserInfo() . '@' . $authority;
315309
}
316310

317-
if ( ! empty($this->getPort())) {
311+
if (!empty($this->getPort())) {
318312
if ($this->getPort() != 80) {
319313
$authority .= ':' . $this->getPort();
320314
}
@@ -346,7 +340,7 @@ public function getUserInfo()
346340
{
347341
$userInfo = $this->username;
348342

349-
if ( ! empty($this->password)) {
343+
if (!empty($this->password)) {
350344
$userInfo .= ':' . $this->password;
351345
}
352346

@@ -609,7 +603,7 @@ public function withScheme($scheme)
609603
* user; an empty string for the user is equivalent to removing user
610604
* information.
611605
*
612-
* @param string $user The user name to use for authority.
606+
* @param string $user The user name to use for authority.
613607
* @param null|string $password The password associated with $user.
614608
*
615609
* @return static|\O2System\Kernel\Http\Message\Uri A new instance with the specified user information.
@@ -773,15 +767,16 @@ public function addQuery($query)
773767

774768
parse_str($query, $newQuery);
775769

776-
if ( ! empty($uri->query)) {
770+
if (!empty($uri->query)) {
777771
parse_str($uri->query, $oldQuery);
778772
$query = array_merge($oldQuery, $newQuery);
779773
} else {
780774
$query = $newQuery;
781775
}
782776

783777
if (is_array($query)) {
784-
$uri->query = is_array($query) ? http_build_query($query, PHP_QUERY_RFC3986, '&', PHP_QUERY_RFC3986) : $query;
778+
$uri->query = is_array($query) ? http_build_query($query, PHP_QUERY_RFC3986, '&',
779+
PHP_QUERY_RFC3986) : $query;
785780
}
786781

787782
return $uri;
@@ -907,7 +902,7 @@ public function __toString()
907902
if ($uriPath !== '/' &&
908903
substr($uriPath, strlen($uriPath) - 1) !== '/' &&
909904
$this->suffix !== '' && $this->suffix !== '.' &&
910-
( ! is_cli() && $uriPath . '/' !== $_SERVER[ 'REQUEST_URI' ]) &&
905+
(!is_cli() && $uriPath . '/' !== $_SERVER['REQUEST_URI']) &&
911906
pathinfo($uriPath, PATHINFO_EXTENSION) === '' &&
912907
strpos($uriPath, '#') === false &&
913908
empty($this->query)
@@ -927,6 +922,8 @@ public function __toString()
927922
? ''
928923
: $this->fragment;
929924

925+
$uriString = str_replace(['https://.', 'http://.'], ['https://', 'http://'], $uriString);
926+
930927
return $uriString;
931928
}
932929
}

src/Http/Message/Uri/Domain.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,11 @@ public function setSubDomain($subDomains)
343343
}
344344

345345
$this->subDomains = [];
346-
foreach($subDomains as $subDomain) {
347-
$this->addSubDomain($subDomain);
346+
347+
if(count($subDomains)) {
348+
foreach($subDomains as $subDomain) {
349+
$this->addSubDomain($subDomain);
350+
}
348351
}
349352
}
350353

@@ -491,9 +494,7 @@ public function getNumOfTlds()
491494
public function __toString()
492495
{
493496
if(count($this->subDomains)) {
494-
return implode('.', $this->subDomains) . '.' . str_replace(array_map(function($subDomain){
495-
return $subDomain . '.';
496-
}, $this->subDomains), '', $this->mainDomain);
497+
return implode('.', array_merge(array_filter($this->subDomains), [$this->mainDomain]));
497498
}
498499

499500
return $this->host;

src/Http/Output.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public function send($data = null, array $headers = [])
306306
$response = [
307307
'status' => $statusCode = $this->statusCode,
308308
'reason' => $reasonPhrase = readable($this->reasonPhrase),
309+
'timestamp' => gmdate('D, d M Y H:i:s e', time()),
309310
'success' => true,
310311
'message' => null,
311312
'result' => [],

src/Kernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ protected function __construct()
7373
$this->services->load($className, $classOffset);
7474
}
7575

76-
if (class_exists('O2System\Framework', false) or class_exists(
77-
'O2System\Reactor', false)) {
76+
if (class_exists('O2System\Framework', false)) {
7877
if (profiler() !== false) {
7978
profiler()->watch('Starting Kernel I/O Service');
8079
}

src/Services/Language.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public function loadFile($filenames)
149149
}
150150

151151
foreach ($filenames as $filename) {
152-
$filename = dash($filename);
153152
if ( ! $this->isLoaded($filename)) {
154153
if (is_file($filename)) {
155154
$this->parseFile($filename);

0 commit comments

Comments
 (0)