Skip to content

Commit

Permalink
Merge pull request #295 from KumbiaPHP/dev
Browse files Browse the repository at this point in the history
Change to use multiple dirnames
  • Loading branch information
joanhey committed May 8, 2019
2 parents 05a7a82 + 4f4cf48 commit 8c4c3c8
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 67 deletions.
10 changes: 5 additions & 5 deletions core/extensions/helpers/form.php
Expand Up @@ -60,7 +60,7 @@ public static function getField($field, $value = null, $is_check = false, $filte
$value = $is_check ?
Input::post($field) == $value : Input::post($field);
} elseif ($is_check) {
$value = (bool) $check;
$value = $check;
} elseif ($tmp_val = self::getFromModel($formField)) {
// Autocarga de datos
$value = $is_check ? $tmp_val == $value : $tmp_val;
Expand Down Expand Up @@ -271,9 +271,9 @@ public static function button($text, $attrs = '', $type = 'button', $value = nul
/**
* Crea un label.
*
* @param string $text Texto a mostrar
* @param string $field Campo al que hace referencia
* @param string|array Atributos de campo (opcional)
* @param string $text Texto a mostrar
* @param string $field Campo al que hace referencia
* @param string|array $attrs Atributos de campo (opcional)
*
* @return string
*/
Expand Down Expand Up @@ -355,7 +355,7 @@ public static function selectValue($item, $key, $id)
*/
public static function selectedValue($value, $key)
{
return ((is_array($value) && in_array($key, $value)) || ($key == $value)) ?
return ((is_array($value) && in_array($key, $value)) || $key === $value) ?
'selected="selected"' : '';
}

Expand Down
9 changes: 4 additions & 5 deletions core/extensions/helpers/model_form.php
Expand Up @@ -61,14 +61,13 @@ public static function create($model, $action = '')
case 'year': case 'day': case 'int unsigned': // Números

if (strripos($field, '_id', -3)) {
echo Form::dbSelect($model_name.'.'.$field, null, null, 'Seleccione', null, $model->$field);
break;
} else {
echo "<input id=\"$formId\" type=\"number\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
echo Form::dbSelect($model_name.'.'.$field, null, null, 'Seleccione', '', $model->$field);
break;
}

// no break
echo "<input id=\"$formId\" type=\"number\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
break;

case 'date': // Usar el js de datetime
echo "<input id=\"$formId\" type=\"date\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
break;
Expand Down
2 changes: 1 addition & 1 deletion core/kumbia/autoload.php
Expand Up @@ -62,7 +62,7 @@ function kumbia_autoload($class)
function kumbia_autoload_vendor($class)
{
//Autoload PSR0
$psr0 = dirname(APP_PATH, 2).'/vendor/'.str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class).'.php';
$psr0 = dirname(dirname(APP_PATH)).'/vendor/'.str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class).'.php';
if (is_file($psr0)) {
include $psr0;
}
Expand Down
18 changes: 13 additions & 5 deletions core/kumbia/bootstrap.php
Expand Up @@ -24,14 +24,22 @@
// Iniciar el buffer de salida
ob_start();

// Versión de KumbiaPHP
/**
* Versión de KumbiaPHP
*
* @return string
*/
function kumbia_version()
{
return '1.0.0';
}

// @see KumbiaException
// Inicializar el ExceptionHandler
/**
* Inicializar el ExceptionHandler
* @see KumbiaException
*
* @return void
*/
set_exception_handler(function($e) {
KumbiaException::handleException($e);
});
Expand All @@ -56,8 +64,8 @@ function kumbia_version()
if ($template = Cache::driver()->get($url, 'kumbia.templates')) {
//verifica cache de template para la url
echo $template;
echo '<!-- Time: ', round((microtime(1) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 4), ' ms -->';
exit(0);
echo '<!-- Time: ', round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 4), ' ms -->';
return;
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/kumbia/config.php
Expand Up @@ -83,6 +83,8 @@ public static function getAll()
*
* @param string $var variable de configuración
* @param mixed $value valor para atributo
*
* @return void
*/
public static function set($var, $value)
{
Expand Down Expand Up @@ -128,6 +130,8 @@ public static function &read($file, $force = false)
* Lee un archivo de configuración.
*
* @param string $file archivo
*
* @return void
*/
private static function load($file)
{
Expand Down
12 changes: 7 additions & 5 deletions core/kumbia/controller.php
Expand Up @@ -59,10 +59,12 @@ class Controller
*
* @var string
*/
public $scaffold;
public $scaffold = '';

/**
* Data disponble para mostrar
*
* @var mixed
*/
public $data;

Expand Down Expand Up @@ -94,7 +96,7 @@ protected function before_filter()
/**
* AfterFilter
*
* @return false|null
* @return false|void
*/
protected function after_filter()
{
Expand All @@ -103,7 +105,7 @@ protected function after_filter()
/**
* Initialize
*
* @return false|null
* @return false|void
*/
protected function initialize()
{
Expand All @@ -112,7 +114,7 @@ protected function initialize()
/**
* Finalize
*
* @return false|null
* @return false|void
*/
protected function finalize()
{
Expand All @@ -122,7 +124,7 @@ protected function finalize()
* Ejecuta los callback filter
*
* @param boolean $init filtros de inicio
* @return false|null
* @return false|void
*/
final public function k_callback($init = false)
{
Expand Down
2 changes: 1 addition & 1 deletion core/kumbia/kumbia_exception.php
Expand Up @@ -23,7 +23,7 @@ class KumbiaException extends Exception
/**
* View de error de la Excepción.
*
* @var string
* @var string|null
*/
protected $view;

Expand Down
2 changes: 1 addition & 1 deletion core/kumbia/kumbia_rest.php
Expand Up @@ -290,7 +290,7 @@ protected function getOutputFormat(array $validOutput)
{
/* busco un posible formato de salida */
$accept = self::accept();
foreach ($accept as $key => $a) {
foreach ($accept as $key) {
if (array_key_exists($key, $validOutput)) {
return $validOutput[$key];
}
Expand Down
77 changes: 48 additions & 29 deletions core/kumbia/kumbia_view.php
Expand Up @@ -23,7 +23,7 @@ class KumbiaView
/**
* Contenido.
*
* @var string
* @var string|null
*/
protected static $_content;
/**
Expand All @@ -35,7 +35,7 @@ class KumbiaView
/**
* Template.
*
* @var string
* @var string|null
*/
protected static $_template = 'default';
/**
Expand Down Expand Up @@ -70,23 +70,27 @@ class KumbiaView
/**
* Cambia el view y opcionalmente el template.
*
* @param string $view nombre del view a utilizar sin .phtml
* @param string $template opcional nombre del template a utilizar sin .phtml
* @param string|null $view nombre del view a utilizar sin .phtml
* @param string|null $template opcional nombre del template a utilizar sin .phtml
*
* @return void
*/
public static function select($view, $template = false)
public static function select($view, $template = '')
{
self::$_view = $view;

// verifica si se indico template
if ($template !== false) {
if ($template !== '') {
self::$_template = $template;
}
}

/**
* Asigna el template para la vista.
*
* @param string $template nombre del template a utilizar sin .phtml
* @param string|null $template nombre del template a utilizar sin .phtml
*
* @return void
*/
public static function template($template)
{
Expand All @@ -99,15 +103,17 @@ public static function template($template)
* ej. View::response('xml');
* buscara: views/controller/action.xml.phtml.
*
* @param string $response
* @param string $template Opcional nombre del template sin .phtml
* @param string $response
* @param string|null $template Opcional nombre del template sin .phtml
*
* @return void
*/
public static function response($response, $template = false)
public static function response($response, $template = null)
{
self::$_response = $response;

// verifica si se indico template
if ($template !== false) {
if ($template !== null) {
self::$_template = $template;
}
}
Expand All @@ -116,6 +122,8 @@ public static function response($response, $template = false)
* Asigna el path de la vista.
*
* @param string $path path de la vista sin extension .phtml
*
* @return void
*/
public static function setPath($path)
{
Expand All @@ -140,6 +148,8 @@ public static function getPath()
* Obtiene un atributo de KumbiaView.
*
* @param string $atribute nombre de atributo (template, response, path, etc)
*
* @return mixed
*/
public static function get($atribute)
{
Expand All @@ -149,18 +159,16 @@ public static function get($atribute)
/**
* Asigna cacheo de vistas o template.
*
* @param $time Tiempo de vida de cache
* @param $type Tipo de cache (view, template)
* @param $group Grupo de pertenencia de cache
* @param string|null $time Tiempo de vida de cache
* @param string $type Tipo de cache (view, template)
* @param string $group Grupo de pertenencia de cache
*
* @return bool En producción y cache de view
*/
public static function cache($time, $type = 'view', $group = 'kumbia.view')
{
if ($time === false) { //TODO borrar cache
self::$_cache['type'] = false;

return false;
if ($time === null) { //TODO borrar cache
return self::$_cache['type'] = false;
}
self::$_cache['type'] = $type;
self::$_cache['time'] = $time;
Expand Down Expand Up @@ -206,6 +214,8 @@ protected static function getView()
* Cachea el view o template.
*
* @param string $type view o template
*
* @return void
*/
protected static function saveCache($type)
{
Expand All @@ -219,11 +229,15 @@ protected static function saveCache($type)
* Renderiza la vista.
*
* @param Controller $controller
*
* @return void
*/
public static function render(Controller $controller)
{
if (!self::$_view && !self::$_template) {
return ob_end_flush();
ob_end_flush();

return;
}

// Guarda los datos del controlador y los envia
Expand All @@ -234,6 +248,8 @@ public static function render(Controller $controller)
* Genera la vista.
*
* @param array $controller
*
* @return void
*/
protected static function generate($controller)
{
Expand Down Expand Up @@ -265,6 +281,7 @@ protected static function generate($controller)
}

self::$_content = ob_get_clean();
ob_clean();
}

// Renderizar template
Expand All @@ -278,15 +295,18 @@ protected static function generate($controller)

// si esta en produccion y se cachea template
self::saveCache('template');
ob_end_flush();

return ob_end_flush();
return;
}

echo self::$_content;
}

/**
* Imprime el contenido del buffer.
*
* @return void
*/
public static function content()
{
Expand All @@ -300,13 +320,12 @@ public static function content()
/**
* Renderiza una vista parcial.
*
* @param string $partial vista a renderizar
* @param string $__time tiempo de cache
* @param array $params
* @param string $group grupo de cache
*
* @return string
* @throw KumbiaException
* @param string $partial vista a renderizar
* @param string $__time tiempo de cache
* @param array|string|null $params variables para el partial
* @param string $group grupo de cache
* @return void
*/
public static function partial($partial, $__time = '', $params = null, $group = 'kumbia.partials')
{
Expand Down Expand Up @@ -363,12 +382,12 @@ public static function getVar($var = '')
* Atajo para htmlspecialchars, por defecto toma el charset de la
* aplicacion.
*
* @param string $s
* @param string $string
* @param string $charset
*
* @return string
*/
function h($s, $charset = APP_CHARSET)
function h($string, $charset = APP_CHARSET)
{
return htmlspecialchars($s, ENT_QUOTES, $charset);
return htmlspecialchars($string, ENT_QUOTES, $charset);
}

0 comments on commit 8c4c3c8

Please sign in to comment.