GithubHelp home page GithubHelp logo

phalcon-micro-skeleton's Introduction

Phalcon Micro Skeleton

Phalcon 微服务项目模板

目录结构

├── app
│   ├── config
│   │   ├── config.php
│   │   ├── loader.php
│   │   ├── router.php
│   │   └── services.php
│   │
│   ├── controllers
│   │   └── ControllerBase.php
│   │
│   ├── middlewares
│   │   └── MiddlewareBase.php
│   │
│   ├── models
│   │   └── ModelBase.php
│   │
│   ├── services
│   │
│   ├── tasks
│   │   └── MainTask.php
│   │
│   ├── traits
│   │   └── Model
│   │       └── SoftDelete.php
│   │
│   ├── app.php
│   └── cli.php
│
├── public
│   ├── index.php
│   └── .htaccess
│
├── vendor
│
├── composer.json
├── config.ini
└── index.html

其中,/vendor 是由 composer 安装的依赖包目录,默认为使用 composer 依赖,如果不需要,则将 /public/index.php 中的

require BASE_PATH . '/vendor/autoload.php';

注释或删除即可

中间件

Phalcon 的中间件不支持只对某一组路由生效,因此对中间件封装了一次,可以直接继承 Middlewares\MiddlewareBase,然后重写 public function handle(Micro $app): bool 方法即可;Middlewares\MiddlewareBase 添加了 protected $onlys = [];(白名单) 和 protected $excepts = [];(排除列表),支持正则表达式,例如:

<?php

namespace Middlewares;

use Phalcon\Mvc\Micro;

class AuthMiddleware extends MiddlewareBase
{
    protected $excepts = [
        '/user/login',    // 用户登录
        '/wechat/*',      // 微信被动消息、支付回调等等
    ];

    public function handle(Micro $app): bool
    {
        if (! is_authorized()) {
            return false;
        }

        return true;
    }
}

phalcon-micro-skeleton's People

Contributors

yianandcode avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.