Beispiel #1
0
 /**
  * Parse Annotations in DocBlock
  *
  * @param string $docblock Full method docblock
  * @return JacksonAnnotation[]
  */
 protected function parseAnnotations($docblock)
 {
     $annotations = array();
     $docblock = substr($docblock, 3, -2);
     $regexAnnotationName = '/@([A-Za-z0-9_-]+)(.*)/';
     if (preg_match_all($regexAnnotationName, $docblock, $annotationNameMatches)) {
         //            echo "<pre>";
         //            print_r($annotationNameMatches);
         //            echo "</pre>";
         // Loop for each annotation
         foreach ($annotationNameMatches[2] as $key => $annotationParameters) {
             $annotationName = $annotationNameMatches[1][$key];
             $annotationParams = array();
             $annotationVars = array();
             //                echo $annotationNameMatches[0][$key]."<br>";
             // Parse in-parenthesis parameters and between space parameters
             $regexAnnotationParenthesisParameters = '/\\((.*)\\)(.*)/';
             if (preg_match($regexAnnotationParenthesisParameters, $annotationParameters, $annotationParenthesisParameters)) {
                 //                    echo "0<pre>";
                 //                    print_r($annotationParenthesisParameters);
                 //                    echo "</pre>";
                 // Split in-parenthesis parameters by ','
                 $annotationEqualParameters = preg_split('/\\s*,+\\s*/', $annotationParenthesisParameters[1], -1, PREG_SPLIT_NO_EMPTY);
                 //                    echo "1<pre>";
                 //                    print_r($annotationEqualParameters);
                 //                    echo "</pre>";
                 $regexEqualParameter = '/(.*?)\\s*\\=\\s*[\\"\']{1}(.*?)[\\"\']{1}/';
                 foreach ($annotationEqualParameters as $annotationEqualParameter) {
                     if (preg_match($regexEqualParameter, $annotationEqualParameter, $equalParameterMatch)) {
                         //                            echo "2<pre>";
                         //                            print_r($equalParameterMatch);
                         //                            echo "</pre>";
                         $annotationParams[$equalParameterMatch[1]] = $equalParameterMatch[2];
                     }
                 }
                 // Split remaining between-spaces vars
                 $annotationSpaceVars = preg_split('/\\s+/', $annotationParenthesisParameters[2], -1, PREG_SPLIT_NO_EMPTY);
                 $annotationVars[] = $annotationSpaceVars;
                 //                    echo "3a<pre>";
                 //                    print_r($annotationSpaceVars);
                 //                    echo "</pre>";
                 // There is no in-parenthesis parameters so only parse between space parameters
             } else {
                 $annotationSpaceVars = preg_split('/\\s+/', $annotationParameters, -1, PREG_SPLIT_NO_EMPTY);
                 $annotationVars[] = $annotationSpaceVars;
                 //                    echo "3b<pre>";
                 //                    print_r($annotationSpaceVars);
                 //                    echo "</pre>";
             }
             // instanciate the right jacksonphp annotation, if it does not exists we don't keep it !
             $annotation = JacksonAnnotation::getAnnotation($annotationName, $annotationParams, $annotationVars);
             if ($annotation != null) {
                 $annotations[$annotation->getName()] = $annotation;
             }
         }
     }
     //        echo "4<pre>";
     //        print_r($annotations);
     //        echo "</pre>";
     return $annotations;
 }