/**
  * @param string $name
  * @param array $args
  * @throws Exceptions\MemberAccessException
  * @return IPaypalPaymentButton|mixed
  */
 public function __call($name, $args)
 {
     if (substr($name, 0, 6) == 'create' && strlen($name) > 6) {
         $name = substr($name, -(strlen($name) - 6));
         $reflection = new ClassType(get_called_class());
         $componentName = $reflection->getNamespaceName() . '\\' . $name;
         if ($this->config === NULL) {
             throw new MemberAccessException('Config is not set');
         }
         /** @var IPaypalPaymentButton $component */
         $component = new $componentName($this->config);
         if (!empty($args) && is_array($settings = $args[0])) {
             $component->assign($settings);
         }
         return $component;
     } else {
         throw new MemberAccessException(sprintf('%s is not create method', $name));
     }
 }
 /**
  * Try to find entity class in possible NS
  *
  * @param class $className
  * @param object $entity
  * @return null|string
  */
 private function findEntityWholeName($className, $entity)
 {
     $existingClass = NULL;
     // try to locate class in this namespace
     if (!class_exists($className)) {
         // try to find in namespace of entity
         $reflection = new ClassType($entity);
         $existingClass = $reflection->getNamespaceName() . "\\" . $className;
         // try to locate in parents namespace (recursive)
         if (!class_exists($existingClass)) {
             $parentClass = $reflection->getParentClass();
             while ($parentClass !== NULL) {
                 $existingClass = $reflection->getParentClass()->getNamespaceName() . "\\" . $className;
                 // not found try to find in parent namespace
                 if (!class_exists($existingClass)) {
                     $rc = new ClassType($parentClass);
                     $parentClass = $rc->getParentClass();
                     $existingClass = NULL;
                 } else {
                     $parentClass = NULL;
                 }
             }
         }
     } else {
         $existingClass = $className;
     }
     return $existingClass;
 }
Exemplo n.º 3
0
 /**
  * Parse Annotation
  * @param ClassType $ref
  * @param array $annotations
  * @param string $type name of annotation
  * @throws RestException
  */
 private function parseProperties(ClassType $ref, array $annotations, $type)
 {
     if (!isset($annotations[$type])) {
         return;
     }
     foreach ($annotations[$type] as $val) {
         $trimmed = trim(preg_replace('!\\s+!', ' ', $val));
         //Replace multiple whitespaces
         $expectedClassName = $className = strstr($trimmed, ' ', true);
         //Try find full name of existing class
         if (!class_exists($className)) {
             $expectedClassName = $ref->getNamespaceName() . '\\' . trim($className, '\\');
             if (!class_exists($expectedClassName)) {
                 $expectedClassName = $this->getClassNameFromAlias($ref, $className);
                 if (!$expectedClassName or !class_exists($expectedClassName)) {
                     continue;
                 }
             }
         }
         $parents = class_parents($expectedClassName);
         if ($expectedClassName != DataHash::class and (!$parents or !in_array(DataHash::class, $parents))) {
             throw RestException::notInheritedForm($expectedClassName, DataHash::class);
         }
         $prop = strstr($trimmed, '$');
         $pos = strpos($prop, ' ');
         $propertyName = $pos != false ? substr($prop, 1, $pos - 1) : substr($prop, 1);
         $property = $this->getClassPropertyByName($ref, $propertyName);
         if ($property and !$property->protected) {
             throw RestException::notProtectedProperty($ref->getName(), $propertyName);
         }
         $this->classProperties[$ref->getName()][$propertyName] = $expectedClassName;
     }
 }