im0rtality / rest-api-bundle

此包已被废弃,不再维护。没有建议的替代包。

REST API Bundle

v0.1.6 2014-09-27 20:23 UTC

This package is not auto-updated.

Last update: 2023-11-20 23:18:32 UTC


README

此工具包是一个RESTful API构建工具,旨在尽可能加快构建过程。例如,要实现简单的CRUD,您只需

  1. 拥有您的实体(目前仅支持Doctrine)
  2. 配置工具包

Scrutinizer Code Quality Build Status SensioLabsInsight

安装

1. 通过Composer安装

$ composer require "im0rtality/rest-api-bundle:dev-master"

2. 激活它

在内核中启用工具包

// app/AppKernel.php
<?php

public function registerBundles()
{
    $bundles = array(
        // ...

        // this bundle depends on following two
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new FOS\UserBundle\FOSUserBundle(),

        new Im0rtality\ApiBundle\Im0rtalityApiBundle(),
    );
}

3. 注册路由

将以下内容添加到您的路由配置中

im0rtality_api:
    resource: "@Im0rtalityApiBundle/Resources/config/routing.yml"
    prefix:   /api

4. 配置FOSUserBundle的安全设置

详细信息请见 https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.3.x/Resources/doc/index.md#step-4-configure-your-applications-securityyml

5. 禁用API路由的安全设置

将以下内容添加到您的安全配置中

security:
    role_hierarchy:
        # Simple admin/user configuration
        ROLE_OWNER:       ROLE_USER
        ROLE_ADMIN:       ROLE_OWNER

    access_control:
        # API bundle takes care of security
        - { path: ^/api, role: IS_AUTHENTICATED_ANONYMOUSLY }

请注意!不应显式设置用户上的ROLE_OWNER。它将在内部添加到用户角色(仅在包作用域内)。

配置

您可以在该项目的测试目录中找到具有配置和所有内容的最小示例应用程序(用于维护behat测试)

示例配置

# app/config/config.yml

im0rtality_api:
    acl: api_acl.yml
    mapping:
        user: 'Acme\DemoBundle\Entity\User'
    data:
        type: orm
    ownership:
        'Acme\DemoBundle\Entity\User': id
描述
acl 包含以YAML格式存储的ACL配置的相对文件路径
mapping 用于URL中的实体别名
data.type 数据源(目前仅支持orm
ownership 实体类名称以及将给定实体与其“所有者”用户关联的字段

测试

大部分代码由PHPSpec内部覆盖,其他部分由Behat外部覆盖。要运行测试,您需要执行以下操作

# install vendors
$ composer install
$ cd test; composer install

# run the tests
$ bin/phpspec run
$ cd test; bin/behat