How to change the coordinate transformation function in Oracle?
You can override a class that implements an interface, the same way that you would normally overwrite a class. But you'll have to choose how you want to implement the interface.
In either case, first you'll have to declare your override as a preference in your module's etc/di.xml
<preference for="Magento\Framework\Message\Manager" type="Vendor\MyModule\Plugin\Magento\Framework\Message\Manager" />
Then the next step is to create Vendor\MyModule\Plugin\Magento\Framework\Message\Manager.php
. Then choose one of the possibilities.
Method #1: Extending the original class (keeping the interface implementation in the original file)
By extending the original class you can overwrite only specific methods or add your own.
<?php
namespace Vendor\MyModule\Plugin\Magento\Framework\Message;
class Manager extends \Magento\Framework\Message\Manager {
public function myFunctionHere() {
}
}
Method #2: Completely overriding the original class + interface
This one is more complex as you'll have to reimplement the whole class. Not something that I can recommend doing.
<?php
namespace Vendor\MyModule\Plugin\Magento\Framework\Message;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\Message\Session;
use Magento\Framework\Message\Factory;
use Magento\Framework\Message\CollectionFactory;
use Magento\Framework\Message\ExceptionMessageFactoryInterface;
use Magento\Framework\Message\ExceptionMessageLookupFactory;
use Magento\Framework\Event;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Debug;
class Manager implements ManagerInterface {
... /* Vars */
public function __construct(
Session $session,
Factory $messageFactory,
CollectionFactory $messagesFactory,
Event\ManagerInterface $eventManager,
LoggerInterface $logger,
$defaultGroup = self::DEFAULT_GROUP,
ExceptionMessageFactoryInterface $exceptionMessageFactory = null
) {
$this->session = $session;
$this->messageFactory = $messageFactory;
$this->messagesFactory = $messagesFactory;
$this->eventManager = $eventManager;
$this->logger = $logger;
$this->defaultGroup = $defaultGroup;
$this->exceptionMessageFactory = $exceptionMessageFactory ?: ObjectManager::getInstance()
->get(ExceptionMessageLookupFactory::class);
}
... /* Other methods */
}