/** * Generate a class trailer for stored routine wrapper. */ private function writeClassTrailer() { $this->codeStore->appendSeparator(); $this->codeStore->append('}'); $this->codeStore->append(''); $this->codeStore->appendSeparator(); }
/** * Generate php doc block in the data layer for stored routine. * * @param array $routine Metadata of the stored routine. */ private function generatePhpDoc($routine) { $this->codeStore->append('/**', false); // Generate phpdoc with short description of routine wrapper. if ($routine['phpdoc']['sort_description']) { $this->codeStore->append(' * ' . $routine['phpdoc']['sort_description'], false); } // Generate phpdoc with long description of routine wrapper. if ($routine['phpdoc']['long_description']) { $this->codeStore->append(' * ' . $routine['phpdoc']['long_description'], false); } // Generate phpDoc with parameters and descriptions of parameters. if (!empty($routine['phpdoc']['parameters'])) { $this->codeStore->append(' *', false); // Compute the max lengths of parameter names and the PHP types of the parameters. $max_name_length = 0; $max_type_length = 0; foreach ($routine['phpdoc']['parameters'] as $parameter) { $mangledName = $this->nameMangler->getParameterName($parameter['parameter_name']); $max_name_length = max($max_name_length, strlen($mangledName)); $max_type_length = max($max_type_length, strlen($parameter['php_type'])); } // Add 1 character for $. $max_name_length++; // Generate phpDoc for the parameters of the wrapper method. foreach ($routine['phpdoc']['parameters'] as $parameter) { $mangledName = $this->nameMangler->getParameterName($parameter['parameter_name']); $format = sprintf(' * %%-%ds %%-%ds %%-%ds %%s', strlen('@param'), $max_type_length, $max_name_length); $lines = explode("\n", $parameter['description']); if (!empty($lines)) { $line = array_shift($lines); $this->codeStore->append(sprintf($format, '@param', $parameter['php_type'], '$' . $mangledName, $line), false); foreach ($lines as $line) { $this->codeStore->append(sprintf($format, ' ', ' ', ' ', $line), false); } } else { $this->codeStore->append(sprintf($format, '@param', $parameter['php_type'], '$' . $mangledName, ''), false); } $this->codeStore->append(sprintf($format, ' ', ' ', ' ', $parameter['data_type_descriptor']), false); } } elseif ($routine['designation'] === 'bulk_insert') { // Generate parameter for bulk_insert routine type. $this->codeStore->append(' *', false); $this->codeStore->append(' * @param array $rows', false); } // Generate return parameter doc. $return = $this->getDocBlockReturnType(); if ($return) { $this->codeStore->append(' *', false); $this->codeStore->append(' * @return ' . $return, false); } // Generate exceptions doc. $exceptions = $this->getDocBlockExceptions(); if (!empty($exceptions)) { $exceptions = array_unique($exceptions); foreach ($exceptions as $exception) { $this->codeStore->append(' * @throws ' . $exception, false); } } $this->codeStore->append(' */', false); }