blessing-skin-server/app/Services/View.php

46 lines
1002 B
PHP
Raw Normal View History

2016-07-21 22:01:57 +08:00
<?php
2016-08-28 10:05:21 +08:00
namespace App\Services;
2016-07-21 22:01:57 +08:00
2016-08-29 23:08:09 +08:00
use Session;
2016-07-21 22:01:57 +08:00
/**
2016-08-28 10:05:21 +08:00
* @see \Illuminate\Support\Facades\View
2016-07-21 22:01:57 +08:00
*/
2016-08-28 10:05:21 +08:00
class View extends \Illuminate\Support\Facades\View
2016-07-21 22:01:57 +08:00
{
public static function show($view, $data = [], $mergeData = [])
{
echo self::make($view, $data, $mergeData)->render();
}
// function reload
public static function json()
{
@header('Content-type: application/json; charset=utf-8');
$args = func_get_args();
if (count($args) == 1) {
self::jsonCustom($args[0]);
} elseif(count($args) == 2) {
self::jsonException($args[0], $args[1]);
}
}
2016-08-29 23:08:09 +08:00
private static function jsonCustom(Array $array)
2016-07-21 22:01:57 +08:00
{
2016-08-29 23:08:09 +08:00
if (is_array($array)) {
Session::save();
2016-07-21 22:01:57 +08:00
exit(json_encode($array));
2016-08-29 23:08:09 +08:00
}
2016-07-21 22:01:57 +08:00
}
private static function jsonException($msg, $errno)
{
2016-08-29 23:08:09 +08:00
Session::save();
2016-07-21 22:01:57 +08:00
exit(json_encode([
'errno' => $errno,
'msg' => $msg
]));
}
}