承接 wizards/rest-bundle 相关项目开发

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

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

wizards/rest-bundle

Composer 安装命令:

composer require wizards/rest-bundle

包简介

Integration of php-rest-api into Symfony.

README 文档

README

Symfony bundle for wizards/php-rest-api

Build Status

Helps you create a REST API in an expressive and streamlined way. It will help you conceive mature and discoverable APIs, thanks to the jsonapi specification. Regardless of the output serialization, the request format will be the same. Have a look at http://github.com/wizardstechnologies/php-rest-api for further documentation and explanations. You can find an example project on https://github.com/BigZ/promoteapi

Requirements

symfony >= 4.4
php >= 7.3

Installation

composer require wizards/rest-bundle

Configuration

Create a configuration file with the following values:

# config/bundles/wizards_rest.yaml
wizards_rest:
	data_source: orm|array # Choose between ORM and Array for your data source. More will be added soon
	reader: annotation|array
	format: jsonapi|array
	base_url: your_url

Usage

Create a REST API the easy and configurable way !

This bundle ease the use of wizard's php rest api, and provide some extra goodies for symfony:

If you use symfony flex, those services will be automatically registered.

To serialize a single resource, just return the object from a controller:

public function getArtistAction(string $id, EntityManagerInterface $entityManager)
{
    try {
        $artist = $entityManager->find(Artist::class, $id);
    } catch (\Exception $exception) {
        throw new NotFoundHttpException('Artist not found.');
    }

    return $artist;
}

Note that we don't use the param injector for the entity as we want to be able to dispatch an error ourselves so it is properly formatted.

To Serialize a collection, use the collectionManager

public function getArtistsAction(CollectionManager $collectionManager, ServerRequestInterface $request)
{
    return $collectionManager->getPaginatedCollection(Artist::class, $request);
}

To deserialize input, use the json trait

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Wizards\RestBundle\Controller\JsonControllerTrait;

class ArtistController extends AbstractController
{
    use JsonControllerTrait;
	public function postArtistAction(Request $request, EntityManagerInterface $entityManager)
    {
        $artist = new Artist();
        $form = $this->createForm(ArtistType::class, $artist);
        $this->handleJsonForm($form, $request);

        if (!$form->isValid()) {
            $this->throwRestErrorFromForm($form);
        }

        $entityManager->persist($artist);
        $entityManager->flush();

        return $artist;
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固