Skip to content

Commit 3cff6ae

Browse files
committed
uri bugs fixing
1 parent 36912bb commit 3cff6ae

File tree

6 files changed

+79
-47
lines changed

6 files changed

+79
-47
lines changed

src/Cli/Abstracts/AbstractCommander.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,7 @@ protected function __callOptions()
275275
*/
276276
public function execute()
277277
{
278-
$this->__callOptions();
279-
280-
if ($options = input()->get()) {
281-
$this->optionHelp();
282-
}
278+
$this->optionHelp();
283279
}
284280

285281
// ------------------------------------------------------------------------

src/Cli/Router.php

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

1818
use O2System\Kernel\Cli\Router\DataStructures\Commander;
19-
use O2System\Spl\Traits\Collectors\FilePathCollectorTrait;
2019

2120
/**
2221
* Class Router
@@ -25,8 +24,6 @@
2524
*/
2625
class Router
2726
{
28-
use FilePathCollectorTrait;
29-
3027
/**
3128
* Router::$string
3229
*
@@ -56,16 +53,6 @@ class Router
5653

5754
// -----------------------------------------------------------------------
5855

59-
/**
60-
* Router::__construct
61-
*/
62-
public function __construct()
63-
{
64-
$this->setFileDirName('Commanders');
65-
}
66-
67-
// -----------------------------------------------------------------------
68-
6956
/**
7057
* Router::handle
7158
*
@@ -162,7 +149,12 @@ protected function parseCommands(array $commands)
162149
{
163150
$numCommands = count($commands);
164151
$commanderRegistry = null;
165-
$commandersDirectories = $this->getFilePaths(true);
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+
];
156+
157+
$commandersDirectories = modules()->getDirs('Commanders');
166158

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

src/DataStructures/Input/Abstracts/AbstractInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected function filterVar($value)
247247
}
248248
}
249249
}
250-
250+
251251
return $value;
252252
}
253253

src/Helpers/Common.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,16 @@ function path_to_url($path)
311311
{
312312
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
313313
$root_dir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $_SERVER[ 'DOCUMENT_ROOT' ]);
314-
$base_dir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, dirname($_SERVER[ 'SCRIPT_FILENAME' ]));
314+
315+
if(strpos($_SERVER['SCRIPT_FILENAME'], 'server.php') !== false) {
316+
$base_dir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, dirname($_SERVER[ 'SCRIPT_FILENAME' ]));
317+
318+
if(is_dir($base_dir) . DIRECTORY_SEPARATOR . 'public') {
319+
$base_dir = $base_dir . DIRECTORY_SEPARATOR . 'public';
320+
}
321+
} else {
322+
$base_dir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, dirname($_SERVER[ 'SCRIPT_FILENAME' ]));
323+
}
315324

316325
$root_dir = rtrim($root_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
317326
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

src/Http/Message/UploadFile.php

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
// ------------------------------------------------------------------------
1717

18+
use O2System\Kernel\Http\Message\Uri\Path;
1819
use O2System\Psr\Http\Message\StreamInterface;
1920
use O2System\Psr\Http\Message\UploadedFileInterface;
2021
use O2System\Spl\Exceptions\Logic\BadFunctionCall\BadPhpExtensionCallException;
@@ -62,8 +63,8 @@ class UploadFile implements UploadedFileInterface
6263

6364
/**
6465
* UploadFile::$error
65-
*
66-
* @var mixed
66+
*
67+
* @var mixed
6768
*/
6869
protected $error;
6970

@@ -92,20 +93,20 @@ class UploadFile implements UploadedFileInterface
9293
*/
9394
public function __construct(array $uploadedFile)
9495
{
95-
if ( ! class_exists('finfo')) {
96+
if (!class_exists('finfo')) {
9697
throw new BadPhpExtensionCallException('E_HEADER_BADPHPEXTENSIONCALLEXCEPTION', 1);
9798
}
9899

99-
$this->name = $uploadedFile[ 'name' ];
100-
$this->type = $uploadedFile[ 'type' ];
101-
$this->tmpName = $uploadedFile[ 'tmp_name' ];
102-
$this->size = $uploadedFile[ 'size' ];
103-
$this->error = $uploadedFile[ 'error' ];
100+
$this->name = $uploadedFile['name'];
101+
$this->type = $uploadedFile['type'];
102+
$this->tmpName = $uploadedFile['tmp_name'];
103+
$this->size = $uploadedFile['size'];
104+
$this->error = $uploadedFile['error'];
104105

105106
if (defined('PATH_STORAGE')) {
106107
$this->path = PATH_STORAGE;
107108
} else {
108-
$this->path = dirname($_SERVER[ 'SCRIPT_FILENAME' ]) . DIRECTORY_SEPARATOR . $path;
109+
$this->path = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . $path;
109110
}
110111
}
111112

@@ -155,7 +156,7 @@ public function getStream()
155156
*
156157
* Sets target filename.
157158
*
158-
* @param string $name The target filename.
159+
* @param string $name The target filename.
159160
* @param string $conversionFunction Conversion function name, by default it's using dash inflector function.
160161
*
161162
* @return static
@@ -198,7 +199,7 @@ public function setPath($path = '')
198199
$this->path = PATH_STORAGE . str_replace(PATH_STORAGE, '', $path);
199200
}
200201
} else {
201-
$this->path = dirname($_SERVER[ 'SCRIPT_FILENAME' ]) . DIRECTORY_SEPARATOR . $path;
202+
$this->path = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . $path;
202203
}
203204
}
204205

