Code Monkey home page Code Monkey logo

xkphp's Introduction

XK-PHP

一个轻量的 PHP 框架

描述 Description

一个简单的 PHP "框架"?又或者可以说是应用模板。

ORM 使用 Eloquent ORM ,路由使用 FastRoute

大部分的接口设计参考了 Laravel,采用门面模式 (Facade) ,单例模式 (Singleton) ,控制反转 (IoC) ,以及 依赖注入 (DI) 的设计,部分也用到了其他的设计模式。

集成了一个 IoC 容器,兼容 PSR-11

支持和 ReactJS 集成,其他前端框架也是可以的,不过我只写了 ReactJS 的配置。

支持 PSR-15 标准的中间件。

封装了请求和响应,根据 PSR-7 标准进行设计,但增加了类似 Laravel 的接口。

支持通过注解设置依赖注入,路由以及中间件

支持 Aop,但是由于没有使用继承代理的方式,所以支持切入的范围有限,目前支持门面切入和控制器切入,同时在容器中也添加了相应的方法提供切入的功能。

之所以不使用继承代理的方式,是因为 PHP 没有类似 Java 中的 Proxy 反射接口,PHP 继承代理需要使用 eval 或 require 的方式动态声明 class,会有安全的风险。

提供一个简单的观察者实现,虽然说一般也没啥用。

使用 APCu 来缓存注解

提供了一个任务队列的实现,类似于协程,可以主动让出,但是由于 PHP 没有多线程机制所以无法实现非阻塞。

由于首次写这种项目,所有会有很多设计缺陷和漏洞,不建议将该项目用于任何生产环境,仅用于学习就可以啦,若您有更好的建议或者发现不足的地方欢迎反馈。

写这个项目的目的是为了下一个博客项目准备的,因为不打算用任何框架,所以就有了这个项目 2333。

安装 Install

  1. 克隆本仓库
git clone https://github.com/syfxlin/xkphp.git
  1. 安装 PHP 依赖
composer install

某些情况下 laminas/laminas-httphandlerrunner 可能无法正常安装,此时就需要先安装 laminas/laminas-diactoros

  1. 若您也需要使用 ReactJS,那么就需要安装 Node 依赖
yarn
  1. 修改 .env 文件配置,并配置 API Key(可以通过 Laravel 生成,暂时还没制作生成脚本),或者执行以下代码生成
php -r "echo base64_encode(openssl_random_pseudo_bytes(32));"
  1. 运行数据库迁移
composer migration:up
  1. 将 PHP 运行目录切换到 public,或者也可以通过 PHP 内置服务器启动。
php -S 0.0.0.0:8000 -t public

TODO

  • 发送请求(不使用第三方库)
  • 终止流程
  • Aop 注解
  • 兼容 PSR-17
  • 适配 Swoole

文档 Doc

暂无

维护者 Maintainer

XK-PHP 由 Otstar Lin 和下列 贡献者 的帮助下撰写和维护。

Otstar Lin -Personal Website · Blog · Github

许可证 License

Lincense

根据 Apache License 2.0 许可证开源。

xkphp's People

Contributors

syfxlin avatar dependabot[bot] avatar

Stargazers

Roman avatar coca avatar  avatar  avatar GeeHon avatar Dr_Black avatar

Watchers

 avatar

Forkers

melodyjerry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.