Reputation: 109
I need to make alterations to this symfony class:
Symfony\Component\Translation\MessageCatalogue
Does anyone know how I can force Symfony to use my own variant of this class? I don't want to tamper with the actual core files, just in case.
Upvotes: 0
Views: 140
Reputation: 6560
The MessageCatalogue
class isn't a service registered in the dependency injection container so it cannot be overriden using the standard methods (class name parameter / compiler pass). It is used directly in the Symfony code, e.g. new MessageCatalogue()
.
If you really need to override it, you can do so by setting the class location explicitly in the class loader. Class maps have precedence over PSR-0/PSR-4 prefixes.
$loader = require __DIR__ . '/../vendor/autoload.php';
$loader->addClassMap([
'Symfony\Component\Translation\MessageCatalogue' => 'path/to/your/override.php',
]);
The downsides are:
Upvotes: 3