Skip to content

Commit

Permalink
1. udpate travis file
Browse files Browse the repository at this point in the history
2. udpate composer components
3. update example
4. update libs
  • Loading branch information
scarwu committed Aug 14, 2018
1 parent 4ef0afb commit bd9b9e4
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 64 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ script:
- php ./example/CLI/boot.php parse arg1 arg2 /arg3/arg4 -opt1 -opt2 opt_arg --cfg1 skip --cfg2=cfg_arg
language: php
php:
- 7.0
- 7.1
- 7.2
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"homepage": "https://github.com/scarwu/Oni",
"description": "A Lightweight PHP Framework for Web & CLI",
"require": {
"php": ">=7.0.0"
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^7",
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions example/Web/controllers/AboutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@ public function defaultAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/default');

$this->res->html($this->view->render([
$this->view->setData([
'title' => 'Oni - About / Default Page'
]));
]);

$this->res->html($this->view->render());
}

public function mvcAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/mvc');

$this->res->html($this->view->render([
$this->view->setData([
'title' => 'Oni - About / MVC Page'
]));
]);

$this->res->html($this->view->render());
}

public function mvvmAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/mvvm');

$this->res->html($this->view->render([
$this->view->setData([
'title' => 'Oni - About / MVVM Page'
]));
]);

$this->res->html($this->view->render());
}
}
14 changes: 8 additions & 6 deletions example/Web/controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function defaultAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('main/default');

$this->res->html($this->view->render([
$this->view->setData([
'title' => 'Oni - A Lightweight PHP Framework for Web & CLI',
'data' => [
'method' => $this->req->method(),
Expand All @@ -40,16 +39,19 @@ public function defaultAction()
'get' => $_GET
]
]
]));
]);

$this->res->html($this->view->render());
}

public function errorAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('main/error');

$this->res->html($this->view->render([
$this->view->setData([
'title' => 'Oni - Error Page'
]));
]);

$this->res->html($this->view->render());
}
}
10 changes: 10 additions & 0 deletions src/Oni/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ private function __construct() {
*
* @param string $namespace
* @param string $path
*
* @return bool
*/
public static function append($namespace, $path)
{
if (false === is_string($namespace)
|| false === is_string($path)) {

return false;
}

if (null === self::$_instance) {
self::$_instance = new self;
}
Expand All @@ -78,5 +86,7 @@ public static function append($namespace, $path)
}

self::$_namespace_list[$namespace][] = $path;

return true;
}
}
2 changes: 1 addition & 1 deletion src/Oni/Web/Req.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Oni\Web;

class Req extends
class Req
{
/**
* @var object
Expand Down
14 changes: 9 additions & 5 deletions src/Oni/Web/Res.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Oni\Web;

class Res extends
class Res
{
/**
* @var object
Expand Down Expand Up @@ -43,7 +43,9 @@ public static function init()
*/
public function redirect($path)
{
header("Location: {$path}");
if (is_string($path)) {
header("Location: {$path}");
}
}

/**
Expand All @@ -55,7 +57,9 @@ public function html($data)
{
header('Content-Type: text/html');

echo $data;
if (is_string($data)) {
echo $data;
}
}

/**
Expand All @@ -64,11 +68,11 @@ public function html($data)
* @param array $data
* @param integer $option
*/
public function json($data = null, $option = null)
public function json($data, $option = null)
{
header('Content-Type: application/json');

if (null !== $data) {
if (is_string($data)) {
echo json_encode($data, $option);
}
}
Expand Down
Loading

0 comments on commit bd9b9e4

Please sign in to comment.