1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* @see https://github.com/zendframework/zend-soap for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-soap/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Soap\Wsdl\DocumentationStrategy;
use ReflectionClass;
use ReflectionProperty;
final class ReflectionDocumentation implements DocumentationStrategyInterface
{
/**
* @return string
*/
public function getPropertyDocumentation(ReflectionProperty $property)
{
return $this->parseDocComment($property->getDocComment());
}
/**
* @return string
*/
public function getComplexTypeDocumentation(ReflectionClass $class)
{
return $this->parseDocComment($class->getDocComment());
}
/**
* @param string $docComment
* @return string
*/
private function parseDocComment($docComment)
{
$documentation = [];
foreach (explode("\n", $docComment) as $i => $line) {
if ($i == 0) {
continue;
}
$line = trim(preg_replace('/\s*\*+/', '', $line));
if (preg_match('/^(@[a-z]|\/)/i', $line)) {
break;
}
// only include newlines if we've already got documentation
if (! empty($documentation) || $line != '') {
$documentation[] = $line;
}
}
return join("\n", $documentation);
}
}