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


PHP ObjectManager::create方法代码示例

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


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

示例1: _runJob

 /**
  * Execute job by calling specific class::method
  *
  * @param int $scheduledTime
  * @param int $currentTime
  * @param string[] $jobConfig
  * @param Schedule $schedule
  * @param string $groupId
  * @return void
  * @throws \Exception
  */
 protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
 {
     $scheduleLifetime = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
     if ($scheduledTime < $currentTime - $scheduleLifetime) {
         $schedule->setStatus(Schedule::STATUS_MISSED);
         throw new \Exception('Too late for the schedule');
     }
     if (!isset($jobConfig['instance'], $jobConfig['method'])) {
         $schedule->setStatus(Schedule::STATUS_ERROR);
         throw new \Exception('No callbacks found');
     }
     $model = $this->_objectManager->create($jobConfig['instance']);
     $callback = [$model, $jobConfig['method']];
     if (!is_callable($callback)) {
         $schedule->setStatus(Schedule::STATUS_ERROR);
         throw new \Exception(sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method']));
     }
     $schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save();
     try {
         call_user_func_array($callback, [$schedule]);
     } catch (\Exception $e) {
         $schedule->setStatus(Schedule::STATUS_ERROR);
         throw $e;
     }
     $schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:38,代码来源:ProcessCronQueueObserver.php

示例2: generateCode

 /**
  * Generate Code
  *
  * @param string $generationDir
  * @param array $fileExcludePatterns
  * @param InputInterface $input
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generateCode($generationDir, $fileExcludePatterns, $input)
 {
     // 1.1 Code scan
     $filePatterns = ['php' => '/.*\\.php$/', 'di' => '/\\/etc\\/([a-zA-Z_]*\\/di|di)\\.xml$/'];
     $directoryScanner = new Scanner\DirectoryScanner();
     foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $codeScanDir) {
         $this->files = array_merge_recursive($this->files, $directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns));
     }
     $this->files['di'][] = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::CONFIG) . '/di.xml';
     $this->files['additional'] = [$input->getOption(self::INPUT_KEY_EXTRA_CLASSES_FILE)];
     $repositoryScanner = new Scanner\RepositoryScanner();
     $repositories = $repositoryScanner->collectEntities($this->files['di']);
     $scanner = new Scanner\CompositeScanner();
     $scanner->addChild(new Scanner\PhpScanner($this->log), 'php');
     $scanner->addChild(new Scanner\XmlScanner($this->log), 'di');
     $scanner->addChild(new Scanner\ArrayScanner(), 'additional');
     $this->entities = $scanner->collectEntities($this->files);
     $interceptorScanner = new Scanner\XmlInterceptorScanner();
     $this->entities['interceptors'] = $interceptorScanner->collectEntities($this->files['di']);
     // 1.2 Generation of Factory and Additional Classes
     $generatorIo = $this->objectManager->create('Magento\\Framework\\Code\\Generator\\Io', ['generationDirectory' => $generationDir]);
     $this->generator = $this->objectManager->create('Magento\\Framework\\Code\\Generator', ['ioObject' => $generatorIo]);
     /** Initialize object manager for code generation based on configs */
     $this->generator->setObjectManager($this->objectManager);
     $generatorAutoloader = new \Magento\Framework\Code\Generator\Autoloader($this->generator);
     spl_autoload_register([$generatorAutoloader, 'load']);
     foreach ($repositories as $entityName) {
         switch ($this->generator->generateClass($entityName)) {
             case CodeGenerator::GENERATION_SUCCESS:
                 $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                 break;
             case CodeGenerator::GENERATION_ERROR:
                 $this->log->add(Log::GENERATION_ERROR, $entityName);
                 break;
             case CodeGenerator::GENERATION_SKIP:
             default:
                 //no log
                 break;
         }
     }
     foreach (['php', 'additional'] as $type) {
         sort($this->entities[$type]);
         foreach ($this->entities[$type] as $entityName) {
             switch ($this->generator->generateClass($entityName)) {
                 case CodeGenerator::GENERATION_SUCCESS:
                     $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                     break;
                 case CodeGenerator::GENERATION_ERROR:
                     $this->log->add(Log::GENERATION_ERROR, $entityName);
                     break;
                 case CodeGenerator::GENERATION_SKIP:
                 default:
                     //no log
                     break;
             }
         }
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:68,代码来源:DiCompileMultiTenantCommand.php

示例3: createMagentoObject

 /**
  * @param  string $type
  * @param  array  $arguments
  *
  * @return mixed
  */
 protected function createMagentoObject($type, array $arguments = [])
 {
     return $this->objectManager->create($type, $arguments);
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:10,代码来源:MercadoPagoFixture.php

示例4: execute

 public function execute($observer)
 {
     $model = $this->_objectManager->create('Celebros\\Celexport\\Model\\Exporter');
     $model->export_celebros($this->_objectManager, false);
     return $this;
 }
开发者ID:CelebrosLtd,项目名称:M2_Celexport,代码行数:6,代码来源:CatalogUpdate.php


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