Download the PHP package veasin/nx-tiny without Composer

On this page you can find all versions of the php package veasin/nx-tiny. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nx-tiny

nx-tiny: A Minimal, Declarative Functional PHP Framework


中文版

描述

nx-tiny 是一个轻量级的、函数驱动的 PHP 框架,专为现代开发实践设计。它优先考虑配置优于代码,支持尾调用优化

它避免了复杂的类层次结构和“魔法”行为,转而采用显式的、简单的全局函数。

核心哲学

安装

函数参考

container - 容器方法

支持双生命周期(持久/请求级)与延迟构建的配置容器,适用于 Swoole/FrankenPHP 等常驻内存场景。 在php-fpm或apache下,每次请求都是重置的,可以忽略^相关逻辑。

env - 环境变量读取

支持系统环境变量、$_ENV.env 文件三种来源。

.env 配置:container('#env', '/path/to/.env')

args - 命令行参数解析

method - HTTP方法获取/检查

缓存键:#method

safe - 安全调用

封装 try/catch 模式,失败返回 null,省去重复的异常处理模板代码。

from - 从指定来源获取原始值,支持来源:query|cookie|file|params|header|input|body

缓存键:#in.input#in.params#in.body#in.headers#in.raw#in.content

filter - 数据验证与转换

扩展方式:container('#filter', [...])

input - 输入数据获取(获取from+验证filter)

hook - 钩子系统

注册/触发分离的钩子系统,与容器集成。用于管理函数执行时机,生命周期模式下 output() 等函数自动挂载。

调用 说明
hook(true) 开启钩子模式,持久级存储默认序列 ['after', 'end']
hook(true, ['a', 'b']) 覆盖默认序列
hook('name', callable) 注册回调到指定钩子名(请求级)
hook('name') 触发指定钩子下的所有回调
hook(['a', 'b']) 按数组顺序依次触发各钩子
hook() 读取持久级默认序列并依次触发

钩子回调存储在请求级容器 #hook.{name},请求结束时 container(null) 自动清空。 默认序列存储在持久级容器 ^#hook,跨请求保持。

output - 输出数据

扩展方式:container('#out.formats', [...])
回调方式:container('#out.callback', fn($response) => ...)

route - 路由匹配

cache - 多级缓存

配置方式:container('cache', [...])
Redis 配置:container('config.redis', ['host' => '127.0.0.1', 'port' => 6379, 'password' => '', 'database' => 0])

db - 数据库操作

事务支持

配置数据库连接

配置方式:container('db.{name}', [...])

配合 nx-sql 使用:

test - 轻量级测试

name - 命名配置管理

配置方式:container('name', [...])

log - 日志函数

PSR Logger 方式:container('#log', $logger)
闭包方式:container('#log.fn', fn(...) => ...)


预制中间件

所有预制中间件返回 callable,直接传入 middleware()run() 使用:

auth(prefix, realm) — HTTP Basic 认证

旧版 Basic 认证。从 Authorization: Basic 头提取用户名密码,调用验证器。

参数 默认值 说明
$prefix #mw:auth 容器键前缀
$realm Protected WWW-Authenticate realm
容器键 说明
{prefix}:validators 验证器数组,接收 ($user, $pass) 返回 bool
{prefix}:user 认证通过后写入用户信息

basic(prefix, realm) — HTTP Basic 认证(推荐)

新版 Basic 认证。验证器返回值直接存入 user(可返回用户对象而非 true)。

参数与容器键同 auth()

token(prefix, headerName) — Token 认证

Authorization 头或 URL 查询参数 ?token= 提取 token。

参数 默认值 说明
$prefix #mw:auth 容器键前缀
$headerName Authorization 请求头名称(未取到时 fallback 查询参数 token
容器键 说明
{prefix}:validators 验证器数组,接收 ($token)
{prefix}:user 认证通过后写入用户信息

jwt(prefix, algo) — JWT 认证

Authorization: Bearer <token> 提取 JWT,HMAC 验证签名后解码 payload。

参数 默认值 说明
$prefix #mw:auth 容器键前缀
$algo HS256 签名算法,支持 HS256HS512
容器键 说明
{prefix}:secret HMAC 签名密钥
{prefix}:validators 验证器数组,接收 ($payload)
{prefix}:user 认证通过后写入用户信息
{prefix}:payload 自动写入解码后的 JWT payload

apikey(prefix, headerName, queryName) — API Key 认证

从请求头或 URL 查询参数提取 API Key。

参数 默认值 说明
$prefix #mw:auth 容器键前缀
$headerName X-API-Key 请求头名称
$queryName api_key URL 查询参数名
容器键 说明
{prefix}:validators 验证器数组,接收 ($apiKey)
{prefix}:user 认证通过后写入用户信息

cors(options) — CORS 跨域

为响应添加 CORS 头,OPTIONS 预检请求直接返回空响应。

参数 默认值 说明
origin '*' 允许的源,数组时随机选取
methods 'GET,POST,PUT,DELETE,OPTIONS' 允许的 HTTP 方法
headers 'Content-Type,Authorization,X-CSRF-Token' 允许的请求头
credentials false 是否允许发送凭证
max-age 86400 预检缓存时间(秒)

csrf(verify) — CSRF 防护

容器键 说明
#mw:csrf:token 存储/读取当前会话的 CSRF token

error(debug) — 异常处理

捕获所有 \Throwable 异常。调试模式返回完整堆栈,生产模式返回通用错误。

gzip(level) — Gzip 响应压缩

检查客户端 Accept-Encoding: gzip,压缩后内容比原内容小时启用压缩。

参数 默认值 说明
$level 6 压缩级别 1-9

json(pretty) — JSON 格式化

将返回值转为 JSON 并设置 Content-Type: application/json; charset=UTF-8

log(level) — 请求日志

记录请求方法、URI、状态码、耗时(ms)、内存(KB)。

容器键 说明
#out.response:code 读取响应状态码(默认 200)

rate(maxRequests, windowSeconds, key) — 接口限流

基于滑动窗口的 IP + 路由级别限流,默认使用 APCu 存储。

参数 默认值 说明
$maxRequests 60 时间窗口内最大请求数
$windowSeconds 60 时间窗口大小(秒)
$key 'rate' 限流键名前缀

自定义存储(通过容器):

serve(root, map) — 静态文件服务

根据 URI 在指定目录查找静态文件,自动设置 MIME 类型和缓存头。

参数 默认值 说明
$root 必填 静态文件根目录
$map [] 扩展名到目标文件的映射

扩展 MIME 类型:


All versions of nx-tiny with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-pdo Version *
ext-json Version *
ext-fileinfo Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package veasin/nx-tiny contains the following files

Loading the files please wait ...