Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NameFinder.php
Go to the documentation of this file.
1 <?php
8 
9 use Zend\Code\Reflection\ClassReflection;
10 
12 {
19  public function getFieldNameFromGetterName($getterName)
20  {
21  if ((strpos($getterName, 'get') === 0)) {
23  $fieldName = substr($getterName, strlen('get'));
24  } elseif ((strpos($getterName, 'is') === 0)) {
26  $fieldName = substr($getterName, strlen('is'));
27  } elseif ((strpos($getterName, 'has') === 0)) {
29  $fieldName = substr($getterName, strlen('has'));
30  } else {
31  $fieldName = $getterName;
32  }
33  return lcfirst($fieldName);
34  }
35 
42  public function getFieldDescriptionFromGetterDescription($shortDescription)
43  {
44  return ucfirst(substr(strstr($shortDescription, " "), 1));
45  }
46 
55  public function getGetterMethodName(ClassReflection $class, $camelCaseProperty)
56  {
57  $getterName = 'get' . $camelCaseProperty;
58  $boolGetterName = 'is' . $camelCaseProperty;
59  return $this->findAccessorMethodName($class, $camelCaseProperty, $getterName, $boolGetterName);
60  }
61 
70  public function getSetterMethodName(ClassReflection $class, $camelCaseProperty)
71  {
72  $setterName = 'set' . $camelCaseProperty;
73  $boolSetterName = 'setIs' . $camelCaseProperty;
74  return $this->findAccessorMethodName($class, $camelCaseProperty, $setterName, $boolSetterName);
75  }
76 
87  public function findAccessorMethodName(
88  ClassReflection $class,
89  $camelCaseProperty,
90  $accessorName,
91  $boolAccessorName
92  ) {
93  if ($this->hasMethod($class, $accessorName)) {
94  $methodName = $accessorName;
95  return $methodName;
96  } elseif ($this->hasMethod($class, $boolAccessorName)) {
97  $methodName = $boolAccessorName;
98  return $methodName;
99  } else {
100  throw new \LogicException(
101  sprintf(
102  'Property "%s" does not have accessor method "%s" in class "%s".',
103  $camelCaseProperty,
104  $accessorName,
105  $class->getName()
106  )
107  );
108  }
109  }
110 
120  public function hasMethod(ClassReflection $class, $methodName)
121  {
122  return $class->hasMethod($methodName) && ($class->getMethod($methodName)->getName() == $methodName);
123  }
124 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
findAccessorMethodName(ClassReflection $class, $camelCaseProperty, $accessorName, $boolAccessorName)
Definition: NameFinder.php:87
getFieldDescriptionFromGetterDescription($shortDescription)
Definition: NameFinder.php:42
getSetterMethodName(ClassReflection $class, $camelCaseProperty)
Definition: NameFinder.php:70
$_option $_optionId $class
Definition: date.phtml:13
getGetterMethodName(ClassReflection $class, $camelCaseProperty)
Definition: NameFinder.php:55
hasMethod(ClassReflection $class, $methodName)
Definition: NameFinder.php:120