00001 <?php 00023 class ControllerBuilder implements BuilderInterface 00024 { 00033 public static function execute ($name, $params) 00034 { 00035 $path = APP_PATH . 'controllers/'; 00036 if (isset($params['module']) && $params['module']) { 00037 $path .= "{$params['module']}/"; 00038 } 00039 if (! is_dir($path)) { 00040 if (! Util::mkpath($path)) { 00041 throw new KumbiaException("No se ha logrado generar la ruta para controllers $path"); 00042 } 00043 } 00044 $controller = Util::camelcase($name); 00045 $scontroller = Util::smallcase($name); 00049 $__file__ = $path . "{$scontroller}_controller.php"; 00053 if (! file_exists($__file__)) { 00054 extract($params); 00055 echo "\r\n-- Generando controller: $controller\r\n$__file__\r\n"; 00056 ob_start(); 00057 echo "<?php\n"; 00058 include CORE_PATH . 'extensions/builder/base_builders/templates/controller.php'; 00059 $code = ob_get_contents(); 00060 ob_end_clean(); 00061 if (! file_put_contents($__file__, $code)) { 00062 throw new KumbiaException("No se ha logrado generar el archivo de controller $__file__"); 00063 } 00064 $path = APP_PATH . 'views/'; 00065 if (isset($params['module']) && $params['module']) { 00066 $path .= "{$params['module']}/"; 00067 } 00068 $path .= $scontroller; 00069 if (! is_dir($path)) { 00070 echo "\r\n-- Generando directorio de vistas: \r\n$path\r\n"; 00071 if (! is_dir($path)) { 00072 if (! Util::mkpath($path)) { 00073 throw new KumbiaException("No se ha logrado generar la ruta para controllers $path"); 00074 } 00075 } 00076 } 00077 } else { 00078 echo "\r\n-- El controller ya existe en $__file__\r\n"; 00079 } 00080 return true; 00081 } 00082 }