Пример #1
0
 /**
  * Maneja las excepciones no capturadas
  *
  * @param Exception $e
  * */
 public static function handleException($e)
 {
     self::setHeader($e);
     //TODO quitar el extract, que el view pida los que necesite
     extract(Router::get(), EXTR_OVERWRITE);
     // Registra la autocarga de helpers
     spl_autoload_register('kumbia_autoload_helper', true, true);
     $Controller = Util::camelcase($controller);
     ob_start();
     if (PRODUCTION) {
         //TODO: añadir error 500.phtml
         include APP_PATH . 'views/_shared/errors/404.phtml';
         return;
     }
     if ($e instanceof KumbiaException) {
         $view = $e->view;
         $tpl = $e->template;
     } else {
         $view = 'exception';
         $tpl = 'views/templates/exception.phtml';
     }
     //Fix problem with action name in REST
     $action = $e->getMessage() ? $e->getMessage() : $action;
     include CORE_PATH . "views/errors/{$view}.phtml";
     $content = ob_get_clean();
     // termina los buffers abiertos
     while (ob_get_level()) {
         ob_end_clean();
     }
     include CORE_PATH . $tpl;
 }
Пример #2
0
 /**
  * Maneja las excepciones no capturadas
  *
  * @param Exception $e
  * */
 public static function handle_exception($e)
 {
     if (isset($e->_view) && ($e->_view == 'no_controller' || $e->_view == 'no_action')) {
         header('HTTP/1.1 404 Not Found');
     } else {
         header('HTTP/1.1 500 Internal Server Error');
     }
     extract(Router::get(), EXTR_OVERWRITE);
     $Controller = Util::camelcase($controller);
     ob_start();
     if (PRODUCTION) {
         include APP_PATH . 'views/_shared/errors/404.phtml';
         return;
     } else {
         $Template = 'views/templates/exception.phtml';
         if (isset($e->_view)) {
             include CORE_PATH . "views/errors/{$e->_view}.phtml";
         } else {
             include CORE_PATH . "views/errors/exception.phtml";
         }
     }
     $content = ob_get_clean();
     // termina los buffers abiertos
     while (ob_get_level()) {
         ob_end_clean();
     }
     // verifica si esta cargado el View
     if (class_exists('View')) {
         if (View::get('template') === NULL) {
             echo $content;
             exit;
         }
     }
     include CORE_PATH . $Template;
 }
Пример #3
0
 /**
  * Ejecuta el builder
  *
  * @param string $name elemento a construir
  * @param array $params
  * @return boolean
  * @throw BuilderException
  */
 public static function execute($name, $params)
 {
     $filter = Util::camelcase($name);
     $sfilter = Util::smallcase($name);
     /**
      * Nombre de archivo
      **/
     $__file__ = APP_PATH . 'filters/' . "{$sfilter}_filter.php";
     /**
      * Generando archivo
      **/
     if (!file_exists($__file__)) {
         extract($params);
         echo "\r\n-- Generando filter: {$filter}\r\n{$__file__}\r\n";
         ob_start();
         echo "<?php\n";
         include CORE_PATH . 'libs/builder/base_builders/templates/filter.php';
         $code = ob_get_contents();
         ob_end_clean();
         if (!file_put_contents($__file__, $code)) {
             throw new KumbiaException("No se ha logrado generar el archivo de filter {$__file__}");
         }
     } else {
         echo "\r\n-- El filter ya existe en {$__file__}\r\n";
     }
     return true;
 }
Пример #4
0
 /**
  * Comando de consola para crear un modelo
  *
  * @param array $params parametros nombrados de la consola
  * @param string $model modelo
  * @throw KumbiaException
  */
 public function create($params, $model)
 {
     // nombre de archivo
     $file = APP_PATH . 'models';
     // obtiene el path
     $path = explode('/', trim($model, '/'));
     // obtiene el nombre de modelo
     $model_name = array_pop($path);
     if (count($path)) {
         $dir = implode('/', $path);
         $file .= "/{$dir}";
         if (!is_dir($file) && !FileUtil::mkdir($file)) {
             throw new KumbiaException("No se ha logrado crear el directorio \"{$file}\"");
         }
     }
     $file .= "/{$model_name}.php";
     // si no existe o se sobreescribe
     if (!is_file($file) || Console::input("El modelo existe, �desea sobrescribirlo? (s/n): ", array('s', 'n')) == 's') {
         // nombre de clase
         $class = Util::camelcase($model_name);
         // codigo de modelo
         ob_start();
         include CORE_PATH . 'console/generators/model.php';
         $code = '<?php' . PHP_EOL . ob_get_clean();
         // genera el archivo
         if (file_put_contents($file, $code)) {
             echo "-> Creado modelo {$model_name} en: {$file}" . PHP_EOL;
         } else {
             throw new KumbiaException("No se ha logrado crear el archivo \"{$file}\"");
         }
     }
 }
