定制 violines/rest-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

violines/rest-bundle

Composer 安装命令:

composer require violines/rest-bundle

包简介

violines/rest-bundle is a Symfony Bundle to create REST APIs. It focusses on HTTP standards and integrates the symfony/serializer and symfony/validator.

README 文档

README

violines/rest-bundle is a Symfony Bundle to create REST APIs. It focusses on HTTP standards and integrates the symfony/serializer and symfony/validator.

build Code Coverage Mutation testing badge type coverage Technical Debt Software License Wiki Docs

Features

  • Request body or query string to object conversion
  • Response building from objects
  • Configurable content negotiation
  • Events to control symfony/serializer context
  • Integration of symfony/validator
  • Error Handling
  • Optional Logging

Compatible with...

  • Symfony 5.4 + 6
  • PHP 8 + 8.1

Designed for...

modern architectures that apply Domain Driven Design principles, hexagonal architecture or similar concepts.

Install

composer require violines/rest-bundle

How does it work?

  1. Create any PHP class (Entity, DTO, Command, Query, etc) and add the #[HttpApi] attribute or @HttpApi annotation
  2. Use any property attributes/annotations from symfony/serializer or symfony/validator
  3. Declare this PHP class as type of a controller argument
  4. Return an instance of this PHP class in the controller

Show Case

Find a sample of usage under: https://github.com/violines/rest-bundle-showcase.

Example

<?php

declare(strict_types=1);

namespace App\Entity;

#[Violines\RestBundle\HttpApi\HttpApi]
final class Order
{
    public $amount;
    public $articles;
}

// Or use Doctrine Annotations (requires separate install):
// In order to use Annotations you have to install `doctrine/annotations` via `composer require doctrine/annotations`

/**
 * @Violines\RestBundle\HttpApi\HttpApi
 */
final class Order {}
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Exception\AuthenticationFailedException;
use App\Entity\Order;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class OrderController
{
    /**
     * @return Order[]
     */
    #[Route('/orders', methods: ['GET'], name: 'find_orders')]
    public function findOrders(): array
    {
        return $this->orderRepository->findOrders();
    }

    #[Route('/order/{id}', methods: ['GET'], name: 'find_order')]
    public function findOrder(int $id): Order
    {
        $order = $this->orderRepository->find($id);

        if (null === $order) {
            throw NotFoundException::id($id);
        }

        return $order;
    }

    /**
     * @param Order[] $orders
     */
    #[Route('/orders/create', methods: ['POST'], name: 'create_orders')]
    public function createOrders(Order ...$orders): Response
    {
        $this->orderRepository->createOrders($orders);

        return new Response(null, Response::HTTP_CREATED);
    }

    #[Route('/order/create', methods: ['POST'], name: 'create_order')]
    public function createOrder(Order $order): Response
    {
        $this->orderRepository->create($order);

        return new Response(null, Response::HTTP_CREATED);
    }
}

Wiki

For more details please check violines/rest-bundle Wiki.

Development setup

  1. copy docker/.env.dist to docker/.env and adjust to your needs
  2. cd docker/
  3. pull latest image(s): docker-compose pull
  4. create the container(s): docker-compose up -d
  5. run tests with docker-compose exec php80 composer run test

violines/rest-bundle 适用场景与选型建议

violines/rest-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 203 次下载、GitHub Stars 达 36, 最近一次更新时间为 2020 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 violines/rest-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 violines/rest-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 violines/rest-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 36
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-08