PHPackages                             waiterphp/core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. waiterphp/core

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

waiterphp/core
==============

waiterphp的核心类库

0.9.3(6y ago)0743MITPHPPHP &gt;=7.1.0CI failing

Since Feb 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/waiter-coders/core)[ Packagist](https://packagist.org/packages/waiterphp/core)[ RSS](/packages/waiterphp-core/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (5)Used By (3)

### waiterphp 核心类库

[](#waiterphp-核心类库)

该项目提供了php的一些基础操作封装。可直接采用composer装载该类。

以下是类库的相关功能介绍。

#### 装载配置

[](#装载配置)

可通过以下方式获取配置文件中的数据。

```
$configs = load_configs($fileNames);
```

函数可以从basePaths设置的多个路径里面，加载fileNames里面设置的多个文件中的内容，覆盖顺序为后者覆盖前者。

#### 设置当前环境

[](#设置当前环境)

通过以下函数设置环境变量和获取环境变量：

```
set_env('app_name', 'waiterphp_core');
print get_env('app_name');
```

可采用dot方式,如下两种写法作用相同:

```
set_env('database.default.username', 'test');
set_env('database', [
	'default'=>[
		'username'=>'test'
	]
]);
```

也可以直接写入数组：

```
set_env(['database'=>['default'=>[
	'host'=>'localhost',
	'username'=>'root',
	'password'=>'',
	'database'=>'tests'
]]])
```

注意：

> 重复设置的环境变量，后者会覆盖前者 环境变量有一些默认键名，如database为数据库设置，cache为缓存设置,函数会检测该键名，并自动初始化到相关类库

#### 访问数据库

[](#访问数据库)

```
// 设置数据库配置，可通过load_configs从文件直接装载
set_env('database.default', [
	'host'=>'127.0.0.1',
	'username'=>'root',
	'password'=>'',
	'database'=>'tests'
]);

// 获取多行数据
$data = table('article')->select('articleId,userId,title,hit as hit_num')
->where([
	'userId'=>1,
	'articleId'=>[1,2,3,4,5,6,7,8],
	'addTime >='=>'2018-01-01 00:00:00',
	'title like'=>'%测试%'
])->orderBy('articleId desc')
->limit(10)
->offset(0)->fetchAll();

// 获取单行
$data = table('article')->where(['userId'=>1])->fetchRow();

// 写入数据
$articleId = table('article')->insert([
	'userId'=>2,
	'title'=>'insert data'
]);

// 删除数据
table('article')->where([
	'articleId'=>$articleId
])->delete();

// 更新数据
table('article')->where([
	'articleId'=>1
])->update([
	'hit'=>211
]);

// 表达式更新
 table('article')->where([
	'articleId'=>1
])->update([
	'hit=hit+1'
]);

// 统计
table('article')->where(['userId'=>1])->count();

// 分组
table('article')->select('userId,count(*)')->groupBy('userId')->fetchAll();
```

#### 访问缓存

[](#访问缓存)

```
//file

// redis
set_env('cache.redis', []);
cache('redis')->hmget('some_key');

// memcache
```

#### 页面渲染工具

[](#页面渲染工具)

```
set_env('view', []);
echo render('user/login.html', ['username'=>'测试'], 'smarty');
```

> 第三个参数可以选择你采用的渲染引擎，默认为smarty。 目前可支持的有：smarty、twig

可以设置自定义的第三个参数，要求类本身实现render方法。如下：

```
set_env('view', []);
render('user/login.html', ['username'=>'测试'], 'tools.myView');
```

> 页面渲染需在您自己的项目composer.json中加入相关类库，

#### dao的使用

[](#dao的使用)

```
use waiterphp\core\database\DaoTrait;

class User
{
	use DaoTrait;
}

```

#### 过滤器的使用

[](#过滤器的使用)

可以利用trait快速构建一个过滤器

```
use waiterphp\core\Filter\FilterTrait;

class HttpRequest
{
	use Filter;
}
```

当然，你也可以直接使用Filter直接过滤数据

```
filter($data)->getInt('userId', '');
```

注意：

> 第二个参数为默认值。如果没有设置，当获取不到数据时，抛出异常！

#### 异常检测

[](#异常检测)

用法如下：

```
assert_exception(false, '程序异常！', 500);
```

#### 事件绑定和触发

[](#事件绑定和触发)

```
bind_to_env($tab, $action);
env_trigger($tab, $params = []);
```

#### 构建工具

[](#构建工具)

```
build();
```

#### http请求

[](#http请求)

```
print request()->hostname();
print request()->query();
print request()->query('userId');
print request()->post();
print request()->post('userId');
```

#### curl请求

[](#curl请求)

```
curl($url, $params, $httpType, $header);
```

#### 文件操作

[](#文件操作)

```
get_files('/home/user');
write('/home/user/test.txt', $content, 'a+');
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~181 days

Total

3

Last Release

2251d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c93342ab0ba04b4dea214583a7ae96930012825a08a1a1806c3ca149e0977a4?d=identicon)[tian8242382](/maintainers/tian8242382)

---

Top Contributors

[![tian8242382](https://avatars.githubusercontent.com/u/7625235?v=4)](https://github.com/tian8242382 "tian8242382 (26 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waiterphp-core/health.svg)

```
[![Health](https://phpackages.com/badges/waiterphp-core/health.svg)](https://phpackages.com/packages/waiterphp-core)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