Пример #5
0
 /**
  * Ejecuta el destroyer
  *
  * @param string $name elemento a destruir
  * @param array $params
  * @return boolean
  * @throw KumbiaException
  */
 public static function execute($name, $params)
 {
     $path = APP_PATH . 'controllers/';
     if (isset($params['module']) && $params['module']) {
         $path .= "{$params['module']}/";
     }
     $controller = Util::camelcase($name);
     $scontroller = Util::smallcase($name);
     /**
      * Nombre de archivo
      **/
     $file = $path . "{$scontroller}_controller.php";
     echo "\r\n-- Eliminando controller: {$controller}\r\n{$file}\r\n";
     if (!unlink($file)) {
         throw new KumbiaException("No se ha logrado eliminar el archivo {$file}");
     }
     $path = APP_PATH . 'views/';
     if (isset($params['module']) && $params['module']) {
         $path .= "{$params['module']}/";
     }
     $path .= Util::smallcase($name) . '/';
     echo "\r\n-- Eliminando directorio:\r\n{$path}\r\n";
     if (!Util::removeDir($path)) {
         throw new KumbiaException("No se ha logrado eliminar el directorio {$path}");
     }
     return true;
 }
Пример #6
0
 /**
  * Ejecuta un destroyer
  *
  * @param string $destroyer nombre del destroyer (destructor) a ejecutar
  * @param string $name elemento a eliminar
  * @param array $params array de parametros para el destructor
  * @return boolean
  */
 public static function destroy($destroyer, $name = null, $params = array())
 {
     $success = false;
     $destroyer_class = Util::camelcase($destroyer) . 'Destroyer';
     if (class_exists($destroyer_class)) {
         $success = call_user_func(array($destroyer_class, 'execute'), $name, $params);
     } else {
         throw new KumbiaException("No se ha encontrado la clase {$destroyer_class} necesaria para el destroyer");
     }
     return $success;
 }
Пример #7
0
 /**
  * Obtiene la instancia de un modelo
  *
  * @param string $model
  * @return obj model
  */
 public static function model($model)
 {
     //Nombre de la clase
     $Model = Util::camelcase(basename($model));
     //Carga la clase
     if (!class_exists($Model, FALSE)) {
         //Carga la clase
         if (!(include APP_PATH . "models/{$model}.php")) {
             throw new KumbiaException("No existe el modelo {$model}");
         }
     }
     return new $Model();
 }
Пример #8
0
 /**
  * Obtiene la instancia de un modelo
  *
  * @param string $model modelo a instanciar
  * @param mixed $params parámetros para instanciar el modelo
  * @return obj model
  */
 public static function model($model, $params = NULL)
 {
     //Nombre de la clase
     $Model = Util::camelcase(basename($model));
     //Carga la clase
     if (!class_exists($Model, FALSE)) {
         //Carga la clase
         if (!(include_once APP_PATH . "models/{$model}.php")) {
             throw new KumbiaException($model, 'no_model');
         }
     }
     return new $Model($params);
 }
 /**
  * Realiza el dispatch de una ruta
  *
  * @return Object
  */
 public static function execute($route)
 {
     extract($route, EXTR_OVERWRITE);
     if (!(include_once APP_PATH . "controllers/{$controller_path}" . '_controller.php')) {
         throw new KumbiaException(NULL, 'no_controller');
     }
     //Asigna el controlador activo
     $app_controller = Util::camelcase($controller) . 'Controller';
     $cont = self::$_controller = new $app_controller($module, $controller, $action, $parameters);
     View::select($action);
     View::setPath($controller_path);
     // Se ejecutan los filtros before
     if ($cont->k_callback('initialize') === FALSE) {
         return $cont;
     }
     if ($cont->k_callback('before_filter') === FALSE) {
         return $cont;
     }
     //Se ejecuta el metodo con el nombre de la accion
     //en la clase de acuerdo al convenio
     if (!method_exists($cont, $action)) {
         throw new KumbiaException(NULL, 'no_action');
     }
     //Obteniendo el metodo
     $reflectionMethod = new ReflectionMethod($cont, $action);
     //k_callback y __constructor metodo reservado
     if ($reflectionMethod->name == 'k_callback' || $reflectionMethod->isConstructor()) {
         throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
     }
     //se verifica que el metodo sea public
     if (!$reflectionMethod->isPublic()) {
         throw new KumbiaException(NULL, 'no_action');
     }
     //se verifica que los parametros que recibe
     //la action sea la cantidad correcta
     $num_params = count($parameters);
     if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() || $num_params > $reflectionMethod->getNumberOfParameters())) {
         throw new KumbiaException("Número de parámetros erroneo para ejecutar la acción \"{$action}\" en el controlador \"{$controller}\"");
     }
     $reflectionMethod->invokeArgs($cont, $parameters);
     //Corre los filtros after
     $cont->k_callback('after_filter');
     $cont->k_callback('finalize');
     //Si esta routed volver a ejecutar
     if (Router::getRouted()) {
         Router::setRouted(FALSE);
         return Dispatcher::execute(Router::get());
         // Vuelve a ejecutar el dispatcher
     }
     return $cont;
 }
