2017 © Pedro Peláez
 

project app

my framework app

image

myf/app

my framework app

  • Friday, May 25, 2018
  • by owenliang
  • Repository
  • 3 Watchers
  • 8 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 50 % Grown

The README.md

myf-app

介绍

myf means 'my framework', (*1)

我一直想自己做个简单的不能再简单的PHP框架,为了少一件心事,所以抽了点时间搞出来。, (*2)

原则

  • 框架核心myf-core作为composer library发布
  • 框架脚手架myf-app作为composer project发布,依赖myf-core包
  • 支持多应用开发,共享公共代码
  • 基于namespace的类自动加载
  • 没有IOC容器,namespace本身就是单例
  • 没有框架基类,不绑架开发者习惯,PHP原汁原味

使用脚手架

myf/app, (*3)

组成

common...

公共代码,被多个应用共享访问,命名空间以common\为前缀,可以实现类自动加载, (*4)

app...

单个应用,命名空间以\app为前缀, (*5)

common/config/myf.php

跨应用共享配置, (*6)

app/config/myf.php

单个应用的独有配置, (*7)

app/webroot/index.php

单个应用的入口文件,复制到其他应用不需要修改, (*8)

<?php

// composer
require_once __DIR__ . '/../../vendor/autoload.php';

// 框架根目录
define('MYF_ROOT', __DIR__ . '/../../');

// 应用根目录
define('APP_ROOT', __DIR__ . '/../');

// 合并配置
$config = array_merge_recursive(require MYF_ROOT . 'common/config/myf.php', require APP_ROOT . 'config/myf.php');

// 启动框架
\myf\App::run($config);

app\controller...

controller层,实现接口, (*9)

app\model...

model层,实现数据访问,调用Http、Mysql、Redis、Elasticsearch等,model仅仅是个分层而已, (*10)

app\service...

service层,封装可复用的业务逻辑,调用model层获取数据, (*11)

app/view/...php

view层,模板文件,可以嵌套渲染, (*12)

common\model...

通用的model,所有app共享, (*13)

common\service...

通用的service,所有app共享, (*14)

common\view...

通用的view,所有app共享, (*15)

配置

app/config/myf.php

应用特有的配置,比如路由配置。, (*16)

<?php

return [
    // 调试模式
    'debug' => true,

    // 路由配置
    'route' => [
        // 静态路由
        'static' => [
            '/service' => ['Demo', 'service'],
            '/view' => ['Demo', 'view'],
            '/mysql' => ['Demo', 'mysql'],
            '/redis' => ['Demo', 'redis'],
            '/http' => ['Demo', 'http'],
            '/elasticsearch' => ['Demo', 'elasticsearch'],
        ],
        // pcre正则路由
        'regex' => [
            ['^/params/(\d+)$', 'Demo', 'params'],
        ],
    ],
];

common配置

所有应用共享的配置,比如各种客户端的配置。, (*17)

<?php

return [
    // mysql配置
    'mysql' => [
        'default' => [
            'dbname' => 'test_db',
            'username' => 'test_user',
            'password' => 'test_pass',
            'charset' => 'utf8',
            'master' => [
                [
                    'host' => 'localhost',
                    'port' => 3306
                ],
            ],
            'slave' => [
                [
                    'host' => 'localhost',
                    'port' => 3306
                ],
            ]
        ]
    ],

    // redis配置
    'redis' => [
        'default' => [
            'dbIndex' => 0,
            'password' => false,
            'isCluster' => false,
            'timeout' => 2,
            'readTimeout' => 2,
            'master' => [
                [
                    'host' => 'localhost',
                    'port' => 6379,
                ]
            ],
            'slave' => [
                [
                    'host' => 'localhost',
                    'port' => 6379,
                ]
            ]
        ],
        'myCluster' => [
            'dbIndex' => 0,
            'password' => false,
            'isCluster' => true,
            'timeout' => 2,
            'readTimeout' => 2, // 高版本phpredis支持此选项
            'master' => [
                [
                    'host' => 'localhost',
                    'port' => 6379,
                ],
                [
                    'host' => 'localhost',
                    'port' => 6379,
                ]
            ],
        ]
    ],

    // elasticsearch配置
    'elasticsearch' => [
        'default' => [
            'hosts' => ['localhost:9200', ],
            'retries' => 2,
            'connectionParams' => [
                'client' => [
                    'timeout' => 2,
                    'connect_timeout' => 2,
                ]
            ]
        ]
    ],

    // http客户端配置
    'http' => [
        'connectTimeout' => 1,  // 连接超时1秒
        'timeout' => 1, // 请求超时1秒
    ]
];

my-core 框架核心

框架核心composer library, (*18)

The Versions

25/05 2018

1.0.0.x-dev

1.0.0.9999999-dev

my framework app

  Sources   Download

MIT

The Requires

 

by Avatar owenliang

25/05 2018

v1.0.0

1.0.0.0

my framework app

  Sources   Download

MIT

The Requires

 

by Avatar owenliang

23/05 2018

dev-master

9999999-dev

my framework app

  Sources   Download

MIT

The Requires

 

by Avatar owenliang