Esempio n. 1
0
 public static function createReflection(ReflectionMethod $reflection)
 {
     $comment = $reflection->getDocComment();
     $result = new MethodServiceReflection($reflection->getName(), '', self::getDescriptionBlock($comment));
     $commentLines = self::prepareDocComment($comment);
     $tmpParams = array();
     $return = new ReturnServiceReflection('void', '');
     $params = $reflection->getParameters();
     foreach ($params as $param) {
         $name = $param->getName();
         $tmpParams[$name] = new ParameterServiceReflection($name, 'mixed');
         /* QUICKFIX: for Bug#62715 in PHP 5.3.16
          * @link https://bugs.php.net/bug.php?id=62715
          * Fatal error: Uncaught exception 'ReflectionException' with message 'Parameter is not optional'
          */
         if (version_compare(str_replace(PHP_EXTRA_VERSION, '', PHP_VERSION), '5.3.16', 'eq')) {
             continue;
         }
         if ($param->isDefaultValueAvailable()) {
             $tmpParams[$name]->setHasDefault(true);
             $tmpParams[$name]->setRequired(false);
             $tmpParams[$name]->setDefault($param->getDefaultValue(), false);
         }
     }
     foreach ($commentLines as $line) {
         if ($line == '') {
             continue;
         }
         if ($line[0] != '@') {
             continue;
         }
         if (preg_match('/^@param\\s+([\\w\\[\\]()]+)\\s+\\$([\\w()]+)\\s*(.*)/i', $line, $match)) {
             $type = $match[1];
             $name = $match[2];
             $desc = $match[3];
             $param = new ParameterServiceReflection($name, $type, $desc);
             if (preg_match('/\\(default=(.*)\\)/i', $desc, $regs)) {
                 $param->setHasDefault(true);
                 $param->setRequired(false);
                 $default = $regs[1];
                 if ($default == "''") {
                     $param->setDefault('', false);
                 } elseif ($default[0] == "'") {
                     $default = substr($default, 1, strlen($default) - 2);
                     $param->setDefault($default);
                 } else {
                     $param->setDefault($default);
                 }
                 $desc = preg_replace('/' . preg_quote('(default=' . $regs[1] . ')', '/') . '/i', '', $desc);
                 $param->setDescription($desc);
             }
             $tmpParams[$name] = $param;
         }
         if (preg_match('/^@return\\s+([\\w\\[\\]()]+)\\s*(.*)/i', $line, $match)) {
             $return->setType($match[1]);
             $return->setDescription($match[2]);
         }
         if (preg_match('/^@result\\s+([\\w\\[\\]()]+)\\s+\\$([\\w()]+)\\s*(.*)/i', $line, $match)) {
             $name = $match[2];
             $type = $match[1];
             $desc = $match[3];
             if (preg_match('/\\(default=(.*)\\)/i', $desc, $regs)) {
                 $resultParam = new ParameterServiceReflection($name, $type, $desc);
                 $resultParam->setHasDefault(true);
                 $resultParam->setRequired(false);
                 $default = $regs[1];
                 if ($default == "''") {
                     $resultParam->setDefault('', false);
                 } elseif ($default[0] == "'") {
                     $default = substr($default, 1, strlen($default) - 2);
                     $resultParam->setDefault($default);
                 } else {
                     $resultParam->setDefault($default);
                 }
                 $desc = preg_replace('/' . preg_quote('(default=' . $regs[1] . ')', '/') . '/i', '', $desc);
                 $resultParam->setDescription($desc);
                 $return->addResult($resultParam);
             } else {
                 $return->addResult(new NamedServiceReflectionBase($name, $type, $desc));
             }
         }
     }
     $result->setParameters($tmpParams);
     $result->setReturn($return);
     return $result;
 }
 public static function createReflection(ReflectionMethod $reflection)
 {
     $comment = $reflection->getDocComment();
     $result = new MethodServiceReflection($reflection->getName(), '', self::getDescriptionBlock($comment));
     $commentLines = self::prepareDocComment($comment);
     $tmpParams = array();
     $return = new ReturnServiceReflection('void', '');
     $params = $reflection->getParameters();
     foreach ($params as $param) {
         $name = $param->getName();
         $tmpParams[$name] = new ParameterServiceReflection($name, 'mixed');
         if ($param->isDefaultValueAvailable()) {
             $tmpParams[$name]->setHasDefault(true);
             $tmpParams[$name]->setRequired(false);
             $tmpParams[$name]->setDefault($param->getDefaultValue(), false);
         }
     }
     foreach ($commentLines as $line) {
         if ($line == '') {
             continue;
         }
         if ($line[0] != '@') {
             continue;
         }
         if (preg_match('/^@param\\s+([\\w\\[\\]()]+)\\s+\\$([\\w()]+)\\s*(.*)/i', $line, $match)) {
             $type = $match[1];
             $name = $match[2];
             $desc = $match[3];
             $param = new ParameterServiceReflection($name, $type, $desc);
             if (preg_match('/\\(default=(.*)\\)/i', $desc, $regs)) {
                 $param->setHasDefault(true);
                 $param->setRequired(false);
                 $default = $regs[1];
                 if ($default == "''") {
                     $param->setDefault('', false);
                 } elseif ($default[0] == "'") {
                     $default = substr($default, 1, strlen($default) - 2);
                     $param->setDefault($default);
                 } else {
                     $param->setDefault($default);
                 }
                 $desc = preg_replace('/' . preg_quote('(default=' . $regs[1] . ')', '/') . '/i', '', $desc);
                 $param->setDescription($desc);
             }
             $tmpParams[$name] = $param;
         }
         if (preg_match('/^@return\\s+([\\w\\[\\]()]+)\\s*(.*)/i', $line, $match)) {
             $return->setType($match[1]);
             $return->setDescription($match[2]);
         }
         if (preg_match('/^@result\\s+([\\w\\[\\]()]+)\\s+\\$([\\w()]+)\\s*(.*)/i', $line, $match)) {
             $name = $match[2];
             $type = $match[1];
             $desc = $match[3];
             if (preg_match('/\\(default=(.*)\\)/i', $desc, $regs)) {
                 $resultParam = new ParameterServiceReflection($name, $type, $desc);
                 $resultParam->setHasDefault(true);
                 $resultParam->setRequired(false);
                 $default = $regs[1];
                 if ($default == "''") {
                     $resultParam->setDefault('', false);
                 } elseif ($default[0] == "'") {
                     $default = substr($default, 1, strlen($default) - 2);
                     $resultParam->setDefault($default);
                 } else {
                     $resultParam->setDefault($default);
                 }
                 $desc = preg_replace('/' . preg_quote('(default=' . $regs[1] . ')', '/') . '/i', '', $desc);
                 $resultParam->setDescription($desc);
                 $return->addResult($resultParam);
             } else {
                 $return->addResult(new NamedServiceReflectionBase($name, $type, $desc));
             }
         }
     }
     $result->setParameters($tmpParams);
     $result->setReturn($return);
     return $result;
 }