Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
ClassGenerator Class Reference
Inheritance diagram for ClassGenerator:
CodeGeneratorInterface InterfaceGenerator

Public Member Functions

 setClassDocBlock (array $docBlock)
 
 addMethods (array $methods)
 
 addMethodFromGenerator (MethodGenerator $method)
 
 addProperties (array $properties)
 
 addPropertyFromGenerator (PropertyGenerator $property)
 
 getNamespaceName ()
 
- Public Member Functions inherited from CodeGeneratorInterface
 setName ($name)
 
 setExtendedClass ($extendedClass)
 
 setImplementedInterfaces (array $interfaces)
 
 addTrait ($trait)
 

Protected Member Functions

 _setDataToObject ($object, array $data, array $map)
 
 createMethodGenerator ()
 

Protected Attributes

 $_docBlockOptions
 
 $_propertyOptions
 
 $_methodOptions
 
 $_parameterOptions
 

Detailed Description

Definition at line 11 of file ClassGenerator.php.

Member Function Documentation

◆ _setDataToObject()

_setDataToObject (   $object,
array  $data,
array  $map 
)
protected
Parameters
object$object
array$data
array$map
Returns
void

Definition at line 72 of file ClassGenerator.php.

73  {
74  foreach ($map as $arrayKey => $setterName) {
75  if (isset($data[$arrayKey])) {
76  $object->{$setterName}($data[$arrayKey]);
77  }
78  }
79  }

◆ addMethodFromGenerator()

addMethodFromGenerator ( MethodGenerator  $method)

Add method from MethodGenerator

Parameters
MethodGenerator$method
Returns
$this
Exceptions

Definition at line 150 of file ClassGenerator.php.

151  {
152  if (!is_string($method->getName())) {
153  throw new \InvalidArgumentException('addMethodFromGenerator() expects string for name');
154  }
155 
156  return parent::addMethodFromGenerator($method);
157  }
$method
Definition: info.phtml:13

◆ addMethods()

addMethods ( array  $methods)

addMethods()

Parameters
array$methods
Returns
$this

Implements CodeGeneratorInterface.

Definition at line 102 of file ClassGenerator.php.

103  {
104  foreach ($methods as $methodOptions) {
105  $methodObject = $this->createMethodGenerator();
106  $this->_setDataToObject($methodObject, $methodOptions, $this->_methodOptions);
107 
108  if (isset(
109  $methodOptions['parameters']
110  ) && is_array(
111  $methodOptions['parameters']
112  ) && count(
113  $methodOptions['parameters']
114  ) > 0
115  ) {
116  $parametersArray = [];
117  foreach ($methodOptions['parameters'] as $parameterOptions) {
118  $parameterObject = new \Zend\Code\Generator\ParameterGenerator();
119  $this->_setDataToObject($parameterObject, $parameterOptions, $this->_parameterOptions);
120  $parametersArray[] = $parameterObject;
121  }
122 
123  $methodObject->setParameters($parametersArray);
124  }
125 
126  if (isset($methodOptions['docblock']) && is_array($methodOptions['docblock'])) {
127  $docBlockObject = new \Zend\Code\Generator\DocBlockGenerator();
128  $docBlockObject->setWordWrap(false);
129  $this->_setDataToObject($docBlockObject, $methodOptions['docblock'], $this->_docBlockOptions);
130 
131  $methodObject->setDocBlock($docBlockObject);
132  }
133 
134  if (!empty($methodOptions['returnType'])) {
135  $methodObject->setReturnType($methodOptions['returnType']);
136  }
137 
138  $this->addMethodFromGenerator($methodObject);
139  }
140  return $this;
141  }
_setDataToObject($object, array $data, array $map)
$methods
Definition: billing.phtml:71

◆ addProperties()

addProperties ( array  $properties)

addProperties()

Parameters
array$properties
Returns
$this
Exceptions

Implements CodeGeneratorInterface.

