Пример #1
0
 /**
  * Retrieve full path to a directory of certain type within a module
  *
  * @param string $moduleName Fully-qualified module name
  * @param string $type Type of module's directory to retrieve
  * @return string
  * @throws \InvalidArgumentException
  */
 public function getDir($moduleName, $type = '')
 {
     $path = $this->_string->upperCaseWords($moduleName, '_', '/');
     if ($type) {
         if (!in_array($type, array('etc', 'sql', 'data', 'i18n', 'view', 'Controller'))) {
             throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
         }
         $path .= '/' . $type;
     }
     $result = $this->_modulesDirectory->getAbsolutePath($path);
     return $result;
 }
Пример #2
0
 /**
  * Retrieve full path to a directory of certain type within a module
  *
  * @param string $moduleName Fully-qualified module name
  * @param string $type Type of module's directory to retrieve
  * @return string
  * @throws \InvalidArgumentException
  */
 public function getDir($moduleName, $type = '')
 {
     if (null === ($path = $this->moduleRegistry->getModulePath($moduleName))) {
         $relativePath = $this->_string->upperCaseWords($moduleName, '_', '/');
         $path = $this->_modulesDirectory->getAbsolutePath($relativePath);
     }
     if ($type) {
         if (!in_array($type, [self::MODULE_ETC_DIR, self::MODULE_I18N_DIR, self::MODULE_VIEW_DIR, self::MODULE_CONTROLLER_DIR])) {
             throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
         }
         $path .= '/' . $type;
     }
     return $path;
 }
Пример #3
0
 /**
  * Create attribute model
  *
  * @param string $name
  * @return \Magento\GoogleShopping\Model\Attribute\DefaultAttribute
  */
 public function createAttribute($name)
 {
     $modelName = 'Magento\\GoogleShopping\\Model\\Attribute\\' . $this->_string->upperCaseWords($this->_googleShoppingHelper->normalizeName($name));
     try {
         /** @var \Magento\GoogleShopping\Model\Attribute\DefaultAttribute $attributeModel */
         $attributeModel = $this->_objectManager->create($modelName);
         if (!$attributeModel) {
             $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
         }
     } catch (\Exception $e) {
         $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
     }
     $attributeModel->setName($name);
     return $attributeModel;
 }
Пример #4
0
 /**
  * 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}();
     }
 }
Пример #5
0
 /**
  * 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\Object) {
             // 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;
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * @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;
 }
Пример #8
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Пример #11
0
 /**
  * Set many options at once
  *
  * @param array $options
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function setOptions($options)
 {
     if (!is_array($options) && !$options instanceof \Traversable) {
         throw new \InvalidArgumentException(sprintf('Parameter provided to %s must be an array or Traversable', __METHOD__));
     }
     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;
 }
Пример #12
0
 /**
  * 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;
 }
Пример #13
0
 /**
  * @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);
 }