/** * Get attribute type based on its backend model. * * @param \Magento\Eav\Api\Data\AttributeInterface $attribute * @param string $serviceClass * @param $serviceBackendModelDataInterfaceMap array * @return string|null */ public function getType($attribute, $serviceClass, $serviceBackendModelDataInterfaceMap) { $backendModel = $attribute->getBackendModel(); //If empty backend model, check if it can be derived if (empty($backendModel)) { $backendModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->stringUtility->upperCaseWords($attribute->getFrontendInput())); $backendModel = class_exists($backendModelClass) ? $backendModelClass : null; } $dataInterface = isset($serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null; return $dataInterface; }
/** * Return variable value for var construction * * @param string $value raw parameters * @param string $default default value * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function getVariable($value, $default = '{no_value_defined}') { \Magento\Framework\Profiler::start('email_template_processing_variables'); $tokenizer = new Template\Tokenizer\Variable(); $tokenizer->setString($value); $stackVars = $tokenizer->tokenize(); $result = $default; $last = 0; for ($i = 0; $i < count($stackVars); $i++) { if ($i == 0 && isset($this->templateVars[$stackVars[$i]['name']])) { // Getting of template value $stackVars[$i]['variable'] =& $this->templateVars[$stackVars[$i]['name']]; } elseif (isset($stackVars[$i - 1]['variable']) && $stackVars[$i - 1]['variable'] instanceof \Magento\Framework\DataObject) { // If object calling methods or getting properties if ($stackVars[$i]['type'] == 'property') { $caller = 'get' . $this->string->upperCaseWords($stackVars[$i]['name'], '_', ''); $stackVars[$i]['variable'] = method_exists($stackVars[$i - 1]['variable'], $caller) ? $stackVars[$i - 1]['variable']->{$caller}() : $stackVars[$i - 1]['variable']->getData($stackVars[$i]['name']); } elseif ($stackVars[$i]['type'] == 'method') { // Calling of object method if (method_exists($stackVars[$i - 1]['variable'], $stackVars[$i]['name']) || substr($stackVars[$i]['name'], 0, 3) == 'get') { $stackVars[$i]['args'] = $this->getStackArgs($stackVars[$i]['args']); $stackVars[$i]['variable'] = call_user_func_array([$stackVars[$i - 1]['variable'], $stackVars[$i]['name']], $stackVars[$i]['args']); } } $last = $i; } } if (isset($stackVars[$last]['variable'])) { // If value for construction exists set it $result = $stackVars[$last]['variable']; } \Magento\Framework\Profiler::stop('email_template_processing_variables'); return $result; }
/** * Custom save logic for section * * @return void */ protected function _saveSection() { $method = '_save' . $this->string->upperCaseWords($this->getRequest()->getParam('section'), '_', ''); if (method_exists($this, $method)) { $this->{$method}(); } }
/** * Create Form Element * * @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute * @param string|int|bool $value * @param string $entityTypeCode * @param bool $isAjax * @return \Magento\Customer\Model\Metadata\Form\AbstractData */ public function create(\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute, $value, $entityTypeCode, $isAjax = false) { $dataModelClass = $attribute->getDataModel(); $params = ['entityTypeCode' => $entityTypeCode, 'value' => is_null($value) ? false : $value, 'isAjax' => $isAjax, 'attribute' => $attribute]; /** TODO fix when Validation is implemented MAGETWO-17341 */ if ($dataModelClass == 'Magento\\Customer\\Model\\Attribute\\Data\\Postcode') { $dataModelClass = 'Magento\\Customer\\Model\\Metadata\\Form\\Postcode'; } if (!empty($dataModelClass)) { $dataModel = $this->_objectManager->create($dataModelClass, $params); } else { $dataModelClass = sprintf('Magento\\Customer\\Model\\Metadata\\Form\\%s', $this->_string->upperCaseWords($attribute->getFrontendInput())); $dataModel = $this->_objectManager->create($dataModelClass, $params); } return $dataModel; }
/** * @param string $name * @param string $content * @return mixed */ protected function processMetadataContent($name, $content) { $method = 'get' . $this->string->upperCaseWords($name, '_', ''); if (method_exists($this->pageConfig, $method)) { $content = $this->pageConfig->{$method}(); } return $content; }
/** * Group model factory * * @param string $type Option type * @return \Magento\Catalog\Model\Product\Option\Type\DefaultType * @throws LocalizedException */ public function groupFactory($type) { $group = $this->getGroupByType($type); if (!empty($group)) { return $this->_optionFactory->create('Magento\\Catalog\\Model\\Product\\Option\\Type\\' . $this->string->upperCaseWords($group)); } throw new LocalizedException(__('The option type to get group instance is incorrect.')); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getType($attributeCode, $serviceClass) { if (!$serviceClass || !$attributeCode || !isset($this->serviceEntityTypeMap[$serviceClass]) || !isset($this->serviceBackendModelDataInterfaceMap[$serviceClass])) { return null; } try { $attribute = $this->attributeRepository->get($this->serviceEntityTypeMap[$serviceClass], $attributeCode); $backendModel = $attribute->getBackendModel(); } catch (NoSuchEntityException $e) { return null; } //If empty backend model, check if it can be derived if (empty($backendModel)) { $backendModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->stringUtility->upperCaseWords($attribute->getFrontendInput())); $backendModel = class_exists($backendModelClass) ? $backendModelClass : null; } $dataInterface = isset($this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null; return $dataInterface; }
/** * Set many options at once * * @param array $options * @param array $default * @return $this */ public function setOptions($options, $default = []) { $options = !is_array($options) && !$options instanceof \Traversable ? $default : $options; if (is_array($options) || $options instanceof \Traversable) { foreach ($options as $option => $value) { $setter = 'set' . $this->_stringHelper->upperCaseWords($option, '_', ''); if (method_exists($this, $setter)) { $this->{$setter}($value); } else { $this->setOption($option, $value); } } } return $this; }
/** * Return attribute data model by attribute * Set entity to data model (need for work) * * @param \Magento\Eav\Model\Attribute $attribute * @param \Magento\Framework\Model\AbstractModel $entity * @return \Magento\Eav\Model\Attribute\Data\AbstractData */ public function create(\Magento\Eav\Model\Attribute $attribute, \Magento\Framework\Model\AbstractModel $entity) { /* @var $dataModel \Magento\Eav\Model\Attribute\Data\AbstractData */ $dataModelClass = $attribute->getDataModel(); if (!empty($dataModelClass)) { if (empty($this->_dataModels[$dataModelClass])) { $dataModel = $this->_objectManager->create($dataModelClass); $this->_dataModels[$dataModelClass] = $dataModel; } else { $dataModel = $this->_dataModels[$dataModelClass]; } } else { if (empty($this->_dataModels[$attribute->getFrontendInput()])) { $dataModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->string->upperCaseWords($attribute->getFrontendInput())); $dataModel = $this->_objectManager->create($dataModelClass); $this->_dataModels[$attribute->getFrontendInput()] = $dataModel; } else { $dataModel = $this->_dataModels[$attribute->getFrontendInput()]; } } $dataModel->setAttribute($attribute); $dataModel->setEntity($entity); return $dataModel; }
/** * @param string $testString * @param string $sourceSeparator * @param string $destinationSeparator * @param string $expected * * @dataProvider upperCaseWordsWithSeparatorsDataProvider */ public function testUpperCaseWordsWithSeparators($testString, $sourceSeparator, $destinationSeparator, $expected) { $actual = $this->_string->upperCaseWords($testString, $sourceSeparator, $destinationSeparator); $this->assertEquals($expected, $actual); }