doucheng5705 2014-05-07 09:37
浏览 33
已采纳

Silex FormServiceProvider和form.secret参数

I am using the FormServiceProvider from Silex and reading through the documentation it explains how it has one parameter called form.secret which I assumed meant constructing the provider with this:

$app->register(new Silex\Provider\FormServiceProvider(), [
    'form.secret' => 'SECRET HERE'
]); 

The problem is however when I look through the source code for this file I cannot see a constructor where this parameter would get used. Only seeing it set internally within the container to md5(__DIR__).

https://github.com/silexphp/Silex/blob/master/src/Silex/Provider/FormServiceProvider.php#L48

Or would it be simply a case of not providing form.secret when constructing and simply setting $app['form.secret'] = 'SECRET HERE' after the provider has been registered?

Am I right in this assumption or I am I missing something?

  • 写回答

1条回答 默认 最新

  • dongzhuo1733 2014-05-07 10:03
    关注

    You can see it being used in line 100, when $app["form.csrf_provider"] is first accessed:

    $app['form.csrf_provider'] = function ($app) {
        if (isset($app['session'])) {
            return new SessionCsrfProvider($app['session'], $app['form.secret']);
        }
    
        return new DefaultCsrfProvider($app['form.secret']);
    };
    

    Since whatever you pass is ignored and overwritten with the md5 call you mention, correct usage would be:

    $app->register(new FormServiceProvider());
    $app["form.secret"] = "foo";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?