Пример #10
0
 /**
  * Ejecuta el destroyer
  *
  * @param string $name elemento a destruir
  * @param array $params
  * @return boolean
  * @throw KumbiaException
  */
 public static function execute($name, $params)
 {
     $filter = Util::camelcase($name);
     $sfilter = Util::smallcase($name);
     /**
      * Nombre de archivo
      **/
     $file = APP_PATH . "filters/{$sfilter}_filter.php";
     echo "\r\n-- Eliminando filter: {$filter}\r\n{$file}\r\n";
     if (!unlink($file)) {
         throw new KumbiaException("No se ha logrado eliminar el archivo {$file}");
     }
     return true;
 }
Пример #11
0
 /**
  * Ejecuta el builder
  *
  * @param string $name elemento a construir
  * @param array $params
  * @return boolean
  * @throw BuilderException
  */
 public static function execute($name, $params)
 {
     $path = APP_PATH . 'controllers/';
     if (isset($params['module']) && $params['module']) {
         $path .= "{$params['module']}/";
     }
     if (!is_dir($path)) {
         if (!Util::mkpath($path)) {
             throw new KumbiaException("No se ha logrado generar la ruta para controllers {$path}");
         }
     }
     $controller = Util::camelcase($name);
     $scontroller = Util::smallcase($name);
     /**
      * Nombre de archivo
      **/
     $__file__ = $path . "{$scontroller}_controller.php";
     /**
      * Generando archivo
      **/
     if (!file_exists($__file__)) {
         extract($params);
         echo "\r\n-- Generando controller: {$controller}\r\n{$__file__}\r\n";
         ob_start();
         echo "<?php\n";
         include CORE_PATH . 'libs/builder/base_builders/templates/controller.php';
         $code = ob_get_contents();
         ob_end_clean();
         if (!file_put_contents($__file__, $code)) {
             throw new KumbiaException("No se ha logrado generar el archivo de controller {$__file__}");
         }
         $path = APP_PATH . 'views/';
         if (isset($params['module']) && $params['module']) {
             $path .= "{$params['module']}/";
         }
         $path .= $scontroller;
         if (!is_dir($path)) {
             echo "\r\n-- Generando directorio de vistas: \r\n{$path}\r\n";
             if (!is_dir($path)) {
                 if (!Util::mkpath($path)) {
                     throw new KumbiaException("No se ha logrado generar la ruta para controllers {$path}");
                 }
             }
         }
     } else {
         echo "\r\n-- El controller ya existe en {$__file__}\r\n";
     }
     return true;
 }
