00001 <?php
00023 class ModelBuilder implements BuilderInterface
00024 {
00033 public static function execute ($name, $params)
00034 {
00035 $path = APP_PATH . 'models/';
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 models $path");
00042 }
00043 }
00044 $model = Util::camelcase($name);
00045 $smodel = Util::smallcase($name);
00049 $__file__ = $path . "$smodel.php";
00053 if (! file_exists($__file__)) {
00054 extract($params);
00055 echo "\r\n-- Generando model: $model\r\n$__file__\r\n";
00056 ob_start();
00057 echo "<?php\n";
00058 include CORE_PATH . 'extensions/builder/base_builders/templates/model.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 model $__file__");
00063 }
00064 } else {
00065 echo "\r\n-- El model ya existe en $__file__\r\n";
00066 }
00067 return true;
00068 }
00069 }