_classesToDestruct as $className) { if (isset($this->_sharedInstances[$className])) { $this->_sharedInstances[$className] = null; } } \Magento\Framework\App\Config\Base::destroy(); $sharedInstances = [ \Magento\Framework\ObjectManagerInterface::class => $this, \Magento\Framework\App\ObjectManager::class => $this, ]; foreach ($this->persistedInstances as $persistedClass) { if (isset($this->_sharedInstances[$persistedClass])) { $sharedInstances[$persistedClass] = $this->_sharedInstances[$persistedClass]; } } $this->_sharedInstances = $sharedInstances; $this->_config->clean(); $this->clearMappedTableNames(); return $this; } /** * Clear mapped table names list. * * @return void */ private function clearMappedTableNames() { $resourceConnection = $this->get(\Magento\Framework\App\ResourceConnection::class); if ($resourceConnection) { $reflection = new \ReflectionClass($resourceConnection); $dataProperty = $reflection->getProperty('mappedTableNames'); $dataProperty->setAccessible(true); $dataProperty->setValue($resourceConnection, null); } } /** * Add shared instance. * * @param mixed $instance * @param string $className * @return void */ public function addSharedInstance($instance, $className) { $this->_sharedInstances[$className] = $instance; } /** * Remove shared instance. * * @param string $className * @return void */ public function removeSharedInstance($className) { unset($this->_sharedInstances[$className]); } /** * Set objectManager. * * @param \Magento\Framework\ObjectManagerInterface $objectManager * @return \Magento\Framework\ObjectManagerInterface */ public static function setInstance(\Magento\Framework\ObjectManagerInterface $objectManager) { return self::$_instance = $objectManager; } /** * @return \Magento\Framework\ObjectManager\FactoryInterface|\Magento\Framework\ObjectManager\Factory\Factory */ public function getFactory() { return $this->_factory; } }