当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectManager::setInstance方法代码示例

本文整理汇总了PHP中Magento\Framework\App\ObjectManager::setInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::setInstance方法的具体用法?PHP ObjectManager::setInstance怎么用?PHP ObjectManager::setInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\App\ObjectManager的用法示例。


在下文中一共展示了ObjectManager::setInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: tearDown

 protected function tearDown()
 {
     parent::tearDown();
     /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock*/
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:7,代码来源:BackendTemplateTest.php

示例2: tearDown

 protected function tearDown()
 {
     parent::tearDown();
     $magentoObjectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
     $objectManager = $magentoObjectManagerFactory->create($_SERVER);
     \Magento\Framework\App\ObjectManager::setInstance($objectManager);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:7,代码来源:TemplateTest.php

示例3: setUp

 protected function setUp()
 {
     $this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false, false);
     $this->orderCollectionFactory = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->orderCollectionFactoryInterface = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValue($this->orderCollectionFactoryInterface));
     \Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
     $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
     $this->orderConfig = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Config')->setMethods(['getVisibleOnFrontStatuses'])->disableOriginalConstructor()->getMock();
     $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:HistoryTest.php

示例4: setUp

 protected function setUp()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->scopeConfigMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn(['test' => 1]);
     $this->structureMock = $this->getMock('Magento\\Config\\Model\\Config\\Structure', [], [], '', false);
     $this->structureMock->expects($this->any())->method('getFieldPathsByAttribute')->willReturn(['path' => 'test']);
     $this->resourceModelMock = $this->getMock('Magento\\Email\\Model\\Resource\\Template', [], [], '', false);
     $this->resourceModelMock->expects($this->any())->method('getSystemConfigByPathsAndTemplateId')->willReturn(['test_config' => 2015]);
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $objectManagerMock->expects($this->any())->method('get')->with('Magento\\Email\\Model\\Resource\\Template')->will($this->returnValue($this->resourceModelMock));
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
     $this->model = $helper->getObject('Magento\\Email\\Model\\BackendTemplate', ['scopeConfig' => $this->scopeConfigMock, 'structure' => $this->structureMock]);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:BackendTemplateTest.php

示例5: testConfigureObjectManager

 public function testConfigureObjectManager()
 {
     try {
         $origObjectManager = ObjectManager::getInstance();
     } catch (\Exception $e) {
         $origObjectManager = null;
     }
     $objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock();
     ObjectManager::setInstance($objectManagerMock);
     $diConfigMock = $this->getMockBuilder('\\Magento\\Framework\\Interception\\ObjectManager\\ConfigInterface')->disableOriginalConstructor()->getMock();
     $configLoaderMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager\\ConfigLoader')->disableOriginalConstructor()->getMock();
     $configLoaderMock->expects($this->any())->method('load')->willReturn([]);
     $omReturnMap = [['Magento\\Framework\\App\\ObjectManager\\ConfigLoader', $configLoaderMock], ['Magento\\Framework\\Config\\ScopeInterface', $this->getMockBuilder('Magento\\Framework\\Config\\ScopeInterface')->disableOriginalConstructor()->getMock()], ['Magento\\Framework\\App\\ObjectManager\\ConfigCache', $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager\\ConfigCache')->disableOriginalConstructor()->getMock()], ['Magento\\Framework\\Interception\\Config\\Config', $this->getMockBuilder('Magento\\Framework\\Interception\\Config\\Config')->disableOriginalConstructor()->getMock()]];
     $objectManagerMock->expects($this->any())->method('get')->willReturnMap($omReturnMap);
     $sharedInstances = ['class_name' => 'shared_object'];
     $this->_developer->configureObjectManager($diConfigMock, $sharedInstances);
     $expectedSharedInstances = ['class_name' => 'shared_object', 'Magento\\Framework\\ObjectManager\\ConfigLoaderInterface' => $configLoaderMock];
     $this->assertSame($expectedSharedInstances, $sharedInstances);
     if (isset($origObjectManager)) {
         ObjectManager::setInstance($origObjectManager);
     }
 }
开发者ID:Zash22,项目名称:magento,代码行数:22,代码来源:DeveloperTest.php

示例6: create

 /**
  * Create ObjectManager
  *
  * @param array $arguments
  * @return \Magento\Framework\ObjectManagerInterface
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function create(array $arguments)
 {
     $deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
     $arguments = array_merge($deploymentConfig->get(), $arguments);
     $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory($this->driverPool->getDriver(DriverPool::FILE), $this->directoryList->getPath(DirectoryList::DI), $this->directoryList->getPath(DirectoryList::GENERATION), $deploymentConfig->get(self::CONFIG_PATH_DEFINITION_FORMAT, Serialized::MODE_NAME));
     $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions'));
     $relations = $definitionFactory->createRelations();
     /** @var EnvironmentFactory $enFactory */
     $enFactory = new $this->envFactoryClassName($relations, $definitions);
     /** @var EnvironmentInterface $env */
     $env = $enFactory->createEnvironment();
     /** @var ConfigInterface $diConfig */
     $diConfig = $env->getDiConfig();
     $appMode = isset($arguments[State::PARAM_MODE]) ? $arguments[State::PARAM_MODE] : State::MODE_DEFAULT;
     $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
     $argInterpreter = $this->createArgumentInterpreter($booleanUtils);
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     if ($env->getMode() != Environment\Compiled::MODE) {
         $configData = $this->_loadPrimaryConfig($this->directoryList, $this->driverPool, $argumentMapper, $appMode);
         if ($configData) {
             $diConfig->extend($configData);
         }
     }
     // set cache profiler decorator if enabled
     if (\Magento\Framework\Profiler::isEnabled()) {
         $cacheFactoryArguments = $diConfig->getArguments('Magento\\Framework\\App\\Cache\\Frontend\\Factory');
         $cacheFactoryArguments['decorators'][] = ['class' => 'Magento\\Framework\\Cache\\Frontend\\Decorator\\Profiler', 'parameters' => ['backendPrefixes' => ['Zend_Cache_Backend_', 'Cm_Cache_Backend_']]];
         $cacheFactoryConfig = ['Magento\\Framework\\App\\Cache\\Frontend\\Factory' => ['arguments' => $cacheFactoryArguments]];
         $diConfig->extend($cacheFactoryConfig);
     }
     $sharedInstances = ['Magento\\Framework\\App\\DeploymentConfig' => $deploymentConfig, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DriverPool' => $this->driverPool, 'Magento\\Framework\\ObjectManager\\RelationsInterface' => $relations, 'Magento\\Framework\\Interception\\DefinitionInterface' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\Interception\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\ObjectManager\\DefinitionInterface' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, 'Magento\\Framework\\ObjectManager\\ConfigLoaderInterface' => $env->getObjectManagerConfigLoader(), $this->_configClassName => $diConfig];
     $arguments['shared_instances'] =& $sharedInstances;
     $this->factory = $env->getObjectManagerFactory($arguments);
     /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
     $objectManager = new $this->_locatorClassName($this->factory, $diConfig, $sharedInstances);
     $this->factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     $definitionFactory->getCodeGenerator()->setObjectManager($objectManager);
     $env->configureObjectManager($diConfig, $sharedInstances);
     return $objectManager;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:49,代码来源:ObjectManagerFactory.php

示例7: testWakeUpWith

 /**
  * Test for the magic method __wakeup
  *
  * @covers \Magento\Framework\App\Response\Http::__wakeup
  */
 public function testWakeUpWith()
 {
     $objectManagerMock = $this->getMock('Magento\\Framework\\App\\ObjectManager', [], [], '', false);
     $objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Stdlib\\CookieManagerInterface')->will($this->returnValue($this->cookieManagerMock));
     $objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\Stdlib\\Cookie\\CookieMetadataFactory')->will($this->returnValue($this->cookieMetadataFactoryMock));
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
     $this->model->__wakeup();
 }
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:HttpTest.php

示例8: create

 /**
  * Create ObjectManager
  *
  * @param string $rootDir
  * @param array $arguments
  * @param bool $useCompiled
  * @return \Magento\Framework\ObjectManager
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function create($rootDir, array $arguments, $useCompiled = true)
 {
     $directories = isset($arguments[Filesystem::PARAM_APP_DIRS]) ? $arguments[Filesystem::PARAM_APP_DIRS] : array();
     $directoryList = new DirectoryList($rootDir, $directories);
     (new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array($directoryList->getDir(Filesystem::GENERATION_DIR)));
     $appArguments = $this->createAppArguments($directoryList, $arguments);
     $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(new \Magento\Framework\Filesystem\Driver\File(), $directoryList->getDir(Filesystem::DI_DIR), $directoryList->getDir(Filesystem::GENERATION_DIR), $appArguments->get('definition.format', 'serialized'));
     $definitions = $definitionFactory->createClassDefinition($appArguments->get('definitions'), $useCompiled);
     $relations = $definitionFactory->createRelations();
     $configClass = $this->_configClassName;
     /** @var \Magento\Framework\ObjectManager\Config\Config $diConfig */
     $diConfig = new $configClass($relations, $definitions);
     $appMode = $appArguments->get(State::PARAM_MODE, State::MODE_DEFAULT);
     $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
     $argInterpreter = $this->createArgumentInterpreter($booleanUtils);
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     $configData = $this->_loadPrimaryConfig($directoryList, $argumentMapper, $appMode);
     if ($configData) {
         $diConfig->extend($configData);
     }
     $this->factory = new \Magento\Framework\ObjectManager\Factory\Factory($diConfig, null, $definitions, $appArguments->get());
     $className = $this->_locatorClassName;
     $sharedInstances = ['Magento\\Framework\\App\\Arguments' => $appArguments, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\ObjectManager\\Relations' => $relations, 'Magento\\Framework\\Interception\\Definition' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\Config' => $diConfig, 'Magento\\Framework\\ObjectManager\\Definition' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, $configClass => $diConfig];
     /** @var \Magento\Framework\ObjectManager $objectManager */
     $objectManager = new $className($this->factory, $diConfig, $sharedInstances);
     $this->factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     /** @var \Magento\Framework\App\Filesystem\DirectoryList\Verification $verification */
     $verification = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Verification');
     $verification->createAndVerifyDirectories();
     $diConfig->setCache($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigCache'));
     $objectManager->configure($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigLoader')->load('global'));
     $objectManager->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope('global');
     $objectManager->get('Magento\\Framework\\App\\Resource')->setCache($objectManager->get('Magento\\Framework\\App\\CacheInterface'));
     $interceptionConfig = $objectManager->get('Magento\\Framework\\Interception\\Config\\Config');
     $diConfig->setInterceptionConfig($interceptionConfig);
     $this->configureDirectories($objectManager);
     return $objectManager;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:49,代码来源:ObjectManagerFactory.php

示例9: tearDown

 protected function tearDown()
 {
     parent::tearDown();
     \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerBackup);
 }
开发者ID:nja78,项目名称:magento2,代码行数:5,代码来源:AbstractCollectionTest.php

示例10: tearDown

 public function tearDown()
 {
     \Magento\Framework\App\ObjectManager::setInstance($this->applicationObjectManager);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:4,代码来源:AbstractPlugin.php


注:本文中的Magento\Framework\App\ObjectManager::setInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。