定制 domingollanes/strong-parameters-bundle 二次开发

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

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

domingollanes/strong-parameters-bundle

Composer 安装命令:

composer require domingollanes/strong-parameters-bundle

包简介

Strong parameters from Rails inside Symfony

README 文档

README

This bundle allow to simulate Strong Parameters from Rails, inside Symfony Controllers.

You can simply allow and deny items from parameters.

This bundle is really useful for APIs, but can be used in any application.

ALERT: this is an early version.

Tested only in Symfony 3.4.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require domingollanes/strong-parameters-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new DomingoLlanes\StrongParametersBundle\StrongParametersBundle(),
        );

        // ...
    }

    // ...
}

Configuration

The bundle accepts two configurations, you can override them in config.yml. But it have defaults values.

// config.yml

strong_parameters:
  resource: '%kernel.project_dir%/app/Resources/parameters/'
  exceptions: false

Configuring the permitted parameters

You can easily configure namespaces of permitted parameters, for example:

// app/Resources/parameters/user.yml

allow:
  test:
  test2:
    test1:
      t3:
      t2:
deny:
  - test4

That yaml accepts this parameters in Controller action:

array:2 [
  "test" => "testValue"
  "test2" => array:1 [
    "test1" => array:2 [
      "t2" => "t2Value",
      "t3" => "t3Value"
    ]
  ]
]

How to use

// src/AppBundle/Controller/DefaultController.php

// ...

    public function testAction(Request $request, ParametersService $parametersService)
    {
        // ...

        // For $_GET parameters
        $params = $parametersService->permitParameters('user', $request->query->all());

        // For $_POST parameters
        $params = $parametersService->permitParameters('user', $request->request->all());

        // For Content/json parameters
        $params = $parametersService->permitParameters('user', json_decode($request->getContent(), true));
        // ...
    }
    
// ...

domingollanes/strong-parameters-bundle 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-06