Skip to content

Commit eb9edf5

Browse files
committed
require ldos/phpapi
1 parent 406cad4 commit eb9edf5

File tree

13 files changed

+361
-3
lines changed

13 files changed

+361
-3
lines changed

application/app/V1/Api/Test.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
namespace App\V1\Api;
3+
4+
use PhpApi\Controller;
5+
use App\V1\Service\Test as ServiceTest;
6+
7+
class Test extends Controller{
8+
9+
public function get() {
10+
// 用retKey字符串代替ret数字,便于阅读代码
11+
return array('retKey' => 'SUCCESS', 'title' => 'test1', 'content' => 'test2', 'request' => $this->params);
12+
}
13+
14+
public function show() {
15+
16+
return array('retKey' => 'FAILURE', 'article' => '第一篇文章', 'content' => 'test');
17+
}
18+
19+
public function set() {
20+
$testService = new ServiceTest();
21+
22+
$data = array(
23+
'title' => 'fifth test title',
24+
'content' => 'fifth test content'
25+
);
26+
$result = $testService->add($data);
27+
28+
$ret = isset($result['rs'])? $result['rs'] : false;
29+
$retKeyString = $ret? 'SUCCESS' : 'FAILURE';
30+
return array('retKey' => $retKeyString, 'title' => $data['title'], 'content' => $data['content']);
31+
}
32+
33+
34+
}

application/app/V1/Model/Test.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace App\V1\Model;
3+
4+
use PhpApi\Model;
5+
6+
class Test extends Model{
7+
// 自定义设置表名
8+
// public $_table = 'test';
9+
10+
public function __construct() {
11+
parent::__construct();
12+
}
13+
14+
public function add($data) {
15+
$result = $this->create($data);
16+
return $result;
17+
}
18+
19+
}

application/app/V1/Service/Test.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace App\V1\Service;
3+
4+
use PhpApi\Service;
5+
use App\V1\Model\Test as ModelTest;
6+
7+
class Test extends Service{
8+
9+
public function __construct() {
10+
11+
}
12+
13+
/**
14+
* 这是一个简单事例,复杂的业务请用装饰器
15+
*/
16+
public function add($data) {
17+
$testModel = new ModelTest();
18+
19+
$result = $testModel->add($data);
20+
return $result;
21+
}
22+
23+
}

application/ischool/Api/Test.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Ischool\Api;
3+
4+
use PhpApi\Controller;
5+
6+
7+
class Test extends Controller{
8+
9+
public function get() {
10+
return array('title' => 'ischool test1', 'content' => 'ischool test2');
11+
}
12+
}

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "ldos1/phpapi-framework",
2+
"name": "ldos/phpapi-framework",
33
"description": "The Api Framework Based On PHPapi",
44
"type": "project",
55
"license": "BSD-2-Clause",
@@ -9,7 +9,7 @@
99
"authors": [
1010
{
1111
"name": "Shawn Yu",
12-
"email": "[email protected]"
12+
"email": "[email protected]"
1313
}
1414
],
1515
"minimum-stability": "dev",
@@ -26,6 +26,6 @@
2626
]
2727
},
2828
"config": {
29-
"secure-http": true
29+
"secure-http": false
3030
}
3131
}

composer.lock

+71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/App.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* App应用配置
4+
*
5+
* @copyright (c)Ldos.net All rights reserved.
6+
* @author Shawn Yu <[email protected]>
7+
*/
8+
9+
return array(
10+
11+
// 默认路由
12+
'Default' => [
13+
'appName' => 'App',
14+
'controller' => 'App/V1/Api/Test',
15+
'action' => 'get',
16+
],
17+
// 语言配置, zh_cn 或 en
18+
'Land' => 'zh_cn',
19+
// 开发者语言包位置
20+
'LandDir' => ROOT . 'lang',
21+
// 错误码文件名
22+
'CodeStatus' => 'CodeStatus',
23+
// 时区设置
24+
'TimeZone' => 'Asia/Shanghai',
25+
// 缓存 配置
26+
'Cache' => array(),
27+
// 全局,请求和响应内容类型: json,crypto-json (http表现为application/json,application/crypto-json)
28+
'ContentType' => 'json',
29+
// 请求和响应单独设置
30+
// 'RequestContentType' => 'application/json',
31+
// 'ResponseContentType' => 'application/json',
32+
33+
// DB 配置
34+
'Db' => array (
35+
'Master' => array(
36+
'type' => 'mysqli',
37+
'host' => '127.0.0.1',
38+
'user' => 'root',
39+
'password' => '123456',
40+
'port' => 3306,
41+
'db' => 'test',
42+
'prefix' => '', // 表名前缀
43+
'charset' => 'utf8'
44+
)
45+
),
46+
);

config/CodeStatus.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* 自定义状态码
5+
* 1.PHPapi有个Http类,里面的状态码往往在fcgi里已经不受控制,定义在里为了查漏预知PHPapi的实现层次
6+
* 如有需要请稳步nginx等WEB服务,接收的客户端也要分清获取web服务器的Status Code与本系统返回的code的方式与区别以及分段控制
7+
*
8+
* 2.这里主要让后台开发人员可以自定义一些Status Code,更好的配合客户端开发人员,可以自定义全平台通用的错误码,如返回 ret=11000
9+
*
10+
* 11000假设代指:2(ischool应用)1(Android)000(错误码成功)
11+
* 根据实际灵活协定
12+
*
13+
* 3.在编码时,我们是采取直接写“英文短语”为键,还是直接写“数字“为键,建议以英文为键找码,不但读起来容易理解点,而且语言包也用得。
14+
*
15+
* @copyright (c)Ldos.net All rights reserved.
16+
* @author Shawn Yu <[email protected]>
17+
*/
18+
19+
return array(
20+
21+
'App' => array(
22+
'SUCCESS' => 10000, // app项目,各端通用,成功
23+
'FAILURE' => 10001,
24+
'NO_METHOD' => 10002,
25+
'INVALID_ARGUMENT' => 10003,
26+
),
27+
'Ischool' => array(
28+
'SUCCESS' => 20000,
29+
'FAILURE' => 20001,
30+
)
31+
32+
);

config/Ischool.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Ischool应用配置
4+
*
5+
* @copyright (c)Ldos.net All rights reserved.
6+
* @author Shawn Yu <[email protected]>
7+
*/
8+
9+
10+
11+
return array(
12+
13+
// 默认路由
14+
'Default' => [
15+
'appName' => 'Ischool',
16+
'controller' => 'Ischool/Api/Test',
17+
'action' => 'get',
18+
],
19+
// 语言配置, zh_cn 或 en
20+
'Land' => 'zh_cn',
21+
// 开发者语言包位置
22+
'LandDir' => ROOT . 'lang',
23+
// 错误码文件名
24+
'CodeStatus' => 'CodeStatus',
25+
// 时区设置
26+
'TimeZone' => 'Asia/Shanghai',
27+
28+
// DB 配置
29+
'Db' => array(
30+
'Master' => array(
31+
'type' => 'mysqli',
32+
'host' => '127.0.0.1',
33+
'user' => 'root',
34+
'password' => '123456',
35+
'port' => 3306,
36+
'db' => 'ischool',
37+
'prefix' => 'sch_', // 表名前缀
38+
'charset' => 'utf8'
39+
)
40+
),
41+
42+
// 缓存 配置
43+
'Cache' => array(),
44+
);

lang/en.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
*
4+
* App自定义英文语言包
5+
*
6+
* @copyright (c)Ldos.net All rights reserved.
7+
* @author Shawn Yu <[email protected]>
8+
*/
9+
10+
11+
return array(
12+
13+
'SUCCESS' => 'success',
14+
'FAILURE' => 'failure',
15+
'ERROR' => 'error',
16+
'NO_METHOD' => 'no method',
17+
'INVALID_ARGUMENT' => 'invalid argument',
18+
19+
);

lang/zh_cn.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
*
4+
* App自定义中文语言包
5+
*
6+
* @copyright (c)Ldos.net All rights reserved.
7+
* @author Shawn Yu <[email protected]>
8+
*/
9+
10+
11+
return array(
12+
13+
'SUCCESS' => '成功',
14+
'FAILURE' => '失败',
15+
'ERROR' => '错误',
16+
'NO_METHOD' => '找不到类或方法',
17+
'INVALID_ARGUMENT' => '无效参数',
18+
19+
);

public/app/index.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* app项目入口文件
4+
*/
5+
6+
// web服务器所指目录
7+
defined('PUB') || define('PUB', dirname(__FILE__));
8+
// 实际项目根目录
9+
defined('ROOT') || define('ROOT', PUB.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
10+
// 加载composer autoload
11+
require_once ROOT . '/vendor/autoload.php';
12+
13+
$kernel = new \PhpApi\Kernel();
14+
15+
// 配置(用户项目config路径及名称)
16+
$kernel::config(ROOT . 'config', 'App');
17+
18+
// 分发
19+
$kernel::dispatch();

0 commit comments

Comments
 (0)