Skip to content

Commit

Permalink
Merge pull request KumbiaPHP#377 from KumbiaPHP/dev
Browse files Browse the repository at this point in the history
Initial changes for v1.2
  • Loading branch information
joanhey authored Jan 5, 2024
2 parents 4891267 + 4cfc2fc commit ae78147
Show file tree
Hide file tree
Showing 29 changed files with 166 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1']
php-versions: ['8.0', '8.1', '8.2', '8.3']
phpunit-versions: ['latest']

steps:
Expand All @@ -57,7 +57,7 @@ jobs:

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
Expand Down
5 changes: 3 additions & 2 deletions README.EN.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
![KumbiaPHP logo](https://rawgit.com/kumbiaphp/kumbiaphp/master/default/public/img/kumbiaphp.svg)

[![PHPUnit](https://github.com/KumbiaPHP/KumbiaPHP/actions/workflows/phpunit.yml/badge.svg)](https://github.com/KumbiaPHP/KumbiaPHP/actions/workflows/phpunit.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KumbiaPHP/KumbiaPHP/badges/quality-score.png)](https://scrutinizer-ci.com/g/KumbiaPHP/KumbiaPHP)
[![Code Climate](https://codeclimate.com/github/KumbiaPHP/KumbiaPHP/badges/gpa.svg)](https://codeclimate.com/github/KumbiaPHP/KumbiaPHP)
[![Slack](https://slack.kumbiaphp.com/badge.svg)](https://slack.kumbiaphp.com)
![PHP7 ready](https://rawgit.com/kumbiaphp/kumbiaphp/master/default/public/img/php7.svg)
![PHP8 ready](/default/public/img/php8.svg?sanitize=true)

English | [Español](README.md)

Fast and easy php framework

---
# Welcome to KumbiaPHP Framework
* v1.2 require PHP 7.4
* v1.2 require PHP 8.0
* Til v1.1.x require PHP 5.4, recommended 7.x or 8.x
## Manual v1:

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
![KumbiaPHP logo](https://raw.githubusercontent.com/KumbiaPHP/KumbiaPHP/master/default/public/img/kumbiaphp.svg?sanitize=true)

[![PHPUnit](https://github.com/KumbiaPHP/KumbiaPHP/actions/workflows/phpunit.yml/badge.svg)](https://github.com/KumbiaPHP/KumbiaPHP/actions/workflows/phpunit.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KumbiaPHP/KumbiaPHP/badges/quality-score.png)](https://scrutinizer-ci.com/g/KumbiaPHP/KumbiaPHP)
[![Code Climate](https://codeclimate.com/github/KumbiaPHP/KumbiaPHP/badges/gpa.svg)](https://codeclimate.com/github/KumbiaPHP/KumbiaPHP)
[![Slack](https://slack.kumbiaphp.com/badge.svg)](https://slack.kumbiaphp.com)
![PHP7 ready](https://raw.githubusercontent.com/KumbiaPHP/KumbiaPHP/master/default/public/img/php7.svg?sanitize=true)
![PHP8 ready](/default/public/img/php8.svg?sanitize=true)

Español | [English](README.EN.md)

Expand All @@ -28,8 +29,8 @@ https://slack.kumbiaphp.com (new)
https://www.techempower.com/benchmarks/#section=data-r18&hw=ph&test=fortune&l=zik073-f&w=0-jz6rk-0&c=4

## Change Log
* v1.2 necesita mínimo PHP 7.4
* Hasta la v1.1.5 requiere PHP 5.4 como mínimo, recomendado usar PHP 5.6, 7.1, 7.2 o 7.3
* v1.2 necesita mínimo PHP 8.0
* Hasta la v1.1.5 requiere PHP 5.4 como mínimo, recomendado 7.x o 8.x
* CRUD: https://wiki.kumbiaphp.com/V1.0_CRUD_en_KumbiaPHP_Framework

Comunidad
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "BSD-3-Clause",
"name": "kumbia/framework",
"require": {
"php": ">=7.4"
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9",
Expand Down
44 changes: 32 additions & 12 deletions core/extensions/helpers/form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* KumbiaPHP web & app Framework
*
Expand Down Expand Up @@ -58,7 +59,7 @@ public static function getField($field, $value = null, $is_check = false, $filte
// Verifica en $_POST
if (Input::hasPost($field)) {
$value = $is_check ?
Input::post($field) == $value : Input::post($field);
Input::post($field) == $value : Input::post($field);
} elseif ($is_check) {
$value = $check;
} elseif ($tmp_val = self::getFromModel($formField)) {
Expand All @@ -67,12 +68,28 @@ public static function getField($field, $value = null, $is_check = false, $filte
}
// Filtrar caracteres especiales
if (!$is_check && $value !== null && $filter) {
$value = htmlspecialchars($value, ENT_COMPAT, APP_CHARSET);
if (is_array($value)) {
$value = self::filterArrayValues($value);
} else {
$value = htmlspecialchars($value, ENT_COMPAT, APP_CHARSET);
}
}
// Devuelve los datos
return array($id, $name, $value);
}

private static function filterArrayValues(array $array)
{
foreach ($array as &$value) {
if (is_array($value)) {
$value = self::filterArrayValues($value);
} else {
$value = htmlspecialchars($value, ENT_COMPAT, APP_CHARSET);
}
}
return $array;
}

/**
* Devuelve el valor del modelo.
*
Expand Down Expand Up @@ -101,7 +118,7 @@ protected static function getFromModel(array $formField)
protected static function fieldName(array $field)
{
return isset($field[1]) ?
array("{$field[0]}_{$field[1]}", "{$field[0]}[{$field[1]}]") : array($field[0], $field[0]);
array("{$field[0]}_{$field[1]}", "{$field[0]}[{$field[1]}]") : array($field[0], $field[0]);
}

/**
Expand Down Expand Up @@ -181,9 +198,9 @@ public static function open($action = '', $method = 'post', $attrs = '')
{
$attrs = Tag::getAttrs($attrs);
if ($action) {
$action = PUBLIC_PATH.$action;
$action = PUBLIC_PATH . $action;
} else {
$action = PUBLIC_PATH.ltrim(Router::get('route'), '/');
$action = PUBLIC_PATH . ltrim(Router::get('route'), '/');
}

return "<form action=\"$action\" method=\"$method\" $attrs>";
Expand Down Expand Up @@ -318,7 +335,7 @@ public static function select($field, $data, $attrs = '', $value = null, $blank
list($id, $name, $value) = self::getFieldData($field, $value);
//Si se quiere agregar blank
$options = empty($blank) ? '' :
'<option value="">'.htmlspecialchars($blank, ENT_COMPAT, APP_CHARSET).'</option>';
'<option value="">' . htmlspecialchars($blank, ENT_COMPAT, APP_CHARSET) . '</option>';
foreach ($data as $k => $v) {
$val = self::selectValue($v, $k, $itemId);
$text = self::selectShow($v, $show);
Expand All @@ -340,8 +357,11 @@ public static function select($field, $data, $attrs = '', $value = null, $blank
*/
public static function selectValue($item, $key, $id)
{
return htmlspecialchars(is_object($item) ? $item->$id : $key,
ENT_COMPAT, APP_CHARSET);
return htmlspecialchars(
is_object($item) ? $item->$id : $key,
ENT_COMPAT,
APP_CHARSET
);
}

/**
Expand All @@ -356,7 +376,7 @@ public static function selectValue($item, $key, $id)
public static function selectedValue($value, $key)
{
return ((is_array($value) && in_array($key, $value)) || $key === $value) ?
'selected="selected"' : '';
'selected="selected"' : '';
}

/**
Expand Down Expand Up @@ -440,7 +460,7 @@ public static function submitImage($img, $attrs = '')
{
$attrs = Tag::getAttrs($attrs);

return '<input type="image" src="'.PUBLIC_PATH."img/$img\" $attrs/>";
return '<input type="image" src="' . PUBLIC_PATH . "img/$img\" $attrs/>";
}

/**
Expand Down Expand Up @@ -507,8 +527,8 @@ public static function dbSelect($field, $show = null, $data = null, $blank = 'Se
$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]}();
$model_asoc->{$data[1]}($data[2]) :
$model_asoc->{$data[1]}();
}

return self::select($field, $data, $attrs, $value, $blank, $pk, $show);
Expand Down
26 changes: 14 additions & 12 deletions core/extensions/helpers/model_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @category KumbiaPHP
* @package Helpers
*
* @copyright Copyright (c) 2005 - 2023 KumbiaPHP Team (http://www.kumbiaphp.com)
* @copyright Copyright (c) 2005 - 2024 KumbiaPHP Team (http://www.kumbiaphp.com)
* @license https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE New BSD License
*/

Expand All @@ -23,10 +23,10 @@
class ModelForm
{
/**
* Generate a form from model automatically
* -
* Genera un form de un modelo (objeto) automáticamente.
*
* @param object $model
* @param string $action
*/
public static function create(object $model, string $action = ''): void
{
Expand All @@ -40,7 +40,7 @@ public static function create(object $model, string $action = ''): void
$pk = $model->primary_key[0];
echo '<input id="', $model_name, '_', $pk, '" name="', $model_name, '[', $pk, ']" class="id" value="', $model->$pk , '" type="hidden">' , PHP_EOL;

$fields = array_diff($model->fields, [$model->_at, $model->_in, $model->primary_key]);
$fields = array_diff($model->fields, [...$model->_at, ...$model->_in, ...$model->primary_key]);

foreach ($fields as $field) {
$tipo = trim(preg_replace('/(\(.*\))/', '', $model->_data_type[$field])); //TODO: recoger tamaño y otros valores
Expand All @@ -50,8 +50,10 @@ public static function create(object $model, string $action = ''): void

if (in_array($field, $model->not_null)) {
echo "<label class=\"required\">$alias" , PHP_EOL;
$required = ' required';
} else {
echo "<label>$alias" , PHP_EOL;
$required = '';
}

switch ($tipo) {
Expand All @@ -61,20 +63,20 @@ public static function create(object $model, string $action = ''): void
case 'real': case 'decimal': case 'numeric':
case 'year': case 'day': case 'int unsigned': // Números

if (strripos($field, '_id', -3)) {
echo Form::dbSelect($model_name.'.'.$field, null, null, 'Seleccione', '', $model->$field);
if (str_ends_with($field, '_id')) {
echo Form::dbSelect($model_name.'.'.$field, null, null, 'Seleccione', $required, $model->$field);
break;
}

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

case 'date':
echo "<input id=\"$formId\" type=\"date\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
echo "<input id=\"$formId\" type=\"date\" name=\"$formName\" value=\"{$model->$field}\"$required>" , PHP_EOL;
break;

case 'datetime': case 'timestamp':
echo "<input id=\"$formId\" type=\"datetime\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
echo "<input id=\"$formId\" type=\"datetime-local\" name=\"$formName\" value=\"{$model->$field}\"$required>" , PHP_EOL;
break;

case 'enum': case 'set': case 'bool':
Expand All @@ -88,15 +90,15 @@ public static function create(object $model, string $action = ''): void

case 'text': case 'mediumtext': case 'longtext': // Usar textarea
case 'blob': case 'mediumblob': case 'longblob':
echo "<textarea id=\"$formId\" name=\"$formName\">{$model->$field}</textarea>" , PHP_EOL;
echo "<textarea id=\"$formId\" name=\"$formName\"$required>{$model->$field}</textarea>" , PHP_EOL;
break;

default: //text,tinytext,varchar, char,etc se comprobara su tamaño
echo "<input id=\"$formId\" type=\"text\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL;
echo "<input id=\"$formId\" type=\"text\" name=\"$formName\" value=\"{$model->$field}\"$required>" , PHP_EOL;
}
echo '</label>';
}
echo '<input type="submit" value="Enviar" />' , PHP_EOL;
echo '<input type="submit">' , PHP_EOL;
echo '</form>' , PHP_EOL;
}
}
2 changes: 1 addition & 1 deletion core/kumbia/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function kumbia_autoload($class)
function kumbia_autoload_vendor($class): void
{
//Autoload PSR0
$psr0 = dirname(dirname(APP_PATH)).'/vendor/'.str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class).'.php';
$psr0 = dirname(APP_PATH, 2).'/vendor/'.str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class).'.php';
if (is_file($psr0)) {
include $psr0;
}
Expand Down
5 changes: 1 addition & 4 deletions core/kumbia/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
*
* @return void
*/
set_exception_handler(function($e) {
KumbiaException::handleException($e);
});

set_exception_handler(fn($e) => KumbiaException::handleException($e));

// @see Autoload
require CORE_PATH.'kumbia/autoload.php';
Expand Down
Loading

0 comments on commit ae78147

Please sign in to comment.