コード例 #1
0
 /**
  * Generate a list of select fields with mapping of client facing attribute names to field names used in SQL select.
  *
  * @param string $attributeCode
  * @param array $selectFields
  * @return array
  */
 public function getSelectFieldsMap($attributeCode, $selectFields)
 {
     $referenceTableAlias = $this->getReferenceTableAlias($attributeCode);
     $useFieldInAlias = count($selectFields) > 1;
     $selectFieldsAliases = [];
     foreach ($selectFields as $selectField) {
         $internalFieldName = $selectField[Converter::JOIN_FIELD_COLUMN] ? $selectField[Converter::JOIN_FIELD_COLUMN] : $selectField[Converter::JOIN_FIELD];
         $setterName = 'set' . ucfirst(SimpleDataObjectConverter::snakeCaseToCamelCase($selectField[Converter::JOIN_FIELD]));
         $selectFieldsAliases[] = [JoinDataInterface::SELECT_FIELD_EXTERNAL_ALIAS => $attributeCode . ($useFieldInAlias ? '.' . $selectField[Converter::JOIN_FIELD] : ''), JoinDataInterface::SELECT_FIELD_INTERNAL_ALIAS => $referenceTableAlias . '_' . $internalFieldName, JoinDataInterface::SELECT_FIELD_WITH_DB_PREFIX => $referenceTableAlias . '.' . $internalFieldName, JoinDataInterface::SELECT_FIELD_SETTER => $setterName];
     }
     return $selectFieldsAliases;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function _getClassMethods()
 {
     $methods = [];
     foreach ($this->getCustomAttributes() as $attributeName => $attributeType) {
         $propertyName = SimpleDataObjectConverter::snakeCaseToCamelCase($attributeName);
         $getterName = 'get' . ucfirst($propertyName);
         $setterName = 'set' . ucfirst($propertyName);
         $methods[] = ['name' => $getterName, 'body' => "return \$this->_get('{$attributeName}');", 'docblock' => ['tags' => [['name' => 'return', 'description' => $attributeType]]]];
         $methods[] = ['name' => $setterName, 'parameters' => [['name' => $propertyName]], 'body' => "\$this->setData('{$attributeName}', \${$propertyName});" . PHP_EOL . "return \$this;", 'docblock' => ['tags' => [['name' => 'param', 'description' => "{$attributeType} \${$propertyName}"], ['name' => 'return', 'description' => '$this']]]];
     }
     return $methods;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function _getClassMethods()
 {
     $methods = [];
     foreach ($this->getCustomAttributes() as $attributeName => $attributeMetadata) {
         $attributeType = $attributeMetadata[Converter::DATA_TYPE];
         $propertyName = SimpleDataObjectConverter::snakeCaseToCamelCase($attributeName);
         $getterName = 'get' . ucfirst($propertyName);
         $setterName = 'set' . ucfirst($propertyName);
         $methods[] = ['name' => $getterName, 'body' => "return \$this->_get('{$attributeName}');", 'docblock' => ['tags' => [['name' => 'return', 'description' => $attributeType . '|null']]]];
         $parameters = ['name' => $propertyName];
         // If the attribute type is a valid type declaration (e.g., interface, class, array) then use it to enforce
         // constraints on the generated setter methods
         if ($this->getTypeProcessor()->isValidTypeDeclaration($attributeType)) {
             $parameters['type'] = $attributeType;
         }
         $methods[] = ['name' => $setterName, 'parameters' => [$parameters], 'body' => "\$this->setData('{$attributeName}', \${$propertyName});" . PHP_EOL . "return \$this;", 'docblock' => ['tags' => [['name' => 'param', 'description' => "{$attributeType} \${$propertyName}"], ['name' => 'return', 'description' => '$this']]]];
     }
     return $methods;
 }
コード例 #4
0
 public function snakeCaseToCamelCase($data)
 {
     $result = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToCamelCase($data);
     return $result;
 }
コード例 #5
0
 /**
  * Check presence for both camelCase and snake_case keys in array and substitute if either is present
  *
  * @param array $requestData
  * @param string $key
  * @param string $value
  * @return void
  */
 protected function substituteParameters(&$requestData, $key, $value)
 {
     $snakeCaseKey = SimpleDataObjectConverter::camelCaseToSnakeCase($key);
     $camelCaseKey = SimpleDataObjectConverter::snakeCaseToCamelCase($key);
     if (isset($requestData[$camelCaseKey])) {
         $requestData[$camelCaseKey] = $value;
     } else {
         $requestData[$snakeCaseKey] = $value;
     }
 }
コード例 #6
0
 public function getSubTabSuffix()
 {
     return SimpleDataObjectConverter::snakeCaseToCamelCase(str_replace('.', '_', $this->getNameInLayout()));
 }
コード例 #7
0
 /**
  * Verify property in parameter's object
  *
  * @param string $serviceClassName name of the service class that we are trying to call
  * @param string $serviceMethodName name of the method that we are trying to call
  * @param string $serviceMethodParamName
  * @param string $objectProperty
  * @return bool
  */
 private function isPropertyDeclaredInDataObject($serviceClassName, $serviceMethodName, $serviceMethodParamName, $objectProperty)
 {
     if ($serviceClassName && $serviceMethodName) {
         $methodParams = $this->getMethodsMap()->getMethodParams($serviceClassName, $serviceMethodName);
         $index = array_search($serviceMethodParamName, array_column($methodParams, 'name'));
         if ($index !== false) {
             $paramObjectType = $methodParams[$index][MethodsMap::METHOD_META_TYPE];
             $setter = 'set' . ucfirst(SimpleDataObjectConverter::snakeCaseToCamelCase($objectProperty));
             if (array_key_exists($setter, $this->getMethodsMap()->getMethodsMap($paramObjectType))) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #8
0
 /**
  * Format $name (JSON or XML) to the valid property name (camelCase with lowercase first).
  * Sample: 'json_prop_name' => 'jsonPropName'.
  *
  * @param $name
  * @return string
  */
 public function formatPropertyName($name)
 {
     $result = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToCamelCase($name);
     return $result;
 }