Пример #1
0
 public static function getQueryDataFormInstance($controllerClassName)
 {
     $finder = new Psr4FindFile(['app' => [Yii::getAlias('@app')]]);
     $staticReflectionParser = new StaticReflectionParser($controllerClassName, $finder);
     $useStatements = $staticReflectionParser->getUseStatements();
     if (isset($useStatements['querydataform']) && class_exists($useStatements['querydataform'])) {
         return new $useStatements['querydataform']();
     }
     return null;
 }
 public function testGetterSetter()
 {
     $Transformer = new CaseTransformer(new SnakeCase(), new StudlyCaps());
     $data = $this->getMockData();
     /** @var AbstractModel $Model */
     $Model = new $this->modelClass();
     $Model->exchangeArray(json_decode($data));
     $ModelReflection = new \ReflectionClass($this->modelClass);
     $ClassFinder = new ClassFinder('DockerCloud');
     $StaticReflectionParser = new StaticReflectionParser($this->modelClass, $ClassFinder);
     $useStatements = $StaticReflectionParser->getUseStatements();
     foreach ($ModelReflection->getProperties(\ReflectionProperty::IS_PROTECTED) as $ReflectionProperty) {
         // Parse @var tag
         $DockBlock = DocBlockFactory::createInstance()->create($ReflectionProperty->getDocComment());
         $this->assertTrue($DockBlock->hasTag('var'));
         /**
          * @var Var_ $VarTag
          */
         $VarTag = $DockBlock->getTagsByName('var')[0];
         $varTypes = explode('|', $VarTag->getType()->__toString());
         //echo $VarTag . PHP_EOL;
         $foundMatchVarTypeCount = 0;
         foreach ($varTypes as $varType) {
             // Get value by using getter method
             $getterMethodName = $Transformer->transform($ReflectionProperty->getName());
             if ('bool' == $varType || 'boolean' == $varType) {
                 $getterMethodName = 'is' . $getterMethodName;
             } else {
                 $getterMethodName = 'get' . $getterMethodName;
             }
             if (!method_exists($Model, $getterMethodName)) {
                 continue;
             }
             $value = $Model->{$getterMethodName}();
             if (strpos($varType, '[]') && is_array($value)) {
                 $value = array_pop($value);
             }
             // If there's no actual value we cannot really validate it...
             $varType = str_replace('[]', '', $varType);
             if (strpos($varType, '\\') === 0) {
                 $varType = substr($varType, 1);
             }
             $foundMatchVarType = $this->validateInternalType($varType, $value);
             if (is_null($foundMatchVarType)) {
                 $foundMatchVarType = $this->validateImportedType($varType, $value, $useStatements);
             }
             if ($foundMatchVarType) {
                 $foundMatchVarTypeCount++;
             }
         }
         self::assertTrue($foundMatchVarTypeCount > 0, sprintf("[%s] haven't getter method.", $ReflectionProperty->getName()));
     }
 }
 public function resolveRelativeName($shortClassName)
 {
     if ($this->useStatements === null) {
         $p = new StaticReflectionParser($this->className, new ReflectionClassFinder());
         $this->useStatements = $p->getUseStatements();
         $this->namespace = $p->getNamespaceName();
     }
     $matches = array();
     preg_match("/^[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*/", $shortClassName, $matches);
     $firstName = strtolower($matches[0]);
     if (isset($this->useStatements[$firstName])) {
         return $this->useStatements[$firstName] . substr($shortClassName, strlen($firstName));
     } else {
         return $this->namespace . "\\" . $shortClassName;
     }
 }
Пример #4
0
 public function getPropertyObjectClass($propertyName)
 {
     if (!in_array($this->getPropertyType($propertyName), [Swagger::DATA_TYPE_OBJECT, Swagger::DATA_TYPE_OBJECT_ARRAY])) {
         throw new Exception('The property type is not object');
     }
     $type = str_replace('[]', '', $this->_getPropertyType($propertyName));
     $finder = new Psr4FindFile(['app' => [Yii::getAlias('@app')]]);
     $staticReflectionParser = new StaticReflectionParser($this->className, $finder);
     $useStatements = $staticReflectionParser->getUseStatements();
     if (isset($useStatements[strtolower($type)])) {
         return $useStatements[strtolower($type)];
     }
     if (class_exists($className = $this->reflection->getNamespaceName() . '\\' . $type)) {
         return $className;
     }
     return null;
 }
Пример #5
0
 /**
  * @return array
  */
 public function getUseStatements()
 {
     return $this->staticReflectionParser->getUseStatements();
 }