PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Mike Stowe   PHP RAML to HTML   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Application script
Class: PHP RAML to HTML
Parse RAML of an API to generate documentation
Author: By
Last change:
Date: 10 years ago
Size: 1,577 bytes
 

Contents

Class file image Download
<?php
/**
  * RAML2HTML for PHP -- A Simple API Docs Script for RAML & PHP
  * @version 1.1beta
  * @author Mike Stowe <me@mikestowe.com>
  * @link https://github.com/mikestowe/php-raml2html
  * @link http://www.mikestowe.com/2014/05/raml-2-html.php
  * @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2
  */

require_once('inc/spyc.php');
require_once(
'inc/ramlDataObject.php');
require_once(
'inc/raml.php');
require_once(
'inc/ramlPathObject.php');
require_once(
'config.php');


// Dangling Function
function formatResponse($text) {
    return
str_replace(array(" ", "\n"), array("&nbsp;", "<br />"), htmlentities($text));
}


// Handle Caching and Build
$RAML = false;
if (
$cacheTimeLimit && function_exists('apc_fetch')) {
   
$RAML = apc_fetch('RAML' . md5($RAMLsource));
} elseif (!
$cacheTimeLimit && function_exists('apc_fetch')) {
   
// Remove existing cache files
   
apc_delete('RAML' . md5($RAMLsource));
}

if (!
$RAML) {
   
$RAMLarray = spyc_load(file_get_contents($RAMLsource));
   
$RAML = new RAML2HTML\RAML($RAMLactionVerbs);

   
$RAML->setIncludePath(dirname($RAMLsource) . '/');
   
$RAML->buildFromArray($RAMLarray);
   
    if (
$cacheTimeLimit && function_exists('apc_store')) {
       
apc_store('RAML' . md5($RAMLsource), $RAML, $cacheTimeLimit);
    }
}


// Set Current Path
if (isset($_GET['path'])) {
   
$RAML->setCurrentPath($_GET['path']);
    unset(
$_GET['path']);
}


// Set Current Action
if (isset($_GET['action']) && $RAML->isActionValid($_GET['action'])) {
   
$RAML->setCurrentAction($_GET['action']);
    unset(
$_GET['action']);
}

// Render Template
require_once($docsTheme);

?>