Sign In – following upgrade from 2.3.0 to 2.3.1 – Fatal error: Uncaught Error: Cannot instantiate interface

If you Sign In to your account and then Sign Out again whilst on the Home page or Category Page you get the following error :- Fatal error: Uncaught Error: Cannot instantiate interface Magento\Shipping\Model\CarrierFactoryInterface in /var/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116 Stack trace: #0

If you Sign In when on a product page the error occurs straight away.

This started after updating from v2.3.0 to v2.3.1

Initially on updating I had to disable several Magento modules that were causing the following error when running the command to Re-index

PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface in /var/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116 Stack trace: #0

I solved the reindex issue by disabling a number of modules in config.php

I am assuming my current Sign In issue is similar but I’m not sure what to disable.

I have tried the usual commands to Update and Compile with no result.

Does anyone know what modules could be related to the error – Cannot instantiate interface Magento\Shipping\Model\CarrierFactoryInterface?

Cannot instantiate interface DrupalStreamWrapperInterface

I am trying to replace drupal_realpath with realpath. What I did is

$  stream_wrapper = new DrupalStreamWrapperInterface(); $  file_path = $  stream_wrapper->realpath($  img_path); 

But it gives me this error: Cannot instantiate interface DrupalStreamWrapperInterface. Any idea how do I use DrupalStreamWrapperInterface::realpath?

Factory to instantiate and configure Selenium WebDriver?

I, also, need to know whether this is a valid implementation of the factory pattern.

The amount of effort which goes into configuring DriverFactory to simply get a WebDriver instance seems disproportionate to the point where I ask: “is there not a better way?”

The main-class code:

package;  import; import java.util.Properties; import java.util.logging.Logger; import org.openqa.selenium.WebDriver;  public class App {      private static final Logger LOG = Logger.getLogger(App.class.getName());     private Properties properties = new Properties();      public static void main(String[] args) throws IOException {         new App().initSelenium();     }      private void initSelenium() throws IOException {         properties.loadFromXML(App.class.getResourceAsStream("/selenium.xml"));         WebDriver webDriver = DriverFactory.getWebDriver(properties);  //is this factory and usage correct?         HomePage homePage = new HomePage(webDriver);         homePage.populateCatalogue();     } } 

And my factory:

package;  import; import; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.logging.Logger; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxBinary; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions;  public class DriverFactory {      private static final Logger LOG = Logger.getLogger(DriverFactory.class.getName());      private Properties properties = new Properties();     private FirefoxBinary firefoxBinary = null;     private FirefoxOptions firefoxOptions = null;     private WebDriver webDriver = null;     private URL url = null;     private String driver = null;     private String gecko = null;     private final List<String> commandLineOptions = new ArrayList<>();      private DriverFactory() {     }      private DriverFactory(Properties properties) throws MalformedURLException { = properties;         loadProps();         init();     }       static WebDriver getWebDriver(Properties properties) throws MalformedURLException {         DriverFactory driverFactory = new DriverFactory(properties);         return driverFactory.webDriver;     }      private void loadProps() throws MalformedURLException {         LOG.fine(properties.toString());         url = new URL(properties.getProperty("url"));         driver = properties.getProperty("driver");         gecko = properties.getProperty("gecko");         String commandLineOption = properties.getProperty("option01");         commandLineOptions.add(commandLineOption);     }      private void init() throws MalformedURLException {         firefoxBinary = new FirefoxBinary();         commandLineOptions.forEach((commandLineOption) -> {             LOG.fine(commandLineOption.toString());             firefoxBinary.addCommandLineOptions(commandLineOption);         });         System.setProperty(driver, gecko);         firefoxOptions = new FirefoxOptions();         firefoxOptions.setBinary(firefoxBinary);         webDriver = new FirefoxDriver(firefoxOptions);         webDriver.get(url.toString());         LOG.fine(webDriver.getTitle());         LOG.fine(webDriver.getCurrentUrl().toLowerCase());     }      void close() {         webDriver.close();     }  } 

There seems no nice way to get around loading configuration from a file, which is then loaded. But, it strikes me that I’m re-inventing the wheel of loading a props file for the purpose of configuring a Selenium WebDriver when I expect there’s a tried-and-true approach.

Or, at least, more re-usable.

Although, what possible use there would be for multiple WebDriver instances is beyond me. It would seem Selenium Grid would handle that question quite differently.

Instantiate Controller with Interface not concrete class

As background, I am rebuilding some old code and want to wrap all the curl based requests in an interface (HttpRequestInterface) so I can swap that out later without having to write all the api calls right now.

I am trying to pass the HttpRequestInterface into controller, but it keeps saying `

TypeError: Argument 1 passed to Drupal\my_api\Controller\MyController::__construct() must be an instance of Drupal\my_api\Controller\HttpRequestInterface, instance of Drupal\my_api\Services\HttpRequest\CurlRequest given

I am new to Drupal from the .Net world and love how this functionality is out of the box and it seems like I am following the examples and code I find in core, but obviously I am missing something.

***One thing that sticks out is that this error message has the wrong namespace for HttpRequestInterface.

Below are the relevant files, I have only included what I think is pertinent to the issue, more can be made available.


<?php  namespace Drupal\my_api\Controller;  use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; use Drupal\my_api\Controller\BaseApiController;  /**  * Controller routines for Api routes.  */ class RallyBoundController extends BaseApiController { 


namespace Drupal\my_api\Controller;  use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\my_api\Services\HttpRequest\HttpRequestInterace;  /**  * BaseApiController abstracts away common api concerns.  */ abstract class BaseApiController extends ControllerBase {   protected $  httpService;    /**    * Contructor requires HttpRequest Service.    *    * @param HttpRequestInterface $  httpService    *   Implementation of HttpRequestInterface defined in services.yml.    */   public function __construct(HttpRequestInterface $  httpService) {     $  this->httpService = $  httpService;   }    /**    * Get the HttpRequest implemention as interface so we can swap out as needed.    */   public static function create(ContainerInterface $  container) {     return new static(       $  container->get('my_api.httprequest')     );   } 


services:   my_api.httprequest:     class: Drupal\my_api\Services\HttpRequest\CurlRequest 


namespace Drupal\my_api\Services\HttpRequest;  /**  * HttpRequestInterace defines interface for making Http GET Requests.  */ interface HttpRequestInterface { 


namespace Drupal\my_api\Services\HttpRequest;  use Drupal\my_api\Services\HttpRequest\HttpRequestInterface;  /**  * HttpRequest Implementation of HttpRequestInterface using CURL.  */ class CurlRequest implements HttpRequestInterface { 

Thanks for the help.

Instantiate a class with two parents

Suppose I have TypeA and TypeB classes, which are totally different, but both hold an list of TypeC objects.

Class TypeA { List<TypeC> cs; } Class TypeB { List<TypeC> cs; } 

Throuth all of it’s life cycle, a TypeC instance is belong to a one single TypeA instance and a one single TypeB instance, which cannot be changed.

My question is how to create a new TypeC instance and associate it to TypeA and TypeB instances?

simple solution would be:

ConstructorOfC(typeA, typeB) {     typeA.insertC(this);     typeB.insertC(this); } 

the drawbacks of this approach is that C is aware and depend on TypeA and TypeB classes. I also expose an insert method, which I do not want since insert should be only upon creation, but this method can be called at any time.

Another solution can be:

TypeA: createTypeC() {      this.cs.insert(new TypeC()); } 

which would work if typeC had a single parent, but it’s not the case.