承接 ucsf/restorm-bundle 相关项目开发

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

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

ucsf/restorm-bundle

Composer 安装命令:

composer require ucsf/restorm-bundle

包简介

REST-based ORM for Symfony - Obtain objects from a REST service... just like using an ORM

README 文档

README

(This document is a work in progress.)

A Symfony bundle that provides a Doctrine-based ORM over REST services

This bundle began as a need to connect Symfony applications with back-end REST services. Rather than duplicating Guzzle code across controller-injected services or making a complete new and custom library for them to share, I wanted to have bona fide entity managers, configured like a Doctrine entity manger, managing REST data. Rather than creating an actual Doctrine driver for REST (a possible retooling in the future) this bundle takes a middle approach by using Doctrine's facilities to emulate that sort of coupling. What you get are configurable entity managers with repositories, a managed way to initiate specific and detailed REST commands, and the ability to have REST data hydrate Symfony entities that are configured with Doctrine annotation. The configuration is fairly simple and though different from how Doctrine itself is configured it otherwise works fairly the same during application development.

Installation

  • Add to composer.json
  • "ucsf/restorm": "dev-master"
  • Add the bundle to AppKernel.php
  • new Ucsf\LdapOrmBundle\UcsfRestOrmBundle()
  • Install using composer
  • $ composer install ucsf/restorm-bundle

Documentation

Develop with RestLdapOrm

Configure a REST service in config.yml

ucsf_rest_orm:
    connections:
        foo_api:
            base_uri: %foo.base_uri%
            username: %foo.username%
            password: %foo.password%
    entity_managers:
        foo_api:
            # The connection and the entity_manager do not need to be named the same, but they
            # are so named here to show the convenience of matching them up. There can be multiple
            # entity_managers using the same connection.
            connection: foo_api
            repositories:
                NiceCompany\AwesomeBundle\Entity\Widget:
                    persist:
                        method: POST
                        path: widgets
                    all:
                        method: GET
                        path: widgets
                    find:
                      byId:
                          method: GET
                          path: widgets/{{id}}
                      byFactory:
                          method: GET
                          path: widgets?factory={{factoryId}}
                NiceCompany\AwesomeBundle\Entity\Factory:
                    find:
                      byId:
                          method: GET
                          path: factories/{{id}}
            # Commands do not have to copy repository method configuration, this just
            # shows command-based analogs of the repository examples.
            commands:
                get_all_widgets:
                    method: GET
                    path: widgets
                    class: NiceCompany\AwesomeBundle\Entity\Widget
                get_widget:
                    method: GET
                    path: widgets/{{id}}
                    class: NiceCompany\AwesomeBundle\Entity\Widget
                get_widget_by_factory:
                    method: GET
                    path: path: widgets?factory={{factoryId}}
                    class: NiceCompany\AwesomeBundle\Entity\Widget
                delete_widget:
                    # For this delete, there's no id supplied, but the object
                    # to delete itself as the body of the request. See how it's
                    # coded below
                    method: DELETE
                    path: widgets
                    class: NiceCompany\AwesomeBundle\Entity\Widget

Dependency injection for REST Entity Managers and Services

    widget_service:
        class: NiceCompany\AwesomeBundle\Services\WidgetService
        arguments:
            # Note how the entity manager's reference is built as
            #   'ucsf_rest_orm.'.$entityManagerName.'_entity_manager'
            entityManager: "@ucsf_rest_orm.foo_api_entity_manager"

Creating Entities (usually to represent an object class)

It works pretty much as Doctrine entities that are generated from a real SQL database. I have not experimented with much more of the Doctrine annotation than what you see here.

/**
 * @ORM\Table(name="widget")
 * @ORM\Entity
 */
class Widget {

    /**
     * @var integer
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     */
    private $id;

    /**
     * @var string
     * @ORM\Column(name="widgetName", type="string")
     */
    private $widgetName;

    ...


Coding the Service

Once you get to this point, it's pretty much just like any other Doctrine entity manager.

use UCSF\RestOrmBundle\Doctrine\ORM\EntityManager;
use NiceCompany\AwesomeBundle\Entity\Widget;
use NiceCompany\AwesomeBundle\Entity\Factory;

class WidgetService
{
    private $entityManager;
    private $widgetRepository;

    public function __construct(EntityManager $entityManager) {
        $this->entityManager = $entityManager;
        $this->widgetRepository = $entityManager->getRepository(Widget::class);
        $this->factoryRepository = $entityManager->getRepository(Factory::class);
    }

    // Using repositories

    public function getWidgetById($id) {
        return $this->roleRepository->findById($id);
    }

    public function saveWidget(Widget $widget) {
        return $this->entityManager->persist($widget);
    }

    // Using commands

    public function getWidgetsByFactory($widgetId) {
        return $this->entityManager->command('get_widgets_by_factory', ['widgetId' => $widgetId]);
    }

    public function deleteWidget(Widget $widget) {
        return $this->entityManager->command('delete_widget', [] /* null is fine too */, $widget);
    }
        

ucsf/restorm-bundle 适用场景与选型建议

ucsf/restorm-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 497 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「orm」 「rest」 「ucsf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-03