Skip to content

Commit

Permalink
1. refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
scarwu committed Feb 7, 2022
1 parent 59dd4e5 commit 7bfba8d
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 51 deletions.
2 changes: 1 addition & 1 deletion example/Web/views/main/error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
use Oni\Web\Helper;
use Oni\Web\View\Helper;
?>
<h1><?=$title?></h1>
<p>Go to <?=Helper::linkTo('/', 'home')?></p>
2 changes: 1 addition & 1 deletion src/Oni/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final public function setAttr($key, $value)
*/
final public function getAttr($key)
{
return isset($this->_attr[$key])
return (true === isset($this->_attr[$key]))
? $this->_attr[$key] : null;
}
}
6 changes: 3 additions & 3 deletions src/Oni/CLI/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function run()
if (null !== $namespace && null !== $path) {
Loader::append($namespace, $path);

if ($this->loadTask()) {
if (true === $this->loadTask()) {
return true;
}
}
Expand All @@ -75,8 +75,8 @@ private function loadTask()
$param = ucfirst($param);

if (false === file_exists("{$path}/{$param}")
&& false === file_exists("{$path}/{$param}Task.php")) {

&& false === file_exists("{$path}/{$param}Task.php")
) {
break;
}

Expand Down
32 changes: 16 additions & 16 deletions src/Oni/CLI/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private function __construct()

// arguments
while ($argv) {
if (preg_match($configRegexRule, $argv[0])) {
if (true === (bool) preg_match($configRegexRule, $argv[0])) {
break;
}

if (preg_match($optionRegexRule, $argv[0])) {
if (true === (bool) preg_match($optionRegexRule, $argv[0])) {
break;
}

Expand All @@ -61,19 +61,19 @@ private function __construct()

// options & configs
while ($value = array_shift($argv)) {
if (preg_match($configRegexRule, $value, $match)) {
if (true === (bool) preg_match($configRegexRule, $value, $match)) {
$this->_configs[$match[1]] = isset($match[2]) ? $match[2] : null;
}

if (preg_match($optionRegexRule, $value, $match)) {
if (true === (bool) preg_match($optionRegexRule, $value, $match)) {
$this->_options[$match[1]] = null;

if (isset($argv[0])) {
if (preg_match($configRegexRule, $argv[0])) {
if (true === (bool) preg_match($configRegexRule, $argv[0])) {
continue;
}

if (preg_match($optionRegexRule, $argv[0])) {
if (true === (bool) preg_match($optionRegexRule, $argv[0])) {
continue;
}

Expand Down Expand Up @@ -104,8 +104,8 @@ public static function init()
*/
public function getArguments($index = null)
{
if (is_integer($index)) {
if (array_key_exists($index, $this->_arguments)) {
if (true === is_integer($index)) {
if (true === array_key_exists($index, $this->_arguments)) {
return $this->_arguments[$index];
} else {
return false;
Expand Down Expand Up @@ -134,8 +134,8 @@ public function hasArguments()
*/
public function getOptions($key = null)
{
if (is_string($key)) {
if (array_key_exists($key, $this->_options)) {
if (true === is_string($key)) {
if (true === array_key_exists($key, $this->_options)) {
return $this->_options[$key];
} else {
return false;
Expand All @@ -154,7 +154,7 @@ public function getOptions($key = null)
*/
public function hasOptions($key = null)
{
if (is_string($key)) {
if (true === is_string($key)) {
return array_key_exists($key, $this->_options);
}

Expand All @@ -170,8 +170,8 @@ public function hasOptions($key = null)
*/
public function getConfigs($key = null)
{
if (is_string($key)) {
if (array_key_exists($key, $this->_configs)) {
if (true === is_string($key)) {
if (true === array_key_exists($key, $this->_configs)) {
return $this->_configs[$key];
} else {
return false;
Expand All @@ -190,7 +190,7 @@ public function getConfigs($key = null)
*/
public function hasConfigs($key = null)
{
if (is_string($key)) {
if (true === is_string($key)) {
return array_key_exists($key, $this->_configs);
}

Expand Down Expand Up @@ -289,12 +289,12 @@ public function ask($text, $callback = null, $textColor = null, $bgColor = null)
*/
private function color($text, $textColor = null, $bgColor = null)
{
if (isset(self::$textColor[$textColor])) {
if (true === isset(self::$textColor[$textColor])) {
$color = self::$textColor[$textColor];
$text = "\033[{$color}m{$text}\033[m";
}

if (isset(self::$bgColor[$bgColor])) {
if (true === isset(self::$bgColor[$bgColor])) {
$color = self::$bgColor[$bgColor];
$text = "\033[{$color}m{$text}\033[m";
}
Expand Down
6 changes: 3 additions & 3 deletions src/Oni/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ private function __construct()
foreach (self::$_namespaceList as $namespace => $pathList) {
$pattern = '/^' . str_replace('\\', '\\\\', $namespace) . '/';

if (!preg_match($pattern, $className)) {
if (false === (bool) preg_match($pattern, $className)) {
continue;
}

$className = str_replace($namespace, '', trim($className, '\\'));
$className = str_replace('\\', '/', trim($className, '\\'));

foreach ($pathList as $path) {
if (!file_exists("{$path}/{$className}.php")) {
if (false === file_exists("{$path}/{$className}.php")) {
continue;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public static function append($namespace, $path)
$namespace = trim($namespace, '\\');
$path = rtrim($path, '/');

if (!isset(self::$_namespaceList[$namespace])) {
if (false === isset(self::$_namespaceList[$namespace])) {
self::$_namespaceList[$namespace] = [];
}

Expand Down
10 changes: 5 additions & 5 deletions src/Oni/Web/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use Oni\Basic;
use Oni\Loader;
use Oni\Web\Req;
use Oni\Web\Res;
use Oni\Web\Http\Req;
use Oni\Web\Http\Res;
use Oni\Web\View;

class App extends Basic
Expand Down Expand Up @@ -85,7 +85,7 @@ public function run()
if (null !== $namespace && null !== $path) {
Loader::append($namespace, $path);

if ($this->loadController()) {
if (true === $this->loadController()) {
return true;
}
}
Expand Down Expand Up @@ -188,8 +188,8 @@ private function loadController()
$param = ucfirst($param);

if (false === file_exists("{$path}/{$param}")
&& false === file_exists("{$path}/{$param}Controller.php")) {

&& false === file_exists("{$path}/{$param}Controller.php")
) {
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Oni/Web/Controller/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Oni\Web\Controller;

use Oni\Basic;
use Oni\Web\Req;
use Oni\Web\Res;
use Oni\Web\Http\Req;
use Oni\Web\Http\Res;

abstract class Ajax extends Basic
{
Expand Down
4 changes: 2 additions & 2 deletions src/Oni/Web/Controller/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Oni\Web\Controller;

use Oni\Basic;
use Oni\Web\Req;
use Oni\Web\Res;
use Oni\Web\Http\Req;
use Oni\Web\Http\Res;
use Oni\Web\View;

abstract class Page extends Basic
Expand Down
4 changes: 2 additions & 2 deletions src/Oni/Web/Controller/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Oni\Web\Controller;

use Oni\Basic;
use Oni\Web\Req;
use Oni\Web\Res;
use Oni\Web\Http\Req;
use Oni\Web\Http\Res;

abstract class Rest extends Basic
{
Expand Down
12 changes: 6 additions & 6 deletions src/Oni/Web/Req.php → src/Oni/Web/Http/Req.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/scarwu/Oni
*/

namespace Oni\Web;
namespace Oni\Web\Http;

class Req
{
Expand Down Expand Up @@ -117,9 +117,9 @@ public function uri()
{
$uri = null;

if (isset($_SERVER['PATH_INFO'])) {
if (true === isset($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
} elseif (true === isset($_SERVER['REQUEST_URI'])) {
$uri = explode('?', $_SERVER['REQUEST_URI'])[0];
}

Expand Down Expand Up @@ -164,9 +164,9 @@ public function content()
public function file()
{
switch ($this->contentType()) {
case 'multipart/form-data':
default:
return $_FILES;
case 'multipart/form-data':
default:
return $_FILES;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Oni/Web/Res.php → src/Oni/Web/Http/Res.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/scarwu/Oni
*/

namespace Oni\Web;
namespace Oni\Web\Http;

class Res
{
Expand Down
5 changes: 1 addition & 4 deletions src/Oni/Web/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@

use Oni\Basic;

class Model extends Basic
{

}
class Model extends Basic {}
4 changes: 2 additions & 2 deletions src/Oni/Web/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function addRoute($path, $callback, $method = 'get', $fullRegex = false)
{
$method = strtolower($method);

if (!isset($this->_rule[$method])) {
if (false === isset($this->_rule[$method])) {
$method = 'get';
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public function run()
$path = $this->regexGenerator($path);
}

if (preg_match($path, $this->_path, $match)) {
if (true === (bool) preg_match($path, $this->_path, $match)) {
$this->_matchRoute = $path;
$this->_isMatch = true;
$this->_rule[$this->_method]['callback'][$index](array_slice($match, 1));
Expand Down
4 changes: 2 additions & 2 deletions src/Oni/Web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ private function loadPartial($_subPath)
{
$_result = '';

if (is_string($_subPath)) {
if (true === is_string($_subPath)) {
$_path = $this->getAttr('path');
$_ext = $this->getAttr('ext');
$_fullpath = "{$_path}/{$_subPath}.{$_ext}";

if (file_exists($_fullpath)) {
if (true === file_exists($_fullpath)) {
foreach ($this->data as $_key => $_value) {
$$_key = $_value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Oni/Web/Helper.php → src/Oni/Web/View/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/scarwu/Oni
*/

namespace Oni\Web;
namespace Oni\Web\View;

class Helper {

Expand Down

0 comments on commit 7bfba8d

Please sign in to comment.