예제 #1
0
 /**
  * Try to get the possible result of all getter methods.
  *
  * @return string
  *   The generated markup.
  */
 public function callMe()
 {
     $output = '';
     /** @var \reflectionClass $ref */
     $ref = $this->parameters['ref'];
     foreach ($this->parameters['methodList'] as $methodName) {
         $propertyName = substr($methodName, 3);
         // We may be facing different writing styles.
         // The property we want from getMyProperty() should be named
         // myProperty, but we can not rely on this.
         // We will check:
         // MyProperty
         // myProperty
         // myproperty
         // my_property
         if ($ref->hasProperty($propertyName)) {
             $refProp = $ref->getProperty($propertyName);
         }
         $realName = lcfirst($propertyName);
         if ($ref->hasProperty(lcfirst($realName))) {
             $refProp = $ref->getProperty($realName);
         }
         $realName = strtolower($propertyName);
         if ($ref->hasProperty(strtolower($realName))) {
             $refProp = $ref->getProperty($realName);
         }
         $realName = $this->convertToSnakeCase($propertyName);
         if ($ref->hasProperty($this->convertToSnakeCase($realName))) {
             $refProp = $ref->getProperty($realName);
         }
         if (empty($refProp)) {
             // Found nothing  :-(
             $value = null;
         } else {
             // We've got ourself a possible result!
             $refProp->setAccessible(true);
             $value = $refProp->getValue($this->parameters['data']);
         }
         // We need to decide if we are handling static getters.
         $model = new Model($this->storage);
         $model->setData($value)->setName($methodName)->setConnector2('()');
         if ($ref->getMethod($methodName)->isStatic()) {
             $model->setConnector1('::');
         } else {
             $model->setConnector1('->');
         }
         $output .= $this->storage->routing->analysisHub($model);
     }
     return $output;
 }