@@ -262,17 +263,17 @@ public function store($path = null)
262263
*/
263264
public function moveTo($targetPath)
264265
{
265-
if ( ! $this->isMoved) {
266+
if (!$this->isMoved) {
266267
$filename = pathinfo($targetPath, PATHINFO_FILENAME);
267268
$filename = dash($filename);
268269

269270
$fileExtension = pathinfo($targetPath, PATHINFO_EXTENSION);
270271
$targetPath = pathinfo($targetPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR;
271-
$targetPath = str_replace(['\\','/'], DIRECTORY_SEPARATOR, $targetPath);
272+
$targetPath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $targetPath);
272273

273-
if ( ! is_file($filePath = $targetPath . $filename . '.' . $fileExtension)) {
274+
if (!is_file($filePath = $targetPath . $filename . '.' . $fileExtension)) {
274275
$targetPath = $filePath;
275-
} elseif ( ! is_file($filePath = $targetPath . $filename . '-1' . '.' . $fileExtension)) {
276+
} elseif (!is_file($filePath = $targetPath . $filename . '-1' . '.' . $fileExtension)) {
276277
$targetPath = $filePath;
277278
} else {
278279
$existingFiles = glob($targetPath . $filename . '*.' . $fileExtension);
@@ -281,32 +282,34 @@ public function moveTo($targetPath)
281282
}
282283

283284
foreach (range($increment + 1, $increment + 3, 1) as $increment) {
284-
if ( ! is_file($filePath = $targetPath . $filename . '-' . $increment . '.' . $fileExtension)) {
285+
if (!is_file($filePath = $targetPath . $filename . '-' . $increment . '.' . $fileExtension)) {
285286
$targetPath = $filePath;
286287
break;
287288
}
288289
}
289290
}
290291

291-
if ( ! is_writable(dirname($targetPath))) {
292+
if (!is_writable(dirname($targetPath))) {
292293
@mkdir(dirname($targetPath), 0777, true);
293294
}
294295

295296
if (strpos($targetPath, '://') !== false) {
296-
if ( ! copy($this->tmpName, $targetPath)) {
297-
throw new \RuntimeException(sprintf('Cant Move Uploaded File %1 to %2', $this->tmpName, $targetPath));
297+
if (!copy($this->tmpName, $targetPath)) {
298+
throw new \RuntimeException(sprintf('Cant Move Uploaded File %1 to %2', $this->tmpName,
299+
$targetPath));
298300
}
299301

300-
if ( ! unlink($this->tmpName)) {
302+
if (!unlink($this->tmpName)) {
301303
throw new \RuntimeException('Failed To Remove Uploaded Temp File');
302304
}
303305
} else {
304-
if ( ! is_uploaded_file($this->tmpName)) {
306+
if (!is_uploaded_file($this->tmpName)) {
305307
throw new \RuntimeException('File Is Not Valid Uploaded File');
306308
}
307309

308-
if ( ! move_uploaded_file($this->tmpName, $targetPath)) {
309-
throw new \RuntimeException(sprintf('Cant Move Uploaded File %1 to %2', $this->tmpName, $targetPath));
310+
if (!move_uploaded_file($this->tmpName, $targetPath)) {
311+
throw new \RuntimeException(sprintf('Cant Move Uploaded File %1 to %2', $this->tmpName,
312+
$targetPath));
310313
}
311314
}
312315

@@ -321,7 +324,7 @@ public function moveTo($targetPath)
321324

322325
/**
323326
* UploadFile::getName
324-
*
327+
*
325328
* @return string
326329
*/
327330
public function getName()
@@ -333,7 +336,7 @@ public function getName()
333336

334337
/**
335338
* UploadFile::getPath
336-
*
339+
*
337340
* @return string
338341
*/
339342
public function getPath()
@@ -437,7 +440,30 @@ public function getClientMediaType()
437440
*/
438441
public function getFileMime()
439442
{
440-
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->tmpName);
443+
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
444+
$mime = finfo_file($finfo, $this->tmpName);
445+
446+
if (empty($mime)) {
447+
if (function_exists('mime_content_type')) {
448+
$mime = mime_content_type($this->name);
449+
}
450+
}
451+
452+
if (empty($mime)) {
453+
$mimeTypes = require(PATH_KERNEL . 'Config' . DIRECTORY_SEPARATOR . 'Mimes.php');
454+
455+
if (array_key_exists($this->getExtension(), $mimeTypes)) {
456+
$mime = $mimeTypes[$this->getExtension()];
457+
458+
if (is_array($mime)) {
459+
$mime = reset($mimeTypes[$this->getExtension()]);
460+
}
461+
}
462+
}
463+
464+
if (empty($mime)) {
465+
$mime = empty($this->type) ? 'application/octet-stream' : $this->type;
466+
}
441467

442468
return $mime;
443469
}

src/Http/Message/Uri.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ public function __construct($httpStringRequest = null)
187187
$xPath = explode('/', trim($xPath[ 0 ], '/'));
188188
array_pop($xPath);
189189

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+
}
196+
}
197+
}
198+
190199
$this->path = empty($xPath) ? null : implode('/', $xPath) . '/';
191200

192201
$this->query = isset($_SERVER[ 'QUERY_STRING' ]) ? $_SERVER[ 'QUERY_STRING' ] : null;

0 commit comments

Comments
 (0)