在我的 Silex 应用程序中,我需要一个基本上执行 file_get_contents() 的函数,我的想法是使用类似
$app['funky_service'] = function () {
$content = file_get_contents();
return $content;
}
这工作正常,但我怎样才能将参数传递给这个函数?我可以这样称呼它
$fs = $app['funky_service'];
但是向它传递参数仍然让我感到困惑
根据silex 文档中的服务章节,如果要将函数存储为参数,则需要保护它:
$app['function_parameter'] = $app->protect(function ($resource) {
$content = file_get_contents($resource);
return $content;
});
$example = $app['function_parameter']('http://example.com');