Beispiel #1
0
 /**
  * Put all the attributes into a bean
  */
 public static function xmlToBean($xmlContent, $class, $elements = null)
 {
     $returnArray = array();
     if (AnnotationUtils::hasAnnotation($class, 'TagAnnotation')) {
         $tagName = AnnotationUtils::getAnnotation($class, 'TagAnnotation')->tagName;
         //important thing: when has more than one tag with same name, we return an array:
         if ($elements == null) {
             $elements = $xmlContent->getElementsByTagName($tagName);
         } else {
             $elements = $elements->getElementsByTagName($tagName);
         }
         foreach ($elements as $element) {
             $instance = new $class();
             //getting the reflection`s field
             $attributes = JasperReflection::getVars($instance);
             $attritubeValue = null;
             foreach ($attributes as $attritubeName => $attritubeValue) {
                 //Getting the annotation`s field
                 if (AnnotationUtils::hasPropertyAnnotation($instance, 'BeanAnnotation', $attritubeName)) {
                     $className = AnnotationUtils::getPropertyAnnotation($instance, 'BeanAnnotation', $attritubeName)->className;
                     $instance->{$attritubeName} = self::xmlToBean($xmlContent, $className, $element);
                 } else {
                     //if the annotation field doesn`t exists, we get the normal XML and put into the bean
                     $val = self::nodeToBean($attritubeName, $element);
                     if (is_numeric($val) && $attritubeName != 'size') {
                         $instance->{$attritubeName} = PixelUtils::pixeltoMm($val);
                     } else {
                         $instance->{$attritubeName} = $val;
                     }
                 }
             }
             array_push($returnArray, $instance);
         }
     } else {
         throw new JasperReaderException("There isnt`t tag specified in the class: " . $class);
     }
     if (count($returnArray) > 1) {
         return $returnArray;
     } else {
         if (count($returnArray) == 0) {
             return null;
         }
         return $returnArray[0];
     }
 }
 public static function getPropertyAnnotation($class, $annotation, $property)
 {
     $className = Constant::$ANNOTATION_NAMESPACE . $annotation;
     $return = new $className();
     $attributes = JasperReflection::getVars($return);
     $reflectionClass = new \ReflectionProperty($class, $property);
     $comments = $reflectionClass->getDocComment();
     if (empty($comments)) {
         return false;
     }
     $comments = explode("\n", $comments);
     foreach ($comments as $comment) {
         $comment = trim($comment);
         $matches = array();
         if (preg_match('/(?<=@)[a-zA-Z0-9]+/', $comment, $matches)) {
             if (is_numeric(array_search($annotation, $matches))) {
                 if (preg_match_all('/(?<=[(\\()|(,\\s)])[a-zA-Z0-9]+/', $comment, $tagMatches)) {
                     $attributeValue = null;
                     foreach ($attributes as $attributeName => $attributeValue) {
                         $index = array_search($attributeName, $tagMatches[0]);
                         //if the attribute class exists in comments
                         if (is_numeric($index)) {
                             if (preg_match('/(?<=' . $attributeName . '=")[\\w\\\\]+/', $comment, $valuesMatches)) {
                                 $return->{$attributeName} = $valuesMatches[0];
                             }
                         }
                     }
                 }
             } else {
                 throw new JasperReaderException("This annotation doesn't exists");
             }
         } else {
             throw new JasperReaderException("This class doesn't have annotations");
         }
     }
     return $return;
 }
Beispiel #3
0
 private function getConfig($configName)
 {
     if ($this->config) {
         if (array_key_exists($configName, $this->config)) {
             foreach ($this->config as $attributeName => $attributeValue) {
                 if ($attributeName == $configName) {
                     return $attributeValue;
                 }
             }
         } else {
             $attributes = JasperReflection::getVars("Constant");
             foreach ($attributes as $attributeName => $attributeValue) {
                 if ($attributeName == $configName) {
                     return $attributeValue;
                 }
             }
         }
     }
     return null;
 }