Definition at line 166 of file ClassGenerator.php.

167  {
168  foreach ($properties as $propertyOptions) {
169  $propertyObject = new PropertyGenerator();
170  $this->_setDataToObject($propertyObject, $propertyOptions, $this->_propertyOptions);
171 
172  if (isset($propertyOptions['docblock'])) {
173  $docBlock = $propertyOptions['docblock'];
174  if (is_array($docBlock)) {
175  $docBlockObject = new \Zend\Code\Generator\DocBlockGenerator();
176  $docBlockObject->setWordWrap(false);
177  $this->_setDataToObject($docBlockObject, $docBlock, $this->_docBlockOptions);
178  $propertyObject->setDocBlock($docBlockObject);
179  }
180  }
181 
182  $this->addPropertyFromGenerator($propertyObject);
183  }
184 
185  return $this;
186  }
_setDataToObject($object, array $data, array $map)
$properties
Definition: categories.php:26
addPropertyFromGenerator(PropertyGenerator $property)

◆ addPropertyFromGenerator()

addPropertyFromGenerator ( PropertyGenerator  $property)

Add property from PropertyGenerator

Parameters
PropertyGenerator$property
Returns
$this
Exceptions

Definition at line 195 of file ClassGenerator.php.

196  {
197  if (!is_string($property->getName())) {
198  throw new \InvalidArgumentException('addPropertyFromGenerator() expects string for name');
199  }
200 
201  return parent::addPropertyFromGenerator($property);
202  }

◆ createMethodGenerator()

createMethodGenerator ( )
protected

Instantiate method generator object.

Returns
MethodGenerator

Definition at line 209 of file ClassGenerator.php.

210  {
211  return new MethodGenerator();
212  }

◆ getNamespaceName()

getNamespaceName ( )
Returns
string|null

Definition at line 217 of file ClassGenerator.php.

218  {
219  return ltrim(parent::getNamespaceName(), '\\') ?: null;
220  }

◆ setClassDocBlock()

setClassDocBlock ( array  $docBlock)

Set class dock block

Parameters
array$docBlock
Returns
$this

Implements CodeGeneratorInterface.

Definition at line 87 of file ClassGenerator.php.

88  {
89  $docBlockObject = new \Zend\Code\Generator\DocBlockGenerator();
90  $docBlockObject->setWordWrap(false);
91  $this->_setDataToObject($docBlockObject, $docBlock, $this->_docBlockOptions);
92 
93  return parent::setDocBlock($docBlockObject);
94  }
_setDataToObject($object, array $data, array $map)

Field Documentation

◆ $_docBlockOptions

$_docBlockOptions
protected
Initial value:
= [
'shortDescription' => 'setShortDescription',
'longDescription' => 'setLongDescription',
'tags' => 'setTags',
]

Definition at line 19 of file ClassGenerator.php.

◆ $_methodOptions

$_methodOptions
protected
Initial value:
= [
'name' => 'setName',
'final' => 'setFinal',
'static' => 'setStatic',
'abstract' => 'setAbstract',
'visibility' => 'setVisibility',
'body' => 'setBody',
'returntype' => 'setReturnType'
]

Definition at line 43 of file ClassGenerator.php.

◆ $_parameterOptions

$_parameterOptions
protected
Initial value:
= [
'name' => 'setName',
'type' => 'setType',
'defaultValue' => 'setDefaultValue',
'passedByReference' => 'setPassedByReference',
'variadic' => 'setVariadic',
]

Definition at line 58 of file ClassGenerator.php.

◆ $_propertyOptions

$_propertyOptions
protected
Initial value:
= [
'name' => 'setName',
'const' => 'setConst',
'static' => 'setStatic',
'visibility' => 'setVisibility',
'defaultValue' => 'setDefaultValue',
]

Definition at line 30 of file ClassGenerator.php.


The documentation for this class was generated from the following file: