abrahanzarza/http-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

abrahanzarza/http-bundle

最新稳定版本:1.0.0

Composer 安装命令:

composer require abrahanzarza/http-bundle

包简介

Module that provides HTTP routing, request and response

README 文档

README

PHP

This library provides a micro HTTP framework with basics, routing and dependency injection container.

Setup

For using this library in your proyect, install it via composer or add it manually in your composer.json file.

composer require abrahanzarza/http-bundle

This will install the latest version in your project.

Usage

Basic configuration

Here is an extract of code for basic configuration usage. At this example we can see that our application is a HttpBundle instance. This instance receive a Symfony\Component\HttpFoundation\Request request param and returns a Symfony\Component\HttpFoundation\Response that is returned to the client.

<?php

declare(strict_types=1);

include_once __DIR__ . '/../vendor/autoload.php';

use AbrahanZarza\HttpBundle\HttpBundle;
use Symfony\Component\HttpFoundation\Request;

$app = new HttpBundle();

// Define your dependencies
// Define your routes

$request = Request::createFromGlobals();
$response = $app->handle($request);

$response->send();

The next thing is define dependencies and routes that we can se how to build after.

Defining dependencies

To define dependencies use PHP-DI syntax.

$app->container->set(
    ClassName::class, 
    static fn(ContainerInterface $c) => new ClassName('params...')
);

As we can see in the code example, we are using our $app DI container.

Defining routes

To define our HTTP application routes we are using this syntax:

$app->route('method', 'path', 'ControllerClass');

If we need to use middleware before executing the controller logic, we can use:

$app->route('method', 'path', 'ControllerClass', 'MiddlewareClass');

Both classes, Controller and Middleware must implement an __Invoke method. An example of controller:

<?php

declare(strict_types=1);

namespace namespace\controllers;

class ControllerClass
{
    public function __invoke(Request $request): Response
    {
        return new Response('Success response');
    }
}

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固