_doc = $doc; } /** * @return LuParameterDbo */ public function parse() { if (!is_string($this->_doc)) { return null; } $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 = new LuParameterDbo(); 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 == "var") { $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"); } } else { $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, strlen($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 { $currentParam->setSummary($currentParam->getSummary() . $line . "\n"); } } } return $currentParam; } }