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


PHP Framework\ObjectManager类代码示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetailsBuilder');
     $this->itemBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetails\\ItemBuilder');
     $this->addressBuilder = $this->objectManager->create('\\Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:7,代码来源:QuoteDetailsBuilderTest.php

示例2: updateFieldForTable

/**
 * Replace {{skin url=""}} with {{view url=""}} for given table field
 *
 * @param \Magento\Framework\ObjectManager $objectManager
 * @param string $table
 * @param string $col
 * @return void
 */
function updateFieldForTable($objectManager, $table, $col)
{
    /** @var $installer \Magento\Framework\Module\Setup */
    $installer = $objectManager->create('Magento\\Framework\\Module\\Setup');
    $installer->startSetup();
    $table = $installer->getTable($table);
    echo '-----' . "\n";
    if ($installer->getConnection()->isTableExists($table)) {
        echo 'Table `' . $table . "` processed\n";
        $indexList = $installer->getConnection()->getIndexList($table);
        $pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']);
        /** @var $select \Magento\Framework\DB\Select */
        $select = $installer->getConnection()->select()->from($table, array('id' => $pkField, 'content' => $col));
        $result = $installer->getConnection()->fetchPairs($select);
        echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n";
        $logMessages = array();
        foreach ($result as $recordId => $string) {
            $content = str_replace('{{skin', '{{view', $string, $count);
            if ($count) {
                $installer->getConnection()->update($table, array($col => $content), $installer->getConnection()->quoteInto($pkField . '=?', $recordId));
                $logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`';
            } else {
                $logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`';
            }
        }
        if (count($result)) {
            printLog($logMessages);
        }
    } else {
        echo 'Table `' . $table . "` was not found\n";
    }
    $installer->endSetup();
    echo '-----' . "\n";
}
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:42,代码来源:themes_view.php

示例3: setUp

 protected function setUp()
 {
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_builder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerDetailsBuilder');
     $this->_customerBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder');
     $this->_addressBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
 }
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:CustomerDetailsBuilderTest.php

示例4: __wakeup

 public function __wakeup()
 {
     $this->pluginLocator = \Magento\Framework\App\ObjectManager::getInstance();
     $this->pluginList = $this->pluginLocator->get('Magento\\Framework\\Interception\\PluginList');
     $this->chain = $this->pluginLocator->get('Magento\\Framework\\Interception\\Chain');
     $this->subjectType = get_parent_class($this);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:SourceClassWithNamespaceInterceptor.php

示例5: setUp

 public function setUp()
 {
     $directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', array('root' => \Magento\Framework\App\Filesystem::ROOT_DIR, 'directories' => array(\Magento\Framework\App\Filesystem::MODULES_DIR => array('path' => dirname(__DIR__)))));
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem', array('directoryList' => $directoryList));
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $this->_objectManager->create('Magento\\Persistent\\Model\\Persistent\\Config', array('filesystem' => $filesystem));
 }
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:ConfigTest.php

示例6: testGetGridParentHtml

 public function testGetGridParentHtml()
 {
     $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Cart', '', array());
     $mockCollection = $this->getMockBuilder('\\Magento\\Framework\\Data\\Collection')->disableOriginalConstructor()->getMock();
     $this->_block->setCollection($mockCollection);
     $this->assertContains("<div class=\"grid-actions\">", $this->_block->getGridParentHtml());
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:7,代码来源:CartTest.php

示例7: modifyPrice

 /**
  * Modify price
  *
  * @param mixed $price
  * @param Product $product
  * @return mixed
  */
 public function modifyPrice($price, Product $product)
 {
     foreach ($this->modifiers as $modifierClass) {
         $price = $this->objectManager->get($modifierClass)->modifyPrice($price, $product);
     }
     return $price;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Composite.php

示例8: testCreate

 public function testCreate()
 {
     $type = '1';
     $data = ['data2', 'data3'];
     $this->objectManagerMock->expects($this->once())->method('create')->with($type, $data);
     $this->conditionFactory->create($type, $data);
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:7,代码来源:ConditionFactoryTest.php

示例9: create

 /**
  * Create link builder instance
  *
  * @param string $instance
  * @param array $arguments
  * @return CopyConstructorInterface
  * @throws \InvalidArgumentException
  */
 public function create($instance, array $arguments = array())
 {
     if (!is_subclass_of($instance, '\\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface')) {
         throw new \InvalidArgumentException($instance . ' does not implement \\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface');
     }
     return $this->objectManager->create($instance, $arguments);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:CopyConstructorFactory.php

示例10: createState

 /**
  * Create state object
  *
  * @param string $cardType
  * @return \Magento\Centinel\Model\AbstractState|false
  */
 public function createState($cardType)
 {
     if (!isset($this->_stateClassMap[$cardType])) {
         return false;
     }
     return $this->_objectManager->create($this->_stateClassMap[$cardType]);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:StateFactory.php

示例11: create

 /**
  * Create new calculator
  *
  * @param string $type Type of calculator
  * @param int $storeId
  * @param Address $billingAddress
  * @param Address $shippingAddress
  * @param null|int $customerTaxClassId
  * @param null|int $customerId
  * @return \Magento\Tax\Model\Calculation\AbstractCalculator
  * @throws \InvalidArgumentException
  */
 public function create($type, $storeId, Address $billingAddress = null, Address $shippingAddress = null, $customerTaxClassId = null, $customerId = null)
 {
     switch ($type) {
         case self::CALC_UNIT_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\UnitBaseCalculator';
             break;
         case self::CALC_ROW_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\RowBaseCalculator';
             break;
         case self::CALC_TOTAL_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\TotalBaseCalculator';
             break;
         default:
             throw new \InvalidArgumentException('Unknown calculation type: ' . $type);
     }
     /** @var \Magento\Tax\Model\Calculation\AbstractCalculator $calculator */
     $calculator = $this->objectManager->create($className, ['storeId' => $storeId]);
     if (null != $shippingAddress) {
         $calculator->setShippingAddress($shippingAddress);
     }
     if (null != $billingAddress) {
         $calculator->setBillingAddress($billingAddress);
     }
     if (null != $customerTaxClassId) {
         $calculator->setCustomerTaxClassId($customerTaxClassId);
     }
     if (null != $customerId) {
         $calculator->setCustomerId($customerId);
     }
     return $calculator;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:43,代码来源:CalculatorFactory.php

示例12: _getSubject

 /**
  * Retrieve subject
  *
  * @return \Magento\Backend\Model\Config\Structure\Element\Group
  */
 protected function _getSubject()
 {
     if (!$this->_subject) {
         $this->_subject = $this->_objectManager->create('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group');
     }
     return $this->_subject;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:12,代码来源:Proxy.php

示例13: get

 /**
  * Get Installer Db type instance
  *
  * @param string $type
  * @return \Magento\Install\Model\Installer\Db\AbstractDb | bool
  * @throws \InvalidArgumentException
  */
 public function get($type)
 {
     if (!empty($type) && isset($this->_types[(string) $type])) {
         return $this->_objectManager->get($this->_types[(string) $type]);
     }
     return false;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Factory.php

示例14: create

 /**
  * @param string $className
  * @return \Magento\ImportExport\Model\Export\Entity\AbstractEntity|\Magento\ImportExport\Model\Export\AbstractEntity
  * @throws \InvalidArgumentException
  */
 public function create($className)
 {
     if (!$className) {
         throw new \InvalidArgumentException('Incorrect class name');
     }
     return $this->_objectManager->create($className);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:12,代码来源:Factory.php

示例15: create

 /**
  * @param string $indexerInstanceName
  * @return \Magento\Index\Model\Indexer\AbstractIndexer|null
  */
 public function create($indexerInstanceName)
 {
     if ($indexerInstanceName) {
         return $this->_objectManager->create($indexerInstanceName);
     }
     return null;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Factory.php


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