Code Monkey home page Code Monkey logo

mpie-framework-starter's Introduction

Mpie Framework Starter

Lightweight • Simple • Fast

A componentized lightweight PHP framework that supports swoole, workerman, and FPM environments. It can be used for API development, which is convenient and fast. The framework has the session and view extensions installed by default, and can be removed directly if not needed.

Environmental requirements

- PHP >= 8.0
- ext-ctype
- ext-dom
- ext-filter
- ext-json
- ext-libxml
- ext-mbstring
- ext-openssl
- ext-openswoole
- ext-pcntl
- ext-pdo
- ext-phar
- ext-redis
- ext-tokenizer
- ext-xml
- ext-xmlwriter

If you use openswoole, be sure to install version 4.8 or above, if you use workerman, be sure to use version 4.0 or above

use

Install

composer create-project mpie22/framework:dev-main

Start the service

swoole service

php bin/openswoole.php // asynchronous mode
php bin/openswoole-co.php // coroutine mode

workerman service

php bin/workerman.php start

Built-in services

php bin/cli-server.php

FPM mode, direct the request to public/index.php

the difference

Using swoole/workerman to support annotations, AOP and other features, FPM mode can directly uninstall AOP packages.

Getting started

route definition

Annotation definitions can be used under swoole/swooleco/workerman

<?php

namespace App\Controllers;

use App\Http\Response;
use Mpie\Routing\Annotation\Controller;
use Mpie\Routing\Annotation\GetMapping;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

#[Controller(prefix: '/')]
class IndexController
{
    #[GetMapping(path: '/')]
    public function index(ServerRequestInterface $request): ResponseInterface
    {
        return Response::HTML('Hello, ' . $request->query('name', 'MpiePHP!'));
    }
}

The above request 0.0.0.0:8080 will point to the index method, the controller method supports dependency injection, if you need an example of the current request, the request parameter name must be request, other routing parameters will be injected, the controller method An instance of ResponseInterface needs to be returned.

Annotations cannot be used under FPM or built-in services

Route definitions are defined in the map method of the App\Http\Kernel class

$router->middleware(TestMiddleware::class)->group(function(Router $router) {
    $router->get('/', [IndexController::class, 'index']);
    $router->get('/test', function(\Psr\Http\Message\ServerRequestInterface $request) {
        return \App\Http\Response::HTML('new');
    });
});

Thanks

mpie-framework-starter's People

Watchers

 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.