<?php 
/** 
 * API Generation for the framework 
 *  
 * @category  API 
 * @package   Generation 
 * @author    Will Tinsdeall <[email protected]> 
 * @copyright 2013 Mercian Labels 
 * @license   http://www.gnu.org/licenses/gpl.html GPL 3.0 
 * @link      http://www.mercianlabels.com 
 * @since     File available since Release 1.0.0 
 */ 
require_once "common.php"; 
 
 
 
 
 
$models = getModels(); 
 
foreach ($models as $table=>$model) { 
    if (strpos($table, "_") !== false) { 
        $class = implode("_",array_map(function($data) { 
            return ucfirst($data); 
        }, explode("_", $table))); 
    } else { 
        $class = ucfirst($table); 
    } 
     
    $modelName = getClassName($table); 
     
    $name = ucfirst($table); 
    echo "API: /api/$table\n"; 
    $file = <<<EOF 
<?php 
/** 
 * API Generation for the framework 
 *  
 * PHP version 5.4 
 *  
 * @category  API 
 * @package   Boiler 
 * @author    Will Tinsdeall <[email protected]> 
 * @copyright 2013 Mercian Labels 
 * @license   http://www.mercianlabels.com All Rights Reserved 
 * @link      http://www.mercianlabels.com 
 */ 
namespace System\Controller\Api; 
 
 
/** 
 * Autogenerated class for API access to the model \\Model\\$class 
 *  
 * PHP version 5.4 
 * 
 * @category API 
 * @package  Boiler 
 * @author   Will Tinsdeall <[email protected]> 
 * @license  All Rights Reserved 
 * @version  GIT: \$Id$ 
 * @link     http://www.mercianlabels.com 
 * 
 */ 
class {$class} extends \\Controller\\Api\\ModelController { 
 
    /** 
     * Parses the name of the model which this API endpoint represents to the ModelController 
     *  
     * @return string 
     */ 
    protected function getModelClass() { 
        return "\\Model\\{$modelName}"; 
    } 
} 
EOF; 
     
    $f = __DIR__."/../../framework/system/controller/api/{$class}.php"; 
    file_put_contents($f, $file); 
     
    $f = __DIR__."/../../framework/application/controller/api/{$class}.php"; 
    if (!file_exists($f)) { 
        $file = <<<EOF 
<?php 
/** 
 * API Generation for the framework 
 *  
 * PHP version 5.4 
 *  
 * @category  API 
 * @package   Boiler 
 * @author    Will Tinsdeall <[email protected]> 
 * @copyright 2013 Mercian Labels 
 * @license   http://www.mercianlabels.com All Rights Reserved 
 * @link      http://www.mercianlabels.com 
 */ 
namespace Controller\Api; 
 
/** 
 * Autogenerated stub for API access to the model \\Model\\$class 
 *  
 * PHP version 5.4 
 * 
 * @category API 
 * @package  Boiler 
 * @author   ivebeenlinuxed <[email protected]> 
 * @license  All Rights Reserved 
 * @version  GIT: \$Id$ 
 * @link     http://www.mercianlabels.com 
 * 
 */ 
class {$class} extends \\System\\Controller\\Api\\{$class} { 
} 
EOF; 
        file_put_contents($f, $file); 
    } 
     
}
 
 |