_summary; } /** * @var string */ private $_summary = ""; /** * @var LuParameterDbo[] */ private $_params = []; /** * @var string */ private $_returnType = ""; /** * @return string */ public function getDoc() { return $this->_doc; } /** * @return \Luticate\Utils\Dbo\LuParameterDbo[] */ public function getParams() { return $this->_params; } /** * @return string */ public function getReturnType() { return $this->_returnType; } /** * LuDocParser constructor. * @param $doc string */ public function __construct($doc) { $this->_doc = $doc; } public function parse() { if (!is_string($this->_doc)) { return; } $lines = preg_split("/(\r?\n)/", $this->_doc); $count = count($lines); if ($count > 2) { array_splice($lines, 0, 1); array_splice($lines, $count - 2, 1); } $currentParam = null; foreach ($lines as $line) { $lineMatches = []; if (preg_match("/ *\\** *(.*) */", $line, $lineMatches) === 1) { $line = $lineMatches[1]; $commandMatches = []; if (preg_match("/@([^ ]+) *(.*)/", $line, $commandMatches)) { $command = strtolower($commandMatches[1]); $line = $commandMatches[2]; if ($command == "param") { $currentParam = new LuParameterDbo(); $paramMatches = []; if (preg_match("/([^ ]+) *([^ ]+) *(.*)/", $line, $paramMatches) === 1) { if ($paramMatches[1][0] == "$") { $currentParam->setName(substr($paramMatches[1], 1, strlen($paramMatches[1]) - 1)); $currentParam->setType($paramMatches[2]); } else { $currentParam->setName(substr($paramMatches[2], 1, strlen($paramMatches[2]) - 1)); $currentParam->setType($paramMatches[1]); } $currentParam->setSummary($paramMatches[3] . "\n"); } $this->_params[$currentParam->getName()] = $currentParam; } else if ($command == "deprecated") { } else if ($command == "inheritdoc") { } else if ($command == "internal") { } else if ($command == "link") { } else if ($command == "return") { $this->_returnType = $line; } else if ($command == "see") { } else if ($command == "throws") { } else if (!is_null($currentParam)) { $methodName = $command; if ($methodName == "nullable") { $currentParam->setNotNull(false); } else { $constraint = new LuParameterConstraintDbo(); $constraint->setMethod($methodName); $args = []; $argMatches = []; if (preg_match_all('/ *(-?(?:\d*\.\d+|\d+|true|false|null|"[^"]*"|\'[^\']*\'))/', $line, $argMatches) !== false) { $args = $argMatches[1]; foreach ($args as $key => $arg) { $argLower = strtolower($arg); if ($arg[0] == '"' || $arg[0] == "'") { $args[$key] = substr($arg, 1, count($arg) - 2); } else if ($argLower == "true") { $args[$key] = true; } else if ($argLower == "false") { $args[$key] = false; } else if ($argLower == "null") { $args[$key] = null; } else if (strpos($arg, ".") !== false) { $args[$key] = floatval($arg); } else { $args[$key] = intval($arg); } } } $constraint->setArguments($args); $currentParam->addConstraint($constraint); } } } else { if (is_null($currentParam)) { $this->_summary .= $line . "\n"; } else { $currentParam->setSummary($currentParam->getSummary() . $line . "\n"); } } } } } }