我正试图用自己的组件覆盖核心Symfony组件。我使用的方法是:
"autoload": {
"psr-0": {
"": "src/",
"Symfony": "src/vendor/symfony/src/"
}
}
然而,当我运行composer更新和安装时,它似乎从未考虑到这一点。这不是强制自动加载器在Symfony核心之前先查找另一个目录的正确方法吗?
感谢任何指点!
EDIT:文件的路径
src/vendor/symfony/src/symfony/Bridge/Twig/Extension/TranslationExtension.php
src/vendor/symfony/src/symfony/Component/Translation/Translator.phpsrc/vendor/symfony/src/symfony/Component/Translation/Loader/YamlFileLoader.php
<?php
// autoload_namespaces.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Twig_Extensions_' => $vendorDir . '/twig/extensions/lib/',
'Twig_' => $vendorDir . '/twig/twig/lib/',
'Symfony\Bundle\SwiftmailerBundle' => $vendorDir . '/symfony/swiftmailer-bundle/',
'Symfony\Bundle\MonologBundle' => $vendorDir . '/symfony/monolog-bundle/',
'Symfony\Bundle\AsseticBundle' => $vendorDir . '/symfony/assetic-bundle/',
'Symfony' => array($vendorDir . '/symfony/symfony/src/', '/src/vendor/symfony/src/'),
'SessionHandlerInterface' => $vendorDir . '/symfony/symfony/src/Symfony/Component/HttpFoundation/Resources/stubs',
'Sensio\Bundle\GeneratorBundle' => $vendorDir . '/sensio/generator-bundle/',
'Sensio\Bundle\FrameworkExtraBundle' => $vendorDir . '/sensio/framework-extra-bundle/',
'Sensio\Bundle\DistributionBundle' => $vendorDir . '/sensio/distribution-bundle/',
'Monolog' => $vendorDir . '/monolog/monolog/src/',
'Metadata\' => $vendorDir . '/jms/metadata/src/',
'JMS\SecurityExtraBundle' => $vendorDir . '/jms/security-extra-bundle/',
'JMS\DiExtraBundle' => $vendorDir . '/jms/di-extra-bundle/',
'JMS\AopBundle' => $vendorDir . '/jms/aop-bundle/',
'Doctrine\ORM' => $vendorDir . '/doctrine/orm/lib/',
'Doctrine\DBAL' => $vendorDir . '/doctrine/dbal/lib/',
'Doctrine\Common' => $vendorDir . '/doctrine/common/lib/',
'Doctrine\Bundle\DoctrineBundle' => $vendorDir . '/doctrine/doctrine-bundle/',
'CG\' => $vendorDir . '/jms/cg/src/',
'Assetic' => $vendorDir . '/kriswallsmith/assetic/src/',
'' => $baseDir . '/src/',
);
如果我手动将自动装载行编辑为:
'Symfony' => array('/Users/macbook/Sites/Opia/Gaia/src/vendor/symfony/src/', $vendorDir . '/symfony/symfony/src/'),
一切都按它的本意运行。所以现在它基本上是在寻找作曲家为什么不能正确作曲的解决方案。
编辑2:
做了更多的搜索,上面的方法似乎不是一个好的实现:
https://groups.google.com/forum/#!消息/作曲家dev/HprRV_wJZg4/M_zQ8O7lB6IJ
相反,我需要扩展给定的类,并告诉Symfony使用这些类,这应该可以通过以下参数实现:
parameters:
security.authentication.listener.anonymous.class: AcmeDemoBundle
SecurityHttpFirewallAcmeAnonymousAuthenticationListener
然而,我不确定我需要设置什么参数来加载扩展类来代替核心。
我终于找到了答案。
首先,如果你需要找出要覆盖的类,请访问:
symfony/src/Symfony/Bundle/FrameworkBundle/Resources/%Your file to override%.xml
在那里,您可以找到一个可以扩展/重写的可能Symfony类的列表。
然后在您的config.yml添加中(我选择将我的添加到扩展命名空间中):
parameters:
twig.extension.trans.class: ExtendSymfonyBridgeTwigExtensionTranslationExtension
translation.loader.yml.class: ExtendSymfonyComponentTranslationLoaderYamlFileLoader
translator.class: ExtendSymfonyBundleFrameworkBundleTranslationTranslator
最后在我的composer.json:中
"autoload": {
"psr-0": {
"": "src/",
"Extend\Symfony": "/path/to/your/symfony/classes"
}
},