定制 bu/extra-param-converter-bundle 二次开发

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

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

bu/extra-param-converter-bundle

Composer 安装命令:

composer require bu/extra-param-converter-bundle

包简介

Symfony2 bundle that extends Sensio ParamConverter functionality, allowing to convert simple GET and complex POST data

README 文档

README

BuExtraParamConverterBundle extends Sensio ParamConverter functionality, allowing to convert simple GET and complex POST data to entities, decode json data and strip tags from data.

Requires SensioFrameworkExtraBundle.

Build Status

Installation

Add bundle with composer:

composer require bu/extra-param-converter-bundle dev-master

Register bundle in AppKernel.php:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Bu\ExtraParamConverterBundle\BuExtraParamConverterBundle(),
    );
}

Sensio ParamConverter should be enabled, ie parameter sensio_framework_extra.request.converters in your app config should be set to true (set by default).

Usage

GetConverter

You don't need to write any annotations, following code will work with any GET request with user parameter, like "/getUserDetails?user=123"

public function detailsAction(User $user)
{
    ...
}

where 123 is user id. It will throw NotFoundHttpException if can't find User by this id.

PostConverter

use Bu\ExtraParamConverterBundle\Configuration\ExtraParamConverter;

    /**
     * @ExtraParamConverter("data", jsonData=true, stripTags=true, namespace="App", entities={"groups"="Group", "role"="Role"})
     */
    public function saveUserAction(array $data)
    {
        // $data['groups'] ...
    }

In this example:

  • raw post data will be json-decoded (jsonData=false by default for standard form submit)
  • all string values will be filtered (stripTags=false by default)
  • all "groups" will converted to "Group" entities, array [id1, id2, id3] - to array of "App:Group" entities
  • all "role" will converted to "Role" entity, single value to single entity
  • all is processed recursively to deepest level
  • result will available in $data (confugired by first unnamed parameter in annotation)
  • exceptions will be thrown in number of incorrect situations:
    • invalid json data, invalid post data
    • entities are defined without namespace (you can ommit them both if want only jsonDecode/stripTags)
    • key defined for entity not found in data
    • any entity not found by id

Recommented to set doctrine mapping alias for your bundle:

# Doctrine Configuration
doctrine:
    orm:
        mappings:
            ApplicationMySuperBundle:
                alias: My

This will allow you to use short namespace "My" instead of long autogenerated "ApplicationMySuperBundle".

License

This bundle is under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固