Phalcon+ is a lightweight Zephir/C framework based on PhalconPHP. We want to build a one-step solution for Phalcon developers. It is precisely because of Phalcon's extremely high flexibility that gives developers too much choice. Sometimes there are too many intersections and it is easy to get lost, so after I made this series of choices, I recorded the process and gradually evolved into the current Phalcon+. In order to prevent every developer from making these choices repeatedly, I resolutely open source Phalcon+ for everyone to communicate and learn.
So, To sum up, Phalcon+ is not a brand new framework, but an excellent practice of the Phalcon framework. It is a reprocessing and supplement to the Phalcon framework. It can allow Phalcon developers to get started and master it more easily, and finally reach the highest level of unity between man and nature.
* PHP 7.0 or above
* cPhalcon 3.4.x,在官方发布3.4.6之前一定要下载此分支,通过`zephir build`手动编译phalcon - https://github.com/phalcon/cphalcon/tree/3.4.x
> 安装zephir之前,需要先安装扩展 https://github.com/phalcon/php-zephir-parser ,然后使用`composer`安装`zephir`
`composer global require phalcon/zephir`
Srv provides Rpc services, Web can provide Restful servicesApp::import("test") ➜ git clone https://github.com/bullsoft/phalconplus.git
➜ cd phalconplus/ext/
➜ /usr/bin/phpize
➜ ./configure --with-php-config=/usr/bin/php-configure
➜ make
➜ make install
graph TD
A[PhalconPlusBootstrap::__construct] -->|Sys::init, initConf| A1(SuperApp::boot with Env, RunMode)
A1 --> |Sys::iniApp, Define global constants, The first module is primary| A2(SuperApp::bootPrimaryModule)
A2 --> |Make sure we have a valid module: Web/Cli/Srv|A3(ModuleDef)
A3 --> |Assign SuperApp::booted -> true, Make this a defaultModule |A4(SuperApp::registerModule with ModuleDef)
A4 --> |Make sure this module is not running in SuperApp::modules|A5(Checkout Module)
A5 --> |AbstractModule::registerAutoloaders/registerServices/registerEvents|A6(Sys::load ComposerAutoloadPath)
A6 --> A7(SuperApp::handle)
A7 --> |params=func_get_args, Event: superapp:beforeExecModule|B1(SuperApp::defaultModule->exec with params)
B1 --> |Event: superapp:afterExecModule|B2(AbstractModule::registerEngine)
B2 --> |Event: module:beforeStartEngine|B3(AbstractModule::exec with params)
B3 --> B31(RunMode: Cli) --> C1(PhalconCliConsole::handle) --> D1
B3 --> B32(RunMode: Web)
B3 --> B33(RunMode: Srv)
B32 --> C2{EngineWeb::handler is}
C2 --> |request:GuzzleHttp\Psr7\ServerRequest|C21(PsrHandler::handle) --> D1
C2 --> |reqeust:String|C22(PhalconMvcApplication::handle) --> D1
C2 --> C23(Excepton: Invalid Handler)
B33 --> C3{application.handler==yar?}
C3 --> |yes|C31(YarService::handle) --> D1
C3 --> |no|C32(SimpleService::handle) --> D1
D1(Event: module:afterStartEngine) --> |Event: superapp:afterExecModule|D2(Return)
# 下载骨架
➜ composer create-project bullsoft/fp-project fp-app
# 生成模块,假设生成的模块名为test
➜ cd fp-app
➜ ./common/bin/fp-devtool module:create
现在开始引导您创建Phalcon+模块 ...
Step 1 请输入该模块的名称,如"api"
[Enter]: test
Step 2 ...
...
...
The structure of a web module is as follows: All modes are integrated in the web module, including Cli and RpcService.
test
.
├── app
│ ├── Module.php
│ ├── auth
│ │ ├── AclResources.php
│ │ ├── Model.php
│ │ ├── Resources
│ │ │ ├── Actions.php
│ │ │ └── Models.php
│ │ └── User.php
│ ├── config
│ │ └── dev.php
│ ├── controllers
│ │ ├── BaseController.php
│ │ ├── ErrorController.php
│ │ ├── IndexController.php
│ │ ├── UserController.php
│ │ └── apis
│ │ └── DemoController.php
│ ├── events
│ │ ├── Acl.php
│ │ ├── AppConsole.php
│ │ ├── AppHandler.php
│ │ ├── BackendServer.php
│ │ ├── Db.php
│ │ ├── EventProvider.php
│ │ ├── Model.php
│ │ ├── MvcDispatch.php
│ │ ├── Router.php
│ │ ├── SuperApp.php
│ │ └── View.php
│ ├── exceptions
│ │ ├── EnumExceptionCode.php
│ │ ├── Handler.php
│ │ ├── UnknownException.php
│ │ ├── UserAlreadyExistsException.php
│ │ └── UserNotExistsException.php
│ ├── plugins
│ │ └── Volt.php
│ ├── providers
│ │ ├── CookieServiceProvider.php
│ │ ├── CryptServiceProvider.php
│ │ ├── DatabaseServiceProvider.php
│ │ ├── DispatcherServiceProvider.php
│ │ ├── LoggerServiceProvider.php
│ │ ├── RedisServiceProvider.php
│ │ ├── RouterServiceProvider.php
│ │ ├── RpcServiceProvider.php
│ │ ├── ServiceProvider.php
│ │ ├── SessionServiceProvider.php
│ │ ├── UrlServiceProvider.php
│ │ └── ViewServiceProvider.php
│ ├── routes
│ │ ├── Api.php
│ │ └── Bare.php
│ └── views
│ ├── error
│ │ ├── show403.volt
│ │ ├── show404.volt
│ │ └── show500.volt
│ ├── index
│ │ └── index.volt
│ └── index.volt
├── cli
│ ├── init.php
│ └── tasks
│ └── HelloTask.php
├── public
│ ├── index.php
│ └── rpc.php
├── src
│ ├── models
│ │ └── UserModel.php
│ ├── protos
│ │ ├── Enums
│ │ │ └── UserStatus.php
│ │ └── Schemas
│ │ └── RegInfo.php
│ └── services
│ ├── BaseService.php
│ └── DemoService.php
└── var
└── cache
➜ ./common/bin/fp-devtool server:start test
正在为您启动服务器...
{
" command " : " { (php -S 0.0.0.0:8181 -t public/ .htrouter.php) <&3 3<&- 3>/dev/null & } 3<&0;pid= $! ; echo $pid > /path/to/test/var/run/server.pid " ,
" pid " : 8249,
" running " : true,
" signaled " : false,
" stopped " : false,
" exitcode " : -1,
" termsig " : 0,
" stopsig " : 0
}
... 启动成功,请使用 http://127.0.0.1:8181 访问 ➜ cd test
➜ ../vendor/bin/ppm start --bridge="PhalconPlus\Bridge" --bootstrap="PhalconPlus\Bootstrap" --static-directory=public/ --port=8181 --workers=2
Of course, you can also create configuration files to make it easier to start each time
➜ cd test
➜ touch ppm.json
➜ ../vendor/bin/ppm start -c ppm.json
The content of ppm.json is as follows:
{
"bridge" : " PhalconPlus \ Bridge " ,
"host" : " 127.0.0.1 " ,
"port" : 8181 ,
"workers" : 2 ,
"app-env" : " dev " ,
"debug" : 1 ,
"logging" : 1 ,
"static-directory" : " public/ " ,
"bootstrap" : " PhalconPlus \ Bootstrap " ,
"max-requests" : 1000 ,
"concurrent-requests" : 20 ,
"php-cgi" : " /usr/local/opt/[email protected]/bin/php "
} ➜ composer require spiral/roadrunner
➜ cd test
➜ touch .rr.json
➜ touch psr-worker.php
The content of .rr.json is as follows:
{
"http" : {
"address" : " 0.0.0.0:8181 " ,
"workers" : {
"command" : " /usr/local/opt/[email protected]/bin/php psr-worker.php " ,
"relay" : " unix://rr.sock " ,
"pool" : {
"numWorkers" : 2
}
}
},
"static" : {
"enable" : true ,
"dir" : " public " ,
"forbid" : [ " .php " , " .htaccess " ]
}
}The content of psr-worker.php is as follows:
<?php
use Spiral Goridge ;
use Spiral RoadRunner ;
use PhalconPlus Http PsrResponseFactory ;
ini_set ( ' display_errors ' , ' stderr ' );
$ app = ( new PhalconPlus Bootstrap ( __DIR__ ))-> app ();
$ worker = new RoadRunner Worker (
new Goridge SocketRelay ( __DIR__ . " /rr.sock " , null , Goridge SocketRelay:: SOCK_UNIX )
);
$ psr7 = new RoadRunner PSR7Client ( $ worker );
while ( $ req = $ psr7 -> acceptRequest ()) {
try {
$ resp = $ app -> handle ( $ req );
} catch ( Throwable $ e ) {
Test Exceptions Handler:: catch ( $ e );
$ resp = $ app -> response ();
}
$ psr7 -> respond (PsrResponseFactory:: create ( $ resp ));
$ app -> terminate ();
unset( $ req , $ resp );
}Then execute in the module directory
➜ rr serve -d -v
Configuration File
server {
listen 8181 ;
server_name localhost;
access_log /var/log/nginx/test.access.log;
index index.php index.html index.htm;
set $root_path '/home/work/wwwroot/fp-app/test/public' ;
root $root_path ;
try_files $uri $uri / @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php last ;
}
location ~ .php {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path ;
}
location ~ /.ht {
deny all ;
}
}Any feedback is welcome and I hope to receive donations and support from everyone.
I wish you all the best, no Brother 82:)