定制 rklib/rkphplib 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rklib/rkphplib

Composer 安装命令:

composer require rklib/rkphplib

包简介

PHP library with template engine and wrapper classes to filesystem, mysql and other.

README 文档

README

PHP library with template engine and wrapper classes to filesystem, mysql and other. Object oriented, namespaced and with strict function types. I have been doing Web Project's since 1998 and in 2003 the first Version of this library started as a Port of it's Perl Ancestor.

Install

Install with composer in project directory

composer require rklib/rkphplib

Examples

Autoload library via composer.

<?php

require_once('vendor/rklib/rkphplib/src/lib/config.php');
// require 'vendor/autoload.php';

print SETTINGS_TIMEZONE."\n";
print SETTINGS_LANGUAGE."\n";

File and Dir example.

<?php

require_once('src/File.php');
require_once('src/Dir.php');

use rkphplib\File;
use rkphplib\Dir;

if (Dir::exists('src')) {
	echo File::load('composer.json');
}

Date calculation.

<?php

require_once('src/DateCalc.php');

use rkphplib\DateCalc;

print "3rd month in ".SETTINGS_LANGUAGE.": ".DateCalc::monthName(3)."\n";

$sql_date = '2016-07-18 15:30:00';
print "SQL Date $sql_date: de_format=".DateCalc::formatDateTimeStr('de', $sql_date, 'sql').", timestamp=".DateCalc::sqlTS('2016-07-18 15:30:00')."\n";

Template parser. If {action:param}body{:action} is detected the result of Plugin->tok_action(param, body) callback will be inserted. Parser is bottom-up but can be changed by plugin to top-down.

<?php

require_once('src/Tokenizer.php');

class Plugin {
	private $n = 0;
	public function getPlugins($tok) { return array('x' => 6); } // change 6 to 0 or 2 and compare different output
	public function tok_x($param, $arg) { $this->n++; return "X".$this->n."($param)[$arg]"; }
}

$txt = 'a1{x:p1}a2{x:p2}a3{:x}a4{:x}a5{x:p3}a6{:x}';

$tok = new rkphplib\Tokenizer();
$tok->setPlugin(new Plugin());
$tok->setText($txt);

// (6) Output: a1X1(p1)[a2X2(p2)[a3]a4]a5X3(p3)[a6]
// (0) Output: a1X2(p1)[a2X1(p2)[a3]a4]a5X3(p3)[a6]
// (2) Output: a1X1(p1)[a2{x:p2}a3{:x}a4]a5X2(p3)[a6] 
print "\nInput: $txt\nOutput: ".$tok->toString()."\n\n";

Extend abstract class ARestAPI for simple REST API implementation.

<?php

require_once('src/ARestAPI.php');

class APIExample extends rkphplib\ARestAPI {

	public static function apiMap($allow = array()) {
		return = ['postSomeAction' => ['POST', 'some/action', 0], 
			'getSomeAction' => ['GET', 'some/action', 2], 
			'putSomething' => ['PUT', 'something', 1]];
	}

	public function checkToken() {
		if ($this->_req['api_token'] != '123') { $this->out(['error' => 'invalid api token'], 400); }
		return ['allow' => ['getSomeAction']];
	}

	public function run() {
		$this->parse(); // log or check $r if necessary
		$priv = $this->checkToken(); // check $this->req['api_token'] and return privileges
		$this->route(static::allow(static::apiMap(), $priv['allow'])); // set _req.api_call if authorized
		$method = $this->_req['api_call'];
		$this->$method();
	}

	protected function getSomeAction() {
		$this->out($this->_req);
	}
}

$api = new APIExample();
$api->run();

Requirements

  • PHP 7.2

Documentation

Create with ApiGen:

vendor/apigen/apigen/bin/apigen generate -s ./src -d ./docs/api

If composer or ApiGen are not installed run:

./build.sh composer
./build.sh docs 
```

统计信息

  • 总下载量: 19
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2016-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固