├── bootstrap
├── autoload.php
├── bin
│ ├── install.bat
│ └── moon
├── php
│ └── route.php
└── app.php
├── .gitignore
├── apps
├── Http
│ ├── Index
│ │ ├── Config
│ │ │ └── providers.php
│ │ └── Controllers
│ │ │ └── IndexController.php
│ └── Common
│ │ ├── Controllers
│ │ └── Controller.php
│ │ └── Views
│ │ └── Error
│ │ ├── 500.html
│ │ └── 404.html
├── Providers
│ ├── EmailServiceProvider.php
│ ├── QueueServiceProvider.php
│ └── SessionServiceProvider.php
├── Console
│ ├── Commands
│ │ ├── Queue
│ │ │ ├── RestartCommand.php
│ │ │ ├── StopCommand.php
│ │ │ └── StartCommand.php
│ │ ├── DemoCommand.php
│ │ └── CreateIdeCommand.php
│ ├── Tasks
│ │ └── MainTask.php
│ ├── Config
│ │ └── commands.php
│ └── Jobs
│ │ └── DemoJob.php
├── Events
│ ├── DbBeforeQueryEvent.php
│ └── RequestEvent.php
├── Listeners
│ ├── RequestLogListener.php
│ └── DbLogListener.php
├── Facades
│ ├── Containers
│ │ ├── QueueContainer.php
│ │ ├── SessionContainer.php
│ │ └── ConfigContainer.php
│ └── Kernel.php
├── Services
│ ├── EventService.php
│ └── QueueService.php
└── Exceptions
│ ├── Handlers
│ ├── QueueHandler.php
│ ├── ErrorEmailHandler.php
│ ├── ShowProdHandler.php
│ └── NotRouteHandler.php
│ └── Kernel.php
├── moon
├── public
├── .htaccess
└── index.php
├── .env.example
├── config
├── database.php
├── queue.php
└── app.php
├── composer.json
└── README.md
/bootstrap/autoload.php:
--------------------------------------------------------------------------------
1 | handle();
--------------------------------------------------------------------------------
/bootstrap/bin/install.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | SET MOON_PATH=%~dp0
4 |
5 | SET PATH=%PATH%%MOON_PATH%
6 |
7 | reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" /t REG_EXPAND_SZ /d "%PATH%
8 | pause
--------------------------------------------------------------------------------
/bootstrap/php/route.php:
--------------------------------------------------------------------------------
1 |
4 | RewriteEngine On
5 | RewriteCond %{REQUEST_FILENAME} !-d
6 | RewriteCond %{REQUEST_FILENAME} !-f
7 | RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
8 |
9 |
--------------------------------------------------------------------------------
/apps/Console/Commands/Queue/RestartCommand.php:
--------------------------------------------------------------------------------
1 | handle();
12 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | # 项目名称
2 | APP_NAME=PPE
3 | # 环境名称
4 | APP_ENV=local
5 | # 日记级别
6 | APP_LOG_LEVEL
7 | # 调试模式
8 | APP_DEBUG=true
9 | # set app key
10 | APP_KEY=敏感功能可以使用这个key进行加密,session,签名等
11 | # 时区设置
12 | TIMEZONE=Asia/Shanghai
13 |
14 | # 队列设置
15 | QUEUE_REDIS_HOST=redis
16 | QUEUE_REDIS_PORT=6379
--------------------------------------------------------------------------------
/apps/Http/Index/Controllers/IndexController.php:
--------------------------------------------------------------------------------
1 | [
5 | 'host' => env('DB_HOST', 'mysql'),
6 | 'username' => env('DB_USERNAME', 'root'),
7 | 'password' => env('DB_PASSWORD', '123456'),
8 | 'dbname' => env('DB_DATABASE', 'wechat'),
9 | 'port' => '3306',
10 | 'charset' => 'utf8'
11 | ],
12 | ];
--------------------------------------------------------------------------------
/apps/Console/Tasks/MainTask.php:
--------------------------------------------------------------------------------
1 | connection = $connection;
22 | }
23 | }
--------------------------------------------------------------------------------
/apps/Events/RequestEvent.php:
--------------------------------------------------------------------------------
1 | dispatcher = $dispatcher;
24 | }
25 | }
--------------------------------------------------------------------------------
/apps/Listeners/RequestLogListener.php:
--------------------------------------------------------------------------------
1 | dispatcher->getModuleName().'/'.$event->dispatcher->getControllerName().'/'.$event->dispatcher->getActionName();
19 | \Log::debug($uri,$event->dispatcher->getParams());
20 | }
21 | }
--------------------------------------------------------------------------------
/config/queue.php:
--------------------------------------------------------------------------------
1 | env('QUEUE_RUN_RIGHT_NOW', false),
11 | // 队列的reids
12 | 'redis_backend' => env('QUEUE_REDIS_HOST', '127.0.0.1') . ':' . env('QUEUE_REDIS_PORT', '6379'),
13 | // 队列分组,组是启动最小单位
14 | 'group'=>[
15 | 'default'=>[
16 | 'interval'=>1,
17 | 'worker'=>4,
18 | 'queue_name' => [
19 | 'default'
20 | ],
21 | ],
22 | ],
23 | ];
--------------------------------------------------------------------------------
/apps/Facades/Containers/QueueContainer.php:
--------------------------------------------------------------------------------
1 | getShared('queue');
28 | }
29 | }
--------------------------------------------------------------------------------
/apps/Facades/Containers/SessionContainer.php:
--------------------------------------------------------------------------------
1 | getShared('session');
28 | }
29 | }
--------------------------------------------------------------------------------
/apps/Listeners/DbLogListener.php:
--------------------------------------------------------------------------------
1 | connection;
19 | $data = $connection->getsqlVariables();
20 | if( !empty($data) ){
21 | \Log::debug("\n".$connection->getSQLStatement()."\n".var_export($data,true));
22 | }else{
23 | \Log::debug($connection->getSQLStatement());
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/bootstrap/bin/moon:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | dir=$(d=${0%[/\\]*}; cd "$d" > /dev/null; cd "../../" && pwd)
4 |
5 | # See if we are running in Cygwin by checking for cygpath program
6 | if command -v 'cygpath' >/dev/null 2>&1; then
7 | # Cygwin paths start with /cygdrive/ which will break windows PHP,
8 | # so we need to translate the dir path to windows format. However
9 | # we could be using cygwin PHP which does not require this, so we
10 | # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
11 | if [[ $(which php) == /cygdrive/* ]]; then
12 | dir=$(cygpath -m "$dir");
13 | fi
14 | fi
15 |
16 | dir=$(echo $dir | sed 's/ /\ /g')
17 | "${dir}/moon" "$@"
--------------------------------------------------------------------------------
/apps/Providers/QueueServiceProvider.php:
--------------------------------------------------------------------------------
1 | di->setShared($this->serviceName,function (){
27 | return new QueueService();
28 | });
29 | }
30 | }
--------------------------------------------------------------------------------
/apps/Console/Commands/DemoCommand.php:
--------------------------------------------------------------------------------
1 | setName('demo')->setDescription('示范命令');
20 | }
21 |
22 | protected function execute(InputInterface $input, OutputInterface $output)
23 | {
24 | $output->writeln('this is demo ');
25 | }
26 | }
--------------------------------------------------------------------------------
/apps/Services/EventService.php:
--------------------------------------------------------------------------------
1 | [
27 | DbLogListener::class
28 | ],
29 | RequestEvent::class =>[
30 | RequestLogListener::class,
31 | ],
32 | ];
33 | }
--------------------------------------------------------------------------------
/apps/Services/QueueService.php:
--------------------------------------------------------------------------------
1 | toArray();
19 | Resque::setBackend($config['redis_backend']);
20 | }
21 |
22 | public function put($obj=false)
23 | {
24 | if( $obj instanceof Queue){
25 | return Resque::enqueue($obj->getQueueName(),get_class($obj),$obj->getParams(),false);
26 | }else{
27 | throw new \Exception('JOB必须继承与'.Queue::class);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/apps/Providers/SessionServiceProvider.php:
--------------------------------------------------------------------------------
1 | di->setShared($this->serviceName,function (){
26 | $session = new Files();
27 | $session->start();
28 | return $session;
29 | });
30 | }
31 | }
--------------------------------------------------------------------------------
/apps/Exceptions/Handlers/QueueHandler.php:
--------------------------------------------------------------------------------
1 | getException();
29 | if( $exception instanceof QueueException){
30 |
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/apps/Exceptions/Handlers/ErrorEmailHandler.php:
--------------------------------------------------------------------------------
1 | getRun();
23 | $handler = new GetEmailPrettyPageHandler();
24 | $handler->setRun($whoops);
25 | $handler->setInspector($this->getInspector());
26 | $handler->setException($this->getException());
27 | $emailBody = $handler->handle();
28 |
29 | // 开发发送邮件
30 | }
31 | }
--------------------------------------------------------------------------------
/apps/Facades/Kernel.php:
--------------------------------------------------------------------------------
1 | LogContainer::class,
29 | 'Event'=>EventContainer::class,
30 | 'Config'=>ConfigContainer::class,
31 | 'Queue'=>QueueContainer::class,
32 | 'Session'=>SessionContainer::class,
33 | ];
34 | }
35 | }
--------------------------------------------------------------------------------
/bootstrap/app.php:
--------------------------------------------------------------------------------
1 | initializeServices([
16 | \Framework\Providers\ConfigServiceProvider::class,
17 | \Framework\Providers\ModulesRouteServiceProvider::class,
18 | \Framework\Providers\MvcDispatcherServiceProvider::class,
19 | \Framework\Providers\LoggerServiceProvider::class,
20 | \Framework\Providers\ExceptionHandlerServiceProvider::class,
21 | \Framework\Providers\LoadFacadeServiceProvider::class,
22 | \Framework\Providers\EventServiceProvider::class,
23 |
24 | // 引入数据库
25 | \Framework\Providers\DatabaseServiceProvider::class,
26 | // 引入队列
27 | \Apps\Providers\QueueServiceProvider::class,
28 | ]);
29 |
30 | $app->init();
31 |
32 | return $app;
--------------------------------------------------------------------------------
/apps/Console/Jobs/DemoJob.php:
--------------------------------------------------------------------------------
1 | test = $value;
29 | }
30 |
31 | /**
32 | * 可选参数
33 | *
34 | * @param string $optional
35 | */
36 | protected function setParamTestOptional($optional='默认值')
37 | {
38 | $this->optional = $optional;
39 | }
40 |
41 | /**
42 | * 任务入口
43 | *
44 | * @return mixed
45 | */
46 | public function handle()
47 | {
48 | \Log::info('队列参数'.$this->test);
49 | }
50 | }
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "selden1992/ppe",
3 | "description": "The ppe Framework.",
4 | "keywords": ["framework", "phalcon", "laravel"],
5 | "license": "MIT",
6 | "type": "project",
7 | "authors": [
8 | {
9 | "name": "明月有色",
10 | "email": "2206582181@qq.com"
11 | }
12 | ],
13 | "autoload-dev": {
14 | "psr-4": {
15 | "Apps\\": "apps/",
16 | "Tests\\": "tests/"
17 | }
18 | },
19 | "repositories": {
20 | "packagist": {
21 | "type": "composer",
22 | "url": "https://packagist.phpcomposer.com"
23 | }
24 | },
25 | "require": {
26 | "selden1992/ppe-framework": "^1.0",
27 | "mashape/unirest-php": "^3.0",
28 | "chrisboulton/php-resque": "^1.2",
29 | "phpmailer/phpmailer": "^6.0",
30 | "workerman/gateway-worker": "^3.0",
31 | "yzalis/identicon": "^1.2",
32 | "workerman/gatewayclient": "^3.0"
33 | },
34 | "require-dev": {
35 | "phalcon/ide-stubs": "*"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/apps/Http/Common/Controllers/Controller.php:
--------------------------------------------------------------------------------
1 | cookies->useEncryption(false);
19 | $this->view->webTitle = '站点标题';
20 | Gateway::$registerAddress = '127.0.0.1:1238';
21 | }
22 |
23 | public function response($data)
24 | {
25 | if( is_string($data) ){
26 | $this->response->setContentType('text/html; charset=utf-8');
27 | $this->response->setContent($data);
28 | }else{
29 | $this->response->setContentType('application/json');
30 | $this->response->setContent(json_encode($data,JSON_UNESCAPED_UNICODE));
31 | }
32 | return $this->response;
33 | }
34 | }
--------------------------------------------------------------------------------
/config/app.php:
--------------------------------------------------------------------------------
1 | env('APP_NAME','PPE'),
11 | /**
12 | * 调试模块
13 | */
14 | 'debug' => env('APP_DEBUG', true),
15 | /**
16 | * 环境名称
17 | */
18 | 'env' => env('APP_ENV', 'production'),
19 |
20 | /**
21 | * 根目录
22 | */
23 | 'base_path'=>dirname(__DIR__),
24 |
25 | /**
26 | * 日记配置
27 | * 记录最小log级别
28 | */
29 | 'log_level' => env('APP_LOG_LEVEL', 'debug'),
30 | /**
31 | * 历史log存储日期
32 | */
33 | 'log_max_files' => 30,
34 |
35 | /**
36 | * 时区设置
37 | */
38 | 'timezone' => env('TIMEZONE','Asia/Shanghai'),
39 |
40 | /**
41 | * 默认模块
42 | */
43 | 'default_module'=>'wechat',
44 | /**
45 | * 模块配置
46 | */
47 | 'modules' => [
48 | "wechat" => [
49 | // 命名空间格式名称
50 | "nameSpace" => 'Index',
51 | // 绑定的域名
52 | "domain" => "www.ppe.app",
53 | // 核心类型
54 | 'core' => 'full',
55 | ],
56 | ],
57 | ];
--------------------------------------------------------------------------------
/apps/Exceptions/Handlers/ShowProdHandler.php:
--------------------------------------------------------------------------------
1 | getView();
36 |
37 | // Start the output buffering
38 | $view->start();
39 |
40 | try{
41 | // Render all the view hierarchy related to the view products/list.phtml
42 | $view->render("Error", "500");
43 | }catch (ErrorException $exception){
44 | $cachePath = App::getRootPath() . '/storage/cache/view';
45 | if( !is_dir($cachePath) ){
46 | mkdir($cachePath,0755,true);
47 | }
48 | $view->render("Error", "500");
49 | }
50 |
51 | // Finish the output buffering
52 | $view->finish();
53 |
54 | echo $view->getContent();
55 | }
56 | }
--------------------------------------------------------------------------------
/apps/Http/Common/Views/Error/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Page Not Found
9 |
10 |
11 |
12 |
13 |
14 |
47 |
48 |
49 |
50 |
51 |
52 | Whoops, looks like something went wrong.
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/apps/Http/Common/Views/Error/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Page Not Found
9 |
10 |
11 |
12 |
13 |
14 |
47 |
48 |
49 |
50 |
51 |
52 | Sorry, the page you are looking for could not be found.
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/apps/Console/Commands/Queue/StopCommand.php:
--------------------------------------------------------------------------------
1 | setName('queue:stop')
21 | ->setDescription('停止队列[QUIT、USR1、USR2、CONT]')
22 | ->addOption('sigspec',null,InputOption::VALUE_OPTIONAL,'退出信号');
23 | }
24 |
25 | protected function execute(InputInterface $input, OutputInterface $output)
26 | {
27 | $sigspec = $input->getOption('sigspec');
28 | if( $GLOBALS['argv'][0]!=realpath($GLOBALS['argv'][0]) ){
29 | // 执行加上路径,用来区别多个项目
30 | $GLOBALS['argv'][0] = realpath($GLOBALS['argv'][0]);
31 | }
32 | $commandPath = $GLOBALS['argv'][0];
33 | exec('ps -ax -o pid -o cmd|grep "'.$commandPath.' queue:start"',$arr);
34 | foreach ($arr as $str){
35 | $arr = explode(' ',trim($str));
36 | if( isset($arr[1]) && strpos($arr[1],'php')!==false ){
37 | $pid = $arr[0];
38 | $sig = $sigspec?' -'.$sigspec:' -9';
39 | $kill = "kill{$sig} {$pid}";
40 | exec($kill);
41 | $output->writeln("{$kill}");
42 | }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/apps/Exceptions/Handlers/NotRouteHandler.php:
--------------------------------------------------------------------------------
1 | getException() instanceof Exception){
26 | if( Misc::isAjaxRequest() ){
27 | return false;
28 | }
29 | /**
30 | * 当关闭调试模式时
31 | * 显示一个精简错误页面
32 | * 为了跨模块显示错误页面,这里使用了公共模块的视图
33 | */
34 | $view = $this->getView();
35 |
36 | // Start the output buffering
37 | $view->start();
38 |
39 | try{
40 | // Render all the view hierarchy related to the view products/list.phtml
41 | $view->render("Error", "404");
42 | }catch (ErrorException $exception){
43 | $cachePath = App::getRootPath() . '/storage/cache/view';
44 | if( !is_dir($cachePath) ){
45 | mkdir($cachePath,0755,true);
46 | }
47 | $view->render("Error", "404");
48 | }
49 |
50 | // Finish the output buffering
51 | $view->finish();
52 |
53 | echo $view->getContent();
54 |
55 | // 如果只是访问地址错误-可以立马退出
56 | return Handler::QUIT;
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/apps/Exceptions/Kernel.php:
--------------------------------------------------------------------------------
1 | pushHandler(new QueueHandler());
42 | $run->pushHandler(new PlainTextHandler());
43 | }
44 |
45 | /**
46 | * 注册自定义错误处理-页面模块
47 | *
48 | * @param Run $run
49 | */
50 | public function registerForWeb(Run &$run)
51 | {
52 | // 500页面显示
53 | $run->pushHandler(new ShowProdHandler());
54 |
55 | // 调试下,可以显示更加具体的错误
56 | if ( Di::getDefault()->get('config')->debug ) {
57 | // 开始调试
58 | if (Misc::isAjaxRequest()) {
59 | $run->pushHandler(new JsonResponseHandler());
60 | } else {
61 | $run->pushHandler(new PrettyPageHandler());
62 | // 检查模块是否初始化
63 | $run->pushHandler(new InitModuleHandler());
64 | }
65 | }
66 |
67 | // 404页面显示,404不需要特殊处理,可以放到后面推入,最先处理
68 | $run->pushHandler(new NotRouteHandler());
69 | }
70 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 一个基于phalcon的laravel框架,php7.0以上版本,composer安装
2 |
3 |
4 |
5 |
6 |
7 |
8 | ## About ppe
9 |
10 | > **Note:** ,phalcon框架本身提供一系列的功能,但是需要整合在一起才能完成一个完整的项目目录,本项目的目的是把phalcon可以有laravel的舒适度、友好、简单、完备的各种好处,但又不失性能。
11 |
12 | 已经集成的功能
13 |
14 | - [env](https://packagist.org/packages/selden1992/ppe) 使用不同环境启用对应的env配置
15 | - [多模块](https://packagist.org/packages/selden1992/ppe) 根据域名或端口自动启动不同模块
16 | - [命令行模块](https://laravel.com/docs/container) 定时任务下,使用phalcon的cli应用,普通命令基于symfony的console
17 | - [异常](https://packagist.org/packages/selden1992/ppe) 使用whoops调试神器,代码调试非常方便,自带的异常发送邮件提示功能
18 | - [Facades门脸](https://packagist.org/packages/selden1992/ppe) Db、Log等常用类都提供根命名的门脸,也允许业务自己注册自己的容器门脸
19 | - [日志](https://packagist.org/packages/selden1992/ppe) 默认使用monolog,因为phalcon自带的log不好扩展,当然,也允许使用phalcon的log类,只要Di注入即可
20 | - [事件](https://packagist.org/packages/selden1992/ppe) 事件和监听器配置,可以满足大多数需求变更
21 |
22 | ## 安装
23 |
24 | 如果安装不上,记得切换国内composer镜像
25 | ~~~~
26 | composer create-project selden1992/ppe
27 | ~~~~
28 |
29 | ## 多模块
30 |
31 | [config/app.php](CODE_OF_CONDUCT.md)配置多模块
32 | ~~~~
33 | 'default_module'=>'index',
34 | 'modules' => [
35 | "index" => [
36 | // 命名空间格式名称
37 | "nameSpace" => 'Index',
38 | "domain" => env('index_domain',"www.ppe.app"),
39 | 'core' => 'full',
40 | ],
41 | ],
42 | ~~~~
43 | 可以配合.env配置,区分不同环境的模块配置
44 |
45 |
46 | ## Facades门脸
47 |
48 | Facades的使用对开发非常有帮助,例如发送短信功能,本地调试使用写日志方式调试,正式环境就真实发送,只要业务层统一使用门脸调用,就可以无缝地切换
49 |
50 | [apps/Facades/Kernel.php](CODE_OF_CONDUCT.md)注册业务门脸
51 |
52 | 所有门脸都是惰性加载
53 |
54 |
55 | ## Exceptions异常
56 |
57 | 处理框架自带的异常处理handler外,可以在[apps/Exceptions/Kernel.php](CODE_OF_CONDUCT.md)注册业务异常处理,例如错误发生邮件、发生日记管理系统
58 |
59 | 已有handler(错误日志记录,404页面处理,500页面处理)
60 |
61 | ## 如何对框架进行修改
62 |
63 | 本框架完全使用DI贯穿整个项目,为了就是可像usb那样,快速切换或者添加功能
64 |
65 | 修改[boostsrap/app.php](CODE_OF_CONDUCT.md)文件的initializeServices内容,就可以替换框架任意功能
66 |
67 |
68 | ## License
69 |
70 | The ppe framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
71 |
--------------------------------------------------------------------------------
/apps/Console/Commands/Queue/StartCommand.php:
--------------------------------------------------------------------------------
1 | setName('queue:start')
24 | ->setDescription('启动队列')
25 | ->addOption('group', null,InputOption::VALUE_OPTIONAL, '队列分组名称', '*');
26 | }
27 |
28 | protected function execute(InputInterface $input, OutputInterface $output)
29 | {
30 | if( $GLOBALS['argv'][0]!=realpath($GLOBALS['argv'][0]) ){
31 | // 执行加上路径,用来区别多个项目
32 | $GLOBALS['argv'][0] = realpath($GLOBALS['argv'][0]);
33 | $cmd = implode(' ',$GLOBALS['argv']);
34 | passthru("php {$cmd}");
35 | exit(0);
36 | }
37 | $group = $input->getOption('group');
38 | $runGroup = [];
39 | if ($group == '*') {
40 | // 启动所有
41 | $runGroup = \Config::get('queue.group', []);
42 | } else {
43 | $config = \Config::get('queue.group.' . $group, []);
44 | if ($config) {
45 | $runGroup = [$config];
46 | } else {
47 | $output->writeln("分组名称不在配置文件里");
48 | }
49 | }
50 | $config = \Config::get('queue')->toArray();
51 | Resque::setBackend($config['redis_backend']);
52 | $countGroup = count($runGroup);
53 | foreach ($runGroup as $name=>$groupName) {
54 | $countGroup--;
55 | $countPid = $groupName['worker'];
56 | for ($i = 0; $i < $groupName['worker']; ++$i) {
57 | $pid = pcntl_fork();
58 | $countPid--;
59 | if ($pid == -1) {
60 | die("Could not fork worker " . $i . "\n");
61 | } else if (!$pid) {
62 | $queues = $groupName->queue_name->toArray();
63 | $worker = new Resque_Worker($queues);
64 | fwrite(STDOUT, '*** Starting worker ' . $worker . "\n");
65 | if( $countGroup<=0 && $countPid<=0 ){
66 | unset($countGroup,$countPid,$queues);
67 | fwrite(STDOUT, "\n");
68 | $output->writeln("Press Ctrl+C to quit. Start success.");
69 | }
70 | $worker->work( $groupName['interval'] );
71 | exit(0);
72 | }
73 | }
74 | }
75 | exit(0);
76 | }
77 | }
--------------------------------------------------------------------------------
/apps/Facades/Containers/ConfigContainer.php:
--------------------------------------------------------------------------------
1 | getShared('config');
35 | }
36 |
37 | /**
38 | * 读取配置-自动加载配置文件
39 | *
40 | * @param string $key
41 | * @param string $default
42 | * @return mixed|null|Config
43 | */
44 | public static function get($key=null,$default=null)
45 | {
46 | if( $key===null ){
47 | return self::$_instance;
48 | }elseif ( !strpos($key,'.') ){
49 | $value = self::$_instance->get($key);
50 | if( $value===null ){
51 | $value = self::getFileConfig($key);
52 | if( $value===false ){
53 | return $default;
54 | }
55 | return $value;
56 | }else{
57 | return $value;
58 | }
59 | }
60 | $arrConfigKey = explode('.',$key);
61 | $config = self::$_instance;
62 | $value = $config->get($arrConfigKey[0]);
63 | foreach ($arrConfigKey as $num=>$keyNext){
64 | if( $value===null ){
65 | if( $num==0 ){
66 | $value = self::getFileConfig($keyNext);
67 | }else{
68 | return $default;
69 | }
70 | }elseif( $value instanceof Config){
71 | $config = $value;
72 | $value = $config->get($keyNext);
73 | }elseif( $num==0 ){
74 | $value = self::getFileConfig($keyNext);
75 | if( $value===null ) {
76 | return $default;
77 | }
78 | }
79 | }
80 | return $value;
81 | }
82 |
83 | private static function getFileConfig($fileName)
84 | {
85 | $value = false;
86 | $configFile = Di::getDefault()->getShared("module")->modulePath . "/Config/{$fileName}.php";
87 | if( file_exists($configFile) ){
88 | $addConfig = @include_once $configFile;
89 | if( is_array($addConfig) ){
90 | self::$_instance->merge(new Config([$fileName=>$addConfig]));
91 | $value = self::$_instance->get($fileName);
92 | }
93 | }else{
94 | $configFile = App::getRootPath() . "/config/{$fileName}.php";
95 | if( file_exists($configFile) ){
96 | $addConfig = @include_once $configFile;
97 | if( is_array($addConfig) ){
98 | self::$_instance->merge(new Config([$fileName=>$addConfig]));
99 | $value = self::$_instance->get($fileName);
100 | }
101 | }
102 | }
103 | return $value;
104 | }
105 | }
--------------------------------------------------------------------------------
/apps/Console/Commands/CreateIdeCommand.php:
--------------------------------------------------------------------------------
1 | setName('create:ide')->setDescription('创建facades的ide提示');
23 | }
24 |
25 | protected function execute(InputInterface $input, OutputInterface $output)
26 | {
27 | $Kernel = new Kernel();
28 |
29 | $arrFacades = $Kernel->getFacades();
30 |
31 | if ($arrFacades && is_array($arrFacades)) {
32 | foreach ($arrFacades as $facade => $containers) {
33 | $realObj = $containers::getFacadesAccessor();
34 | if (!is_object($realObj)) {
35 | $realObj = new $realObj();
36 | }
37 | $this->createObjIde($facade, $realObj);
38 | }
39 | }
40 | $output->writeln('创建成功 ');
41 | }
42 |
43 | protected function createObjIde($facade, $object)
44 | {
45 | $nn = PHP_EOL;
46 | $ReflectionClass = new \ReflectionClass($object);
47 | foreach ($ReflectionClass->getMethods() as $reflectionMethod) {
48 | if ($reflectionMethod->getName() != '__construct') {
49 | if ($reflectionMethod->isPublic()) {
50 | $publicFunctions[] = $this->getFunIde($reflectionMethod);
51 | }
52 | }
53 | }
54 | $strFunction = implode(PHP_EOL, $publicFunctions);
55 | $strFunction = "getParameters();
68 | $arrParam = [];
69 | foreach ($Parameters as $parameter) {
70 | $objType = $parameter->getType();
71 | if (is_object($objType)) {
72 | if (method_exists($objType, 'getName')) {
73 | $type = $objType->getName() . ' ';
74 | } else {
75 | $type = $objType->__toString() . ' ';
76 | }
77 | $lineKey = __FILE__.__LINE__;
78 |
79 | try {
80 | $DefaultValue = $parameter->getDefaultValue();
81 | } catch (\Exception $exception) {
82 | $DefaultValue = $lineKey;
83 | }
84 |
85 | if ($DefaultValue !== $lineKey) {
86 | $DefaultValue = '=' . str_replace([PHP_EOL, ' '], '', var_export($DefaultValue, true));
87 | }else{
88 | $DefaultValue = '';
89 | }
90 | $arrParam[] = $type . '$' . $parameter->getName() . $DefaultValue;
91 | } elseif( $parameter->isOptional() ) {
92 | if( $parameter->allowsNull() ){
93 | $DefaultValue = '=' . str_replace([PHP_EOL, ' '], '', var_export($parameter->getDefaultValue(), true));
94 | $arrParam[] = '$' . $parameter->getName(). $DefaultValue;
95 | }else{
96 | $arrParam[] = '$' . $parameter->getName()."=''";
97 | }
98 | } else {
99 | $arrParam[] = '$' . $parameter->getName();
100 | }
101 | }
102 | $strReturn = "return '';";
103 | $stringParam = implode(',', $arrParam);
104 | $publicFunctions = "{$s4}{$reflectionMethod->getDocComment()}{$nn}{$s4}public static function {$reflectionMethod->getName()}({$stringParam}){$nn}{$s4}{{$nn}{$s4}{$s4}{$strReturn}{$nn}{$s4}}{$nn}";
105 | return $publicFunctions;
106 | }
107 | }
--------------------------------------------------------------------------------