我最近通过更改composer.json中的3行来将Silex v1.3迁移到v2
"silex/silex": "~2.0",
"silex/web-profiler": "~2.0",
"deralex/yaml-config-service-provider": "2.0.x-dev"
但是,由于Silex无法找到很多课程......
这是我的app.php文件,在Silex 1.3中正确加载我需要的所有内容:
<?php
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\ValidatorServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\HttpFragmentServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Silex\Provider\SecurityServiceProvider;
use Silex\Provider\FormServiceProvider;
use Manager\ManagerProvider;
$app = new Application();
$app->register(new UrlGeneratorServiceProvider());
$app->register(new ValidatorServiceProvider());
$app->register(new ServiceControllerServiceProvider());
$app->register(new TwigServiceProvider());
$app->register(new HttpFragmentServiceProvider());
$app->register(new SessionServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'translator.messages' => array(),
));
$app->register(new SecurityServiceProvider(), [
'security.firewalls' => [
'foo' => [ 'pattern' => '^/foo' ],
'default' => [
'pattern' => '^.*$',
'anonymous' => true,
'form' => [ 'login_path' => '/login','check_path' => 'connexion' ],
'logout' => [ 'logout_path' => '/logout' ],
'users' => $app->share( function () use ( $app ) {
return new Authenticate\UserProvider( $app['manager.user'] );
} ),
],
],
'security.access_rules' => [
[ '^/.+$','IS_AUTHENTICATED_ANONYMOUSLY' ],
[ '^/foo$','' ]
]
]);
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
// add custom globals, filters, tags, ...
return $twig;
}));
$app->register(new DerAlex\Silex\YamlConfigServiceProvider(__DIR__ . '/../app/settings.yml'));
$app->register(new ManagerProvider($app));
return $app;
第一个错误:
ClassNotFoundException in app.php line 15:
Attempted to load class "UrlGeneratorServiceProvider" from namespace "Silex\Provider".
Did you forget a "use" statement for another namespace?
第二个错误:
UndefinedMethodException in app.php line 33:
Attempted to call an undefined method named "share" of class "Silex\Application".
第三个错误:
ClassNotFoundException in app.php line 56:
Attempted to load class "YamlConfigServiceProvider" from namespace "DerAlex\Silex".
Did you forget a "use" statement for "DerAlex\Pimple\YamlConfigServiceProvider"?
第四个错误:
ClassNotFoundException in ManagerProvider.php line 12:
Attempted to load interface "ServiceProviderInterface" from namespace "Silex".
Did you forget a "use" statement for "Pimple\ServiceProviderInterface"?
我不知道应该改变什么以及如何纠正...... 谢谢你的帮助
答案 0 :(得分:3)
UrlGeneratorServiceProvider
已被RoutingServiceProvider
$app->register(new RoutingServiceProvider());
方法share
已从Pimple
中移除。只需设置返回对象的函数来共享一些对象。
$app['object'] = function() { return new Object(); }
可能是作曲家未设置为名称空间为DerAlex\...
的自动加载类。尝试使用\DerAlex\Silex\YamlConfigServiceProvider
。
添加使用声明use Pimple\ServiceProviderInterface
或将此类用作\Pimple\ServiceProviderInterface
。