Пример #12
0
 /**
  * Comando de consola para crear un controlador
  *
  * @param array $params parametros nombrados de la consola
  * @param string $controller controlador
  * @throw KumbiaException
  */
 public function create($params, $controller)
 {
     // nombre de archivo
     $file = APP_PATH . 'controllers';
     // limpia el path de controller
     $clean_path = trim($controller, '/');
     // obtiene el path
     $path = explode('/', $clean_path);
     // obtiene el nombre de controlador
     $controller_name = array_pop($path);
     // si se agrupa el controlador en un directorio
     if (count($path)) {
         $dir = implode('/', $path);
         $file .= "/{$dir}";
         if (!is_dir($file) && !FileUtil::mkdir($file)) {
             throw new KumbiaException("No se ha logrado crear el directorio \"{$file}\"");
         }
     }
     $file .= "/{$controller_name}_controller.php";
     // si no existe o se sobreescribe
     if (!is_file($file) || Console::input("El controlador existe, ¿desea sobrescribirlo? (s/n): ", array('s', 'n')) == 's') {
         // nombre de clase
         $class = Util::camelcase($controller_name);
         // codigo de controlador
         ob_start();
         include __DIR__ . '/generators/controller.php';
         $code = '<?php' . PHP_EOL . ob_get_clean();
         // genera el archivo
         if (file_put_contents($file, $code)) {
             echo "-> Creado controlador {$controller_name} en: {$file}" . PHP_EOL;
         } else {
             throw new KumbiaException("No se ha logrado crear el archivo \"{$file}\"");
         }
         // directorio para vistas
         $views_dir = APP_PATH . "views/{$clean_path}";
         //si el directorio no existe
         if (!is_dir($views_dir)) {
             if (FileUtil::mkdir($views_dir)) {
                 echo "-> Creado directorio para vistas: {$views_dir}" . PHP_EOL;
             } else {
                 throw new KumbiaException("No se ha logrado crear el directorio \"{$views_dir}\"");
             }
         }
     }
 }
Пример #13
0
 /**
  * Ejecuta el destroyer
  *
  * @param string $name elemento a destruir
  * @param array $params
  * @return boolean
  * @throw KumbiaException
  */
 public static function execute($name, $params)
 {
     $path = APP_PATH . 'models/';
     if (isset($params['module']) && $params['module']) {
         $path .= "{$params['module']}/";
     }
     $model = Util::camelcase($name);
     $smodel = Util::smallcase($name);
     /**
      * Nombre de archivo
      **/
     $file = $path . "{$smodel}.php";
     echo "\r\n-- Eliminando model: {$model}\r\n{$file}\r\n";
     if (!unlink($file)) {
         throw new KumbiaException("No se ha logrado eliminar el archivo {$file}");
     }
     return true;
 }
 /**
  * Edita un Registro
  */
 public function editar($id = null)
 {
     if ($id != null) {
         View::select('crear');
         $model = Util::camelcase($this->model);
         //se verifica si se ha enviado via POST los datos
         if (Input::hasPost($this->model)) {
             $obj = Load::model($this->model);
             if (!$obj->update(Input::post($this->model))) {
                 Flash::error('Falló Operación');
                 //se hacen persistente los datos en el formulario
                 $this->result = Input::post($this->model);
             } else {
                 return Router::redirect("{$this->controller_path}");
             }
         }
         //Aplicando la autocarga de objeto, para comenzar la edición
         $this->result = Load::model($this->model)->find($id);
     } else {
     }
 }
Пример #15
0
 /**
  * Aplica filtro de manera estatica
  *
  * @param mixed $s variable a filtrar
  * @param string $filter filtro
  * @param array $options
  * @return mixed
  */
 public static function get($s, $filter, $options = array())
 {
     if (is_string($options)) {
         $filters = func_get_args();
         unset($filters[0]);
         $options = array();
         foreach ($filters as $f) {
             $filter_class = Util::camelcase($f) . 'Filter';
             if (!class_exists($filter_class, false)) {
                 self::_load_filter($f);
             }
             $s = call_user_func(array($filter_class, 'execute'), $s, $options);
         }
     } else {
         $filter_class = Util::camelcase($filter) . 'Filter';
         if (!class_exists($filter_class, false)) {
             self::_load_filter($filter);
         }
         $s = call_user_func(array($filter_class, 'execute'), $s, $options);
     }
     return $s;
 }
Пример #16
0
 /**
  * Maneja las excepciones no capturadas
  *
  * @param Exception $e
  **/
 public static function handle_exception($e)
 {
     if (isset($e->_view) && ($e->_view == 'no_controller' || $e->_view == 'no_action')) {
         header('HTTP/1.1 404 Not Found');
     } else {
         header('HTTP/1.1 500 Internal Server Error');
     }
     extract(Router::get(), EXTR_OVERWRITE);
     $Controller = Util::camelcase($controller);
     ob_start();
     if (!PRODUCTION) {
         $Template = 'views/templates/exception.phtml';
         $boot = Config::read('boot');
         if (isset($e->_view)) {
             include CORE_PATH . "views/errors/{$e->_view}.phtml";
         } else {
             include CORE_PATH . "views/errors/exception.phtml";
         }
     } else {
         include APP_PATH . 'views/errors/404.phtml';
         $Template = 'views/templates/error.phtml';
     }
     $content = ob_get_clean();
     // termina los buffers abiertos
     while (ob_get_level()) {
         ob_end_clean();
     }
     // verifica si esta cargado el dispatcher
     if (class_exists('Dispatcher')) {
         $controller = Dispatcher::get_controller();
         if ($controller && $controller->response == 'view') {
             echo $content;
             exit;
         }
     }
     include CORE_PATH . $Template;
 }
Пример #17
0
 /**
  * Crea una instancia de la consola indicada
  *
  * @param string $console_name nombre de la consola
  * return object
  * @throw KumbiaException
  **/
 public static function load($console_name)
 {
     // nombre de la clase de consola
     $Console = Util::camelcase($console_name) . 'Console';
     if (!class_exists($Console)) {
         // intenta carga el archivo de consola
         $file = APP_PATH . "extensions/console/{$console_name}_console.php";
         if (!is_file($file)) {
             $file = CORE_PATH . "console/{$console_name}_console.php";
             if (!is_file($file)) {
                 throw new KumbiaException('Consola "' . $file . '" no se encontro');
             }
         }
         // incluye la consola
         include_once $file;
     }
     // crea la instancia de objeto
     $console = new $Console();
     // inicializa la consola
     if (method_exists($console, 'initialize')) {
         $console->initialize();
     }
     return $console;
 }
Пример #18
0
 /**
  * Paginador por sql
  *	
  * @param string $model nombre del modelo
  * @param string $sql consulta sql
  *
  * page: numero de pagina a mostrar (por defecto la pagina 1)
  * per_page: cantidad de elementos por pagina (por defecto 10 items por pagina)
  *			
  *	
  * Retorna un PageObject que tiene los siguientes atributos:
  *  next: numero de pagina siguiente, si no hay pagina siguiente entonces es false
  *  prev: numero de pagina anterior, si no hay pagina anterior entonces es false
  *  current: numero de pagina actual
  *  total: total de paginas que se pueden mostrar
  *  items: array de items de la pagina
  *  count: Total de registros
  *
  * Ejemplos:
  *  $page = paginate_by_sql('usuario', 'SELECT * FROM usuario' , 'per_page: 5', "page: $page_num");
  *	
  * @return object
  **/
 public static function paginate_by_sql($model, $sql)
 {
     $params = Util::getParams(func_get_args());
     $page_number = isset($params['page']) ? $params['page'] : 1;
     $per_page = isset($params['per_page']) ? $params['per_page'] : 10;
     $start = $per_page * ($page_number - 1);
     /**
      * Si es una cadena, instancio el modelo
      **/
     if (is_string($params[0])) {
         $m = Util::camelcase($params[0]);
         $model = ActiveRecord::get($m);
     }
     /**
      * Instancia del objeto contenedor de pagina
      **/
     $page = new stdClass();
     /**
      * Cuento las apariciones atraves de una tabla derivada
      **/
     $n = $model->count_by_sql("SELECT COUNT(*) FROM ({$sql}) AS t");
     $page->items = $model->find_all_by_sql($model->limit($sql, "offset: {$start}", "limit: {$per_page}"));
     /**
      * Se efectuan los calculos para las paginas
      **/
     $page->next = $start + $per_page < $n ? $page_number + 1 : false;
     $page->prev = $page_number > 1 ? $page_number - 1 : false;
     $page->current = $page_number;
     $page->total = $n % $per_page ? (int) ($n / $per_page) + 1 : $n / $per_page;
     $page->count = $n;
     $page->per_page = $per_page;
     return $page;
 }
Пример #19
0
 /**
  * @param Auth $auth
  */
 public function set_adapter($adapter, $auth = '', $extra_args = array())
 {
     if (!in_array($adapter, array('digest', 'http', 'model', 'kerberos5', 'radius'))) {
         throw new kumbiaException("Adaptador de autenticación '{$adapter}' no soportado");
     }
     $this->adapter = Util::camelcase($adapter);
     require_once __DIR__ . "/adapters/{$adapter}_auth.php";
     $adapter_class = $this->adapter . 'Auth';
     $this->extra_args = $extra_args;
     $this->adapter_object = new $adapter_class($auth, $extra_args);
 }
Пример #20
0
 /**
  * Realiza el dispatch de la ruta actual
  *
  * @return Controller
  */
 private static function _dispatch()
 {
     // Extrae las variables para manipularlas facilmente
     extract(self::$_vars, EXTR_OVERWRITE);
     if (!(include_once APP_PATH . "controllers/{$controller_path}" . '_controller.php')) {
         throw new KumbiaException(null, 'no_controller');
     }
     View::select($action);
     //TODO: mover al constructor del controller base las 2 lineas
     View::setPath($controller_path);
     //Asigna el controlador activo
     $app_controller = Util::camelcase($controller) . 'Controller';
     $cont = new $app_controller($module, $controller, $action, $parameters);
     // Se ejecutan los filtros initialize y before
     if ($cont->k_callback(true) === false) {
         return $cont;
     }
     //Obteniendo el metodo
     try {
         $reflectionMethod = new ReflectionMethod($cont, $cont->action_name);
     } catch (ReflectionException $e) {
         throw new KumbiaException(null, 'no_action');
         //TODO: enviar a un método del controller
     }
     //k_callback y __constructor metodo reservado
     if ($cont->action_name == 'k_callback' || $reflectionMethod->isConstructor()) {
         throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
     }
     //se verifica que los parametros que recibe
     //la action sea la cantidad correcta
     $num_params = count($cont->parameters);
     if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() || $num_params > $reflectionMethod->getNumberOfParameters())) {
         throw new KumbiaException(NULL, 'num_params');
     }
     try {
         $reflectionMethod->invokeArgs($cont, $cont->parameters);
     } catch (ReflectionException $e) {
         throw new KumbiaException(null, 'no_action');
         //TODO: mejor no_public
     }
     //Corre los filtros after y finalize
     $cont->k_callback();
     //Si esta routed internamente volver a ejecutar
     if (self::$_routed) {
         self::$_routed = FALSE;
         return self::_dispatch();
         // Vuelve a ejecutar el dispatcher
     }
     return $cont;
 }
Пример #21
0
Файл: form.php Проект: Jamp/sgas
 /**
  * Crea un campo select que toma los valores de un array de objetos
  *
  * @param string $field Nombre de campo
  * @param string $show Campo que se mostrara (opcional)
  * @param array $data Array('modelo','metodo','param') (opcional)
  * @param string $blank Campo en blanco (opcional)
  * @param string|array $attrs Atributos de campo (opcional)
  * @param string|array $value (opcional) Array en select multiple
  * @return string
  */
 public static function dbSelect($field, $show = NULL, $data = NULL, $blank = 'Seleccione', $attrs = '', $value = NULL)
 {
     $model = $data === NULL ? substr($field, strpos($field, '.') + 1, -3) : $data[0];
     $model = Util::camelcase($model);
     $model_asoc = new $model();
     //por defecto el primer campo no pk
     $show = $show ?: $model_asoc->non_primary[0];
     $pk = $model_asoc->primary_key[0];
     if ($data === NULL) {
         $data = $model_asoc->find("columns: {$pk},{$show}", "order: {$show} asc");
         //mejor usar array
     } else {
         $data = isset($data[2]) ? $model_asoc->{$data}[1]($data[2]) : $model_asoc->{$data}[1]();
     }
     return self::select($field, $data, $attrs, $value, $blank, $pk, $show);
 }
Пример #22
0
 /**
  * Carga y devuelve una instancia del controllador
  */
 public static function getController($param)
 {
     // Extrae las variables para manipularlas facilmente
     extract($param, EXTR_OVERWRITE);
     if (!(include_once "{$default_path}{$dir}/{$controller_path}{$suffix}")) {
         throw new KumbiaException(null, 'no_controller');
     }
     //Asigna el controlador activo
     $app_controller = Util::camelcase($controller) . 'Controller';
     return new $app_controller($param);
 }
 /**
  * Obtiene la instacia de un modelo
  *
  * @param string $model
  * @return ActiveRecord
  * @throw KumbiaException
  * */
 public static function get($model)
 {
     if (isset(self::$_models[$model])) {
         return self::$_models[$model];
     }
     /**
      * Nombre de la clase
      * */
     $Model = Util::camelcase(basename($model));
     /**
      * Verifico si esta cargada la clase
      * */
     if (!class_exists($Model, false)) {
         /**
          * Carga la clase
          * */
         $file = APP_PATH . "models/{$model}.php";
         if (is_file($file)) {
             include $file;
         } else {
             throw new KumbiaException(null, 'no_model');
         }
     }
     self::$_models[$model] = $obj = new $Model();
     return $obj;
 }
Пример #24
0
 /**
  * Obtiene la instancia de un modelo
  *
  * @param string $model
  * @return obj model
  */
 public static function model($model)
 {
     /**
      * Si se utiliza base de datos
      **/
     if (!class_exists('Db', false)) {
         require CORE_PATH . 'libs/db/db.php';
     }
     /**
      * Nombre de la clase
      **/
     $Model = Util::camelcase(basename($model));
     /**
      * Carga la clase
      **/
     if (!class_exists($Model, false)) {
         /**
          * Carga la clase
          **/
         $file = APP_PATH . "models/{$model}.php";
         if (!is_file($file)) {
             throw new KumbiaException("No existe el modelo {$model}");
         }
         include $file;
     }
     return new $Model();
 }
Пример #25
0
 /**
  * Realiza el dispatch de una ruta
  *
  * @return Object
  */
 public static function execute()
 {
     extract(Router::get(), EXTR_OVERWRITE);
     $controllers_dir = APP_PATH . 'controllers';
     if ($module) {
         $controllers_dir = $controllers_dir . '/' . $module;
     }
     $app_controller = Util::camelcase($controller) . 'Controller';
     $file = "{$controllers_dir}/{$controller}" . '_controller.php';
     if (!is_file($file)) {
         throw new KumbiaException(null, 'no_controller');
     }
     include_once $file;
     /**
      * Asigna el controlador activo
      **/
     self::$_controller = $activeController = new $app_controller($module, $controller, $action, $id, $all_parameters, $parameters);
     /**
      * Carga de modelos
      **/
     if (Config::get('config.application.database')) {
         if (Config::get('config.application.models_autoload')) {
             Load::models();
         } elseif ($activeController->models !== null) {
             Load::models($activeController->models);
         }
     }
     /**
      * Se ejecutan los filtros before
      */
     if ($activeController->initialize() === false) {
         return $activeController;
     }
     if ($activeController->before_filter() === false) {
         return $activeController;
     }
     /**
      * Se ejecuta el metodo con el nombre de la accion
      * en la clase
      */
     if (!method_exists($activeController, $action)) {
         throw new KumbiaException(null, 'no_action');
     }
     call_user_func_array(array($activeController, $action), $parameters);
     /**
      * Corre los filtros after
      */
     $activeController->after_filter();
     $activeController->finalize();
     /**
      * Elimino del controlador los modelos inyectados
      **/
     foreach (Load::get_injected_models() as $model) {
         unset($activeController->{$model});
     }
     /**
      * Limpia el buffer de modelos inyectados
      **/
     Load::reset_injected_models();
     return $activeController;
 }
Пример #26
0
 /**
  * Carga modelos
  *
  * @param string $model en small_case
  * @throw KumbiaException
  */
 public static function models($model)
 {
     $args = is_array($model) ? $model : func_get_args();
     foreach ($args as $model) {
         $Model = Util::camelcase(basename($model));
         //Si esta cargada continua con la siguiente clase
         if (class_exists($Model, FALSE)) {
             continue;
         }
         if (!(include APP_PATH . "models/{$model}.php")) {
             throw new KumbiaException($model, 'no_model');
         }
     }
 }
Пример #27
0
 /**
  * Carga los modelos
  *
  * @param string $model
  */
 protected function models($model)
 {
     $args = func_get_args();
     foreach ($args as $model) {
         $file = APP_PATH . "models/{$model}.php";
         if (is_file($file)) {
             include_once $file;
             $Model = Util::camelcase(basename($model));
             $this->{$Model} = new $Model();
             $this->_loaded_models[] = $Model;
         } elseif (is_dir(APP_PATH . "models/{$model}")) {
             foreach (new DirectoryIterator(APP_PATH . "models/{$model}") as $file) {
                 if ($file->isDot() || $file->isDir()) {
                     continue;
                 }
                 if ($file->isFile()) {
                     include_once $file->getPathname();
                     $Model = Util::camelcase(basename($file->getFilename(), '.php'));
                     $this->{$Model} = new $Model();
                     $this->_loaded_models[] = $Model;
                 }
             }
         } else {
             throw new KumbiaException("Modelo {$model} no encontrado");
         }
     }
 }