private function createContentForTemplate($endpoints = array())
{
if (!$endpoints) {
return FALSE;
}
$navigation = '';
$body = '';
foreach ($endpoints as $endpoint_name => $array) {
$sectionName = $this->normalizeSectionName($endpoint_name);
$sectionItem = '';
$sectionHead = '';
$bodySection = '';
$navSections = '';
$navItems = '';
$navSections .= File::get(config::get('apidocs.navigation_template_path'));
$navSections = str_replace('{column-title}', $sectionName, $navSections);
$sectionHead .= File::get(config::get('apidocs.section_header_template_path'));
$sectionHead = str_replace('{column-name}', $sectionName, $sectionHead);
$sectionHead = str_replace('{main-description}', $endpoints[$endpoint_name]['description'], $sectionHead);
if (isset($array['methods'])) {
foreach ($array['methods'] as $key => $value) {
$endpoint = $value;
$uri = explode(' ', $endpoint['uri']);
$navItems .= File::get(config::get('apidocs.nav_items_template_path'));
$navItems = str_replace('{column-title}', $sectionName, $navItems);
$navItems = str_replace('{function}', $endpoint['function'], $navItems);
$sectionItem .= File::get(config::get('apidocs.body_content_template_path'));
$sectionItem = str_replace('{column-name}', $sectionName, $sectionItem);
$sectionItem = str_replace('{request-type}', $endpoint['method'], $sectionItem);
$sectionItem = str_replace('{endpoint-short-description}', $endpoint['docBlock']->getShortDescription(), $sectionItem);
$sectionItem = str_replace('{endpoint-long-description}', $endpoint['docBlock']->getLongDescription(), $sectionItem);
$sectionItem = str_replace('{function}', $endpoint['function'], $sectionItem);
$sectionItem = str_replace('{request-uri}', end($uri), $sectionItem);
$method_params = $endpoint['docBlock']->getTagsByName('param');
$controller_params = $endpoint['controllerDocBlock']->getTagsByName('param');
$params = array_merge($method_params, $controller_params);
$parameters = '';
foreach ($params as $param) {
$param_name = str_replace($param->getDescription(), '', $param->getContent());
$param_name = str_replace($param->getType(), '', $param_name);
$param_name = str_replace(' ', '', $param_name);
$param_name = urldecode($param_name);
if ($param_name[0] == '$') {
$param_name = str_replace('$', '', $param_name);
}
if ($param->getType() == 'array' && strpos($param_name, '[') == false) {
$param_name .= '[]';
}
$parameters .= File::get(config::get('apidocs.parameters_template_path'));
$parameters = str_replace('{param-name}', $param_name, $parameters);
$parameters = str_replace('{param-type}', $param->getType(), $parameters);
$parameters = str_replace('{param-desc}', $param->getDescription(), $parameters);
if (strpos(strtolower($param_name), 'password') !== false) {
$parameters = str_replace('type="text" class="parameter-value-text" name="' . $param_name . '"', 'type="password" class="parameter-value-text" name="' . $param_name . '"', $parameters);
}
}
if (strlen($parameters) > 0) {
$sectionItem = str_replace('{request-parameters}', $parameters, $sectionItem);
// insert the parameters into the section items
} else {
$sectionItem = str_replace('<h4>Parameters</h4>
<ul>
<li class="parameter-header">
<div class="parameter-name">PARAMETER</div>
<div class="parameter-type">TYPE</div>
<div class="parameter-desc">DESCRIPTION</div>
<div class="parameter-value">VALUE</div>
</li>
{request-parameters}
</ul>', '', $sectionItem);
}
}
$navSections = str_replace('{nav-items}', '<ul>' . $navItems . '</ul>', $navSections);
// add the navigation items to the nav section
} else {
$navSections = str_replace('{nav-items}', '', $navSections);
// add the navigation items to the nav section
}
$navigation .= $navSections;
$bodySection .= File::get(config::get('apidocs.compile_content_template_path'));
$bodySection = str_replace('{section-header}', $sectionHead, $bodySection);
$bodySection = str_replace('{section-details}', $sectionItem, $bodySection);
$body .= $bodySection;
}
$data = array('navigation' => $navigation, 'body-content' => $body);
return $data;
}