承接 riverside/php-express 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

riverside/php-express

最新稳定版本:2.0.1

Composer 安装命令:

composer require riverside/php-express

包简介

PHP micro-framework inspired by Express.js

README 文档

README

PHP micro-framework inspired by Express.js

Build GitHub pages Stable License
CI pages-build-deployment Latest Stable Version License

Requirements

  • PHP >= 7.1
  • PHP extensions:
    • JSON (ext-json)

Installation

If Composer is not installed on your system yet, you may go ahead and install it using this command line:

$ curl -sS https://getcomposer.org/installer | php

Next, add the following require entry to the composer.json file in the root of your project.

{
    "require" : {
        "riverside/php-express" : "^2.0.1"
    }
}

Finally, use Composer to install php-express and its dependencies:

$ php composer.phar install 

Routing

<?php
$app = new \Riverside\Express\Application();

$app->get('/', function ($req, $res) {
     $res->send('hello world');
});

Route methods

<?php
// GET method route
$app->get('/', function ($req, $res) {
    $res->send('GET request to the homepage');
});

// POST method route
$app->post('/', function ($req, $res) {
    $res->send('POST request to the homepage');
});

Route paths

<?php
$app->get('/', function ($req, $res) {
    $res->send('root');
});

$app->get('about', function ($req, $res) {
    $res->send('about');
});

$app->get('random.text', function ($req, $res) {
    $res->send('random.text');
});

Response methods

Method Description
$res->end() End the response process.
$res->json() Send a JSON response.
$res->redirect() Redirect a request.
$res->render() Render a view template.
$res->send() Send a response of various types.
$res->sendStatus() Set the response status code and send its string representation as the response body.

$app->route()

<?php
$app->route('/book')
    ->get(function ($req, $res) {
        $res->send('Get a random book');
    })
    ->post(function ($req, $res) {
        $res->send('Add a book');
    })
    ->put(function ($req, $res) {
        $res->send('Update the book');
    });

Router

<?php
$router = new \Riverside\Express\Router($app);

$router->param('uuid', '[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}');

$router->get('/', function ($req, $res) {
    $res->send('Birds home page');
});

$router->get('about', function ($req, $res) {
    $res->send('About birds');
});

$router->get('ticket/:uuid/', function($req, $res) {
    echo $req->params['uuid'];
});

$router->run();

Middleware

$app->use(function($req, $res) {
    $res->header('X-Frame-Options', 'DENY');
    $res->header('X-Powered-By', false);
});

$app->use('/cors', function($req, $res) {
    $res->header('Access-Control-Allow-Origin', '*');
});

统计信息

  • 总下载量: 628
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 35
  • Watchers: 2
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固