本文整理汇总了PHP中Magento\Framework\App\ObjectManager类的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager类的具体用法?PHP ObjectManager怎么用?PHP ObjectManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: getDataPersistor
/**
* Get Data Persistor
*
* @return DataPersistorInterface
*/
private function getDataPersistor()
{
if ($this->dataPersistor === null) {
$this->dataPersistor = ObjectManager::getInstance()->get(DataPersistorInterface::class);
}
return $this->dataPersistor;
}
示例3: getOptionRepository
/**
* @return Option\Repository
*/
private function getOptionRepository()
{
if (null === $this->optionRepository) {
$this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Catalog\\Model\\Product\\Option\\Repository');
}
return $this->optionRepository;
}
示例4: getAnchorUrlRewriteGenerator
/**
* @return AnchorUrlRewriteGenerator
*
* @deprecated
*/
private function getAnchorUrlRewriteGenerator()
{
if ($this->anchorUrlRewriteGenerator === null) {
$this->anchorUrlRewriteGenerator = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\CatalogUrlRewrite\\Model\\Product\\AnchorUrlRewriteGenerator');
}
return $this->anchorUrlRewriteGenerator;
}
示例5: _construct
protected function _construct()
{
if ($this->checkConfig()) {
$page = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Framework\\View\\Page\\Config');
$page->addPageAsset('Mageplaza_Blog::css/index/mp.css');
}
}
示例6: execute
public function execute()
{
$result = $this->resultJsonFactory->create();
$data = array();
try {
$params = $this->getRequest()->getParams();
if (isset($params['lastid']) && isset($params['limit'])) {
$lastId = $params['lastid'];
$limit = $params['limit'];
$isadmin = isset($params['isadmin']) ? $params['isadmin'] : false;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$raaDataHelper = $objectManager->create('Retail\\Analytics\\Helper\\Data');
$width = $raaDataHelper->getImageWidth();
$height = $raaDataHelper->getImageHeight();
$imagetype = "small_image";
if (isset($params['width']) && $params['width'] != null && $params['width'] != "") {
$width = $params['width'];
}
if (isset($params['height']) && $params['height'] != null && $params['height'] != "") {
$height = $params['height'];
}
if (isset($params['imagetype']) && $params['imagetype'] != null && $params['imagetype'] != "") {
$imagetype = $params['imagetype'];
}
$producCollection = new \Retail\Analytics\Model\Product();
$data = $producCollection->getProductFinalPrice($lastId, $limit, $imagetype, $width, $height, $isadmin);
return $result->setData($data);
}
} catch (Exception $e) {
return $result->setData($data);
}
}
示例7: __wakeup
/**
* {@inheritdoc}
*/
public function __wakeup()
{
parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->_resource = $objectManager->get('Magento\\Authorization\\Model\\ResourceModel\\Role');
$this->_resourceCollection = $objectManager->get('Magento\\Authorization\\Model\\ResourceModel\\Role\\Collection');
}
示例8: getHttpClientFactory
/**
* Get HttpClientFactory dependency
*
* @return \Magento\Framework\HTTP\ZendClientFactory
*
* @deprecated
*/
private function getHttpClientFactory()
{
if ($this->httpClientFactory === null) {
$this->httpClientFactory = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Framework\\HTTP\\ZendClientFactory');
}
return $this->httpClientFactory;
}
示例9: createTestimonialAction
public function createTestimonialAction()
{
$data = $this->getRequest()->getPost();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$testimonial = $objectManager->get('V3N0m21\\Testimonials\\Model\\Testimonial');
$testimonial->setId();
}
示例10: testSetSaveHandler
/**
* Tests that the session handler is correctly set when object is created.
*
* @dataProvider saveHandlerProvider
* @param string $deploymentConfigHandler
* @param string $iniHandler
*/
public function testSetSaveHandler($deploymentConfigHandler, $iniHandler)
{
// Set expected session.save_handler config
if ($deploymentConfigHandler) {
if ($deploymentConfigHandler !== 'files') {
$expected = 'user';
} else {
$expected = $deploymentConfigHandler;
}
} else {
if ($iniHandler) {
$expected = $iniHandler;
} else {
$expected = SaveHandlerInterface::DEFAULT_HANDLER;
}
}
// Set ini configuration
if ($iniHandler) {
ini_set('session.save_handler', $iniHandler);
}
/** @var DeploymentConfig | \PHPUnit_Framework_MockObject_MockObject $deploymentConfigMock */
$deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)->disableOriginalConstructor()->getMock();
$deploymentConfigMock->expects($this->once())->method('get')->with(Config::PARAM_SESSION_SAVE_METHOD, SaveHandlerInterface::DEFAULT_HANDLER)->willReturn($deploymentConfigHandler ?: SaveHandlerInterface::DEFAULT_HANDLER);
new SaveHandler(ObjectManager::getInstance()->get(SaveHandlerFactory::class), $deploymentConfigMock);
// Test expectation
$this->assertEquals($expected, ObjectManager::getInstance()->get(ConfigInterface::class)->getOption('session.save_handler'));
}
示例11: _prepareForm
/**
* Prepare form fields
*
* @return \Magento\Backend\Block\Widget\Form
*/
protected function _prepareForm()
{
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('manufacturer_');
$form->setFieldNameSuffix('manufacturer');
$model = $this->_coreRegistry->registry('manufacturer_manufacturer');
$om = \Magento\Framework\App\ObjectManager::getInstance();
$reader = $om->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'manufacturer');
$attributeOptions = $reader->getSource()->getAllOptions(true, true);
$default = array('value' => '', 'label' => 'Choose Brand');
$i = 0;
$manufacturer[$i] = $default;
foreach ($attributeOptions as $key => $value) {
$i++;
if ($key != 0) {
$manufacturer[$i] = $value;
//$name[$i] = $value['label'];
}
}
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('General')]);
if ($model->getId()) {
$fieldset->addField('id', 'hidden', ['name' => 'id']);
}
$fieldset->addField('mfc_id', 'select', ['name' => 'mfc_id', 'label' => __('Manufacturer'), 'required' => true, 'values' => $manufacturer]);
$fieldset->addField('status', 'select', ['name' => 'status', 'label' => __('Status'), 'options' => $this->_manufacturerStatus->toOptionArray()]);
$fieldset->addField('position', 'textarea', ['name' => 'position', 'label' => __('Position'), 'required' => true, 'style' => 'height: 15em; width: 30em;']);
$fieldset->addField('image_path', 'image', array('name' => 'image_path', 'label' => __('Image'), 'title' => __('Image')));
$wysiwygConfig = $this->_wysiwygConfig->getConfig();
$fieldset->addField('description', 'editor', ['name' => 'description', 'label' => __('Description'), 'required' => true, 'config' => $wysiwygConfig]);
$data = $model->getData();
$form->setValues($data);
$this->setForm($form);
return parent::_prepareForm();
}
示例12: getImageUploader
/**
* Get image uploader
*
* @return \Magento\Catalog\Model\ImageUploader
*
* @deprecated
*/
private function getImageUploader()
{
if ($this->imageUploader === null) {
$this->imageUploader = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Catalog\\CategoryImageUpload');
}
return $this->imageUploader;
}
示例13: getItmeProductThumbnailUrl
public function getItmeProductThumbnailUrl()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$thumbnailHelper = $objectManager->get('Magento\\Catalog\\Helper\\Image');
$thumbnail = $thumbnailHelper->init($this->getItmeProduct(), 'thumbnail')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($this->getItmeProduct()->getImage())->resize('160', '160')->getUrl();
return $thumbnail;
}
示例14: getAttributeHelper
/**
* The getter function to get the attributeHelper for real application code
*
* @deprecated
*
* @return Attribute
*/
private function getAttributeHelper()
{
if ($this->attributeHelper === null) {
$this->attributeHelper = ObjectManager::getInstance()->get('Magento\\Eav\\Model\\Entity\\Attribute');
}
return $this->attributeHelper;
}
示例15: getCookieMetadataFactory
/**
* Retrieve cookie metadata factory
*
* @deprecated
* @return CookieMetadataFactory
*/
private function getCookieMetadataFactory()
{
if (!$this->cookieMetadataFactory) {
$this->cookieMetadataFactory = ObjectManager::getInstance()->get(CookieMetadataFactory::class);
}
return $this->cookieMetadataFactory;
}