Download the PHP package tigerb/easy-php without Composer
On this page you can find all versions of the php package tigerb/easy-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tigerb/easy-php
More information about tigerb/easy-php
Files in tigerb/easy-php
Package easy-php
Short Description A Faster Lightweight Full-Stack PHP Framework
License MIT
Homepage http://easy-php.tigerb.cn/
Informations about the package easy-php
A Faster Lightweight Full-Stack PHP Framework
中文版
# Docker env > Just one command to build all env for the easy-php [![easy-env](https://asciinema.org/a/219911.svg)](https://asciinema.org/a/219911?autoplay=1) # How to build a PHP framework by ourself ? Why do we need to build a PHP framework by ourself? Maybe the most of people will say "There have so many PHP frameworks be provided, but we still made a wheel?". My point is "Made a wheel is not our purpose, we will get a few of knowledge when making a wheel which is our really purpose". Then, how to build a PHP framework by ourself? General process as follows: In addition, unit test, nosql support, api documents and some auxiliary scripts, e.g. Finnally, My framework directory as follows: # Project Directory Structure # Life Cycle
# Framework Module Description:
## Entrance file
Defined a entrance file that provide a uniform file for user visit, which hide the complex logic like the enterprise service bus.
[[file: public/index.php](https://github.com/TIGERB/easy-php/blob/master/public/index.php)]
## Autoload Module
Register a autoload function in the __autoload queue by used spl_autoload_register, after that, we can use a class by namespace and keyword 'use'.
[[file: framework/Load.php](https://github.com/TIGERB/easy-php/blob/master/framework/Load.php)]
## Error&Exception Handle Module
- Catch error:
Register a function by used set_error_handler to handle error, but it can't handle the following error, E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING and the E_STRICT produced by the file which called set_error_handler function. So, we need use register_shutdown_function and error_get_last to handle this finally error which set_error_handler can't handle. When the framework running, we can handle the error by ourself, such as, give a friendly error messge for client.
[[file: framework/hanles/ErrorHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ErrorHandle.php)]
- Catch exception:
Register a function by used set_exception_handler to handle the exception which is not be catched, which can give a friendly error messge for client.
[[file: framework/hanles/ExceptionHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ExceptionHandle.php)]
## Config Handle Module
Loading framework-defined and user-defined config files.
For example,the master-salve database config:
[[file: framework/hanles/ConfigHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ConfigHandle.php)]
## Request&Response Module
- Request Object: contains all the requested information.
- Response Object: contains all the response information.
All output is json in the framework, neithor framework's core error or business logic's output, beacuse I think is friendly.
##### Request param check, Support require/length/number check at present. Use as follows:
[[file: framework/Request.php](https://github.com/TIGERB/easy-php/blob/master/framework/Request.php)]
[[file: framework/Response.php](https://github.com/TIGERB/easy-php/blob/master/framework/Response.php)]
## Route Handle Module
Execute the target controller's function by the router parse the url information.Is composed of four types of:
**tradition router**
**pathinfo router**
**user-defined router**
**micro monolith router**
What's the micro monolith router? There are a lot of teams are moving in the SOA service structure or micro service structure, I think it is difficult for a small team. So the micro monolith was born, what's this? In my opinion, this is a SOA process for a monolith application.For example:
As above, we implemented a easy micro monolith structure.But how these module to communicate with each other? As follows:
So we can resolve this problem loose coupling. In the meantime, we can exchange our application to the SOA structure easily, beacuse we only need to change the method get implementing way in the App class, the way contain RPC, REST. etc.
[[file: framework/hanles/RouterHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/RouterHandle.php)]
## MVC To MCL
The tradition MVC pattern includes the model,view,controller layer. In general, you always write the business logic in the controller or model layer. But you will feel the code is difficult to read, maintain, expand after a long time. So I add a logic layer in the framework forcefully where you can implement the business logic by yourself. You can not only implement a tool class but also implement your business logic in a new subfolder, what's more, you can implement a gateway based on the pattern of responsibility (I provided a example).
In the end, the structure as follows:
- M: models, the map of database's table where define the curd operation.
- C: controllers, where expose the business resourse
- L: logics, where implement the business logic flexiblly
**Logics layer**
A gateway example:
I built a gateway in the logics folder, structure as follows:
The gateway entrance class code as follows:
After the gateway be implemented, how to use this in the framework?I provide a user-defined's class, we just register this in the UserDefinedCase class. for example:
So, the gateway is running.But what's the UserDefinedCase that can be loading before RouterHandle.
Where is the view layer?I abandon it, beacuse I chose the SPA for frontend, detail as follows.
[[file: app/*](https://github.com/TIGERB/easy-php/tree/master/app/demo)]
## Using Vue For View
**source code folder**
The separate-frontend-and-backend and two-way data binding, modular is so popular.In the meantime, I moved the project [easy-vue](http://vue.tigerb.cn/) that built by myself to the framework as the view layer. The frontend source code folder as follows:
**Build Step**
**After build**
After built success, there made dist folder and index.html in the public. This file will be ignore when this branch is not the release branch.
[[file: frontend/*](https://github.com/TIGERB/easy-php/tree/master/frontend)]
## ORM
What's the ORM(Object Relation Map)? In my opinion, ORM is a thought that build a relationship of object and the abstract things.The model is the database's table and the model's instance is a operation for the table."Why do you do that, use the sql directly is not good?", my answer:you can do what you like to do, everything is flexable, but it's not be suggested from a perspective of a framework's **reusable, maintainable and extensible**.
On the market for the implemention of the ORM, such as: Active Record in thinkphp and yii, Eloquent in laravel, then we call the ORM here is "ORM" simply. The "ORM" structure in the framework as follows:
**DB example**
**Model example**
[[file: framework/orm/*](https://github.com/TIGERB/easy-php/tree/master/framework/orm)]
## Service Container
What's the service container?
Service container is difficultly understand, I think it just a third party class, which can inject the class and instance. we can get the instance in the container very simple.
The meaning of the service container?
According to the design patterns: we need make our code "highly cohesive, loosely coupled". As the result of "highly cohesive" is "single principle", As the result of "single principle" is the class rely on each other. General way that handle the dependency as follows:
The above code is no problem, but is not conform to the design pattern of "The least kown principle", beacuse it has a direct dependence. We bring a third class in the framework, which can new a class or get a instance. So, the third party class is the service container, which like the role of 'middleware' in the architecture of the system.
After implements a service container, I put the Rquest, Config and other instances are injected into service in the singleton container, when we need to use can be obtained from the container, is very convenient.Use the following:
[[file: framework/Container](https://github.com/TIGERB/easy-php/blob/master/framework/Container.php)]
## Nosql Support
Inject the nosql's single instance in service container when the framework loading, you can decide what nosql you need use whit the configuration. At present we support redis/memcahed/mongodb.
Some example:
[[file: framework/nosql/*](https://github.com/TIGERB/easy-php/tree/master/framework/nosql)]
## Log
I make the log class like a third part module that be used by composer, the project link
**Cli Mode:**
**Swoole Mode:**
Get Help:
Use php cli OR php cli --help
# Docker env
Docker env is support by this framework, you will build the env just by one command quickly. Get more please click [easy-env](https://easy-framework.github.io/easy-env/).
# Performance with php-fpm
> ab -c 100 -n 10000 "http://easy-php.local/Demo/Index/hello"
# Performance with Swoole
> ab -c 100 -n 10000 "http://easy-php.local/Demo/Index/hello"
# Question&Contribution
If you find some question,please launch a [issue](https://github.com/TIGERB/easy-php/issues) or PR。
How to Contribute?
After that, launch a PR as usual.
project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/easy-php)
# TODO
- Add database sql helper
- Integrate swagger
- Provide much friendly help for user
- Module's config support module-defined mysql and nosql configuration
- ORM provide more apis
- Resolve config problem when publish our project
- implement auto deploy by used phar
- ...
# DONE
- v0.8.6(2019/04/21)
- fix core error data strcut
- fix phpunit
- v0.8.5(2019/01/06)
- fix error_report
- fix when __coreError is occur the response is output 200 but it also out put __coreError
- v0.8.1(2018/06/24)
- use easy log
- add folder bin
- v0.8.0(2017/12/29)
- use swoole
- fix infinite recursion for micromonomer router
- v0.7.1(2017/08/29)
- refactor router by the strategy design pattern
- v0.7.0(2017/06/18)
- implement ci by travis-ci
- add jobs script folder
- v0.6.9(2017/05/22)
- more friendly for api develop process
+ request param check:require/length/number
- support master-salve config for db
- v0.6.7(2017/05/14)
- fix not set default time zone
- The performance test and optimize
- Use the lazy load thought to optimize the framework
- Change Helper's method to the framework's function
## APPRECIATION
### Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
### Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/easy-php#backer)]
### Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/easy-php#sponsor)]
# CONTACT