From 3a35f98fc8eb27f86cd22072b83ace556b691565 Mon Sep 17 00:00:00 2001 From: juancristobalgd1 <65052633+juancristobalgd1@users.noreply.github.com> Date: Thu, 23 Nov 2023 21:58:49 +0100 Subject: [PATCH 1/5] update files : axm_helper, Axm --- src/Axm.php | 4 ++-- src/axm_helper.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Axm.php b/src/Axm.php index 2e6b4ab..09b8b50 100644 --- a/src/Axm.php +++ b/src/Axm.php @@ -93,8 +93,8 @@ public static function is_cli(): bool */ private static function initializeEnvironment() { - // Obtain the value of AXM_ENVIRONMENT or use a default value - static::$_environment = $env = env('AXM_ENVIRONMENT', 'production'); + // Obtain the value of APP_ENVIRONMENT or use a default value + static::$_environment = $env = env('APP_ENVIRONMENT', 'production'); // Configuring environment-based error handling. if ($env === 'debug') { diff --git a/src/axm_helper.php b/src/axm_helper.php index bef8a53..332d257 100644 --- a/src/axm_helper.php +++ b/src/axm_helper.php @@ -96,7 +96,7 @@ function raxmScripts() * @param string $ext The file extension of the View template (default is '.php'). * @return void */ - function view(string $view, $params = null, bool $buffer = true, string $ext = '.php') + function view(string $view, array $params = [], bool $buffer = true, string $ext = '.php') { // Render the View template using the provided parameters. $renderedView = Axm::app()->controller->renderView($view, $params, $buffer, $ext); From a0e6dc13fcdaf382a131dea464635028af83fe87 Mon Sep 17 00:00:00 2001 From: juancristobalgd1 <65052633+juancristobalgd1@users.noreply.github.com> Date: Fri, 24 Nov 2023 01:04:20 +0100 Subject: [PATCH 2/5] update Controller.php --- src/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller.php b/src/Controller.php index af7e9c7..89ed731 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -158,6 +158,6 @@ public function accessControl(array $actions, bool $allowedAction = false) */ public function __call($name, $arguments) { - throw new AxmException(Axm::t('axm', 'El método "%s" no existe', [$name]), 'no_action'); + throw new AxmException("Method [ $name ] does not exist"); } } From fe88c52c6e9b225f9ad4f1be4308c0dce28ce677 Mon Sep 17 00:00:00 2001 From: juancristobalgd1 <65052633+juancristobalgd1@users.noreply.github.com> Date: Fri, 24 Nov 2023 02:25:30 +0100 Subject: [PATCH 3/5] update axm_helper.php --- src/axm_helper.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/axm_helper.php b/src/axm_helper.php index 332d257..fe27644 100644 --- a/src/axm_helper.php +++ b/src/axm_helper.php @@ -1008,6 +1008,22 @@ function camelCase($str) } } +if (!function_exists('esc')) { + /** + * Escapes and formats a text string for safe display in HTML. + * + * This function combines HTML encoding and newline-to-break conversion. + * @param string $text The input text to be escaped and formatted. + * @return string The escaped and formatted text. + */ + function esc(string $text): string + { + $encodedText = htmlspecialchars($text, ENT_QUOTES, config('app.charset') ?? 'UTF-8'); + $brText = nl2br($encodedText); + return $brText; + } +} + if (!function_exists('getLatestPackageVersion')) { /** From 8a2b4667791193c25f953bcee131707ba908f2c5 Mon Sep 17 00:00:00 2001 From: juancristobalgd1 <65052633+juancristobalgd1@users.noreply.github.com> Date: Fri, 24 Nov 2023 02:50:16 +0100 Subject: [PATCH 4/5] update axm_helper --- src/axm_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/axm_helper.php b/src/axm_helper.php index fe27644..27606d9 100644 --- a/src/axm_helper.php +++ b/src/axm_helper.php @@ -819,8 +819,8 @@ function helpers($helpers, string $customPath = null, string $separator = '_') } // Define paths for helper files - $appPath = APP_PATH . DIRECTORY_SEPARATOR . 'Helpers'; // Default application path - $axmHelpersPath = AXM_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'src'; // Axm system path + $appPath = config('paths.helpersPath'); // Default application path + $axmHelpersPath = config('paths.helpersAxmPath'); // Axm system path // Load custom helpers from the provided path if ($customPath) { @@ -920,7 +920,7 @@ function logger(string $message, string $level = 'debug', bool $output = false) $dateTime = date('d-m-Y H:i:s'); $level = in_array($level, $levels) ? $level : 'debug'; $formattedMessage = '[' . strtoupper($level) . "] $dateTime - $message"; - $logFilePath = STORAGE_PATH . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'axm_log.log'; + $logFilePath = config('paths.logsPath') . DIRECTORY_SEPARATOR . 'axm_log.log'; if (!file_exists($logFilePath)) { setFlash('error', sprintf('The log file does not exist at %s', $logFilePath)); From ff4543c5873cfd365f87e72c38f953919464f8c5 Mon Sep 17 00:00:00 2001 From: juancristobalgd1 <65052633+juancristobalgd1@users.noreply.github.com> Date: Sat, 25 Nov 2023 03:26:20 +0100 Subject: [PATCH 5/5] update Database.php --- src/Database.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Database.php b/src/Database.php index 52f43f6..31eb9c0 100644 --- a/src/Database.php +++ b/src/Database.php @@ -16,20 +16,25 @@ */ class Database { - private static $conection; + /** + * @var Illuminate\Database\Capsule\Manager + */ + private static $connection; /** * Create a new database connection for models - * * @param string|null $driver */ public static function connect(string $driver = null) { + // If there is already a connection, do nothing + if (isset(static::$connection)) return; + $config = config('/DataBase.php'); $driver = $driver ?? $config['db']['default'] ?? 'mysql'; - $capsule = static::$conection = new Capsule; + $capsule = static::$connection = new Capsule; $capsule->addConnection( $config['db']['connections'][$driver] ); @@ -39,14 +44,25 @@ public static function connect(string $driver = null) $capsule->setAsGlobal(); $capsule->bootEloquent(); + + // if (php_sapi_name() === 'cli') { + // Schema::$capsule = $capsule; + // } } /** * Get database connection + * @return Illuminate\Database\Capsule\Manager */ - public static function get() + public static function db() { - return static::$conection; + if (static::$connection) { + return static::$connection; + } + + static::connect(); + + return static::$connection; } /** @@ -54,6 +70,8 @@ public static function get() */ public static function disconnect(string $driver) { - return static::$conection->getConnection()->disconnect($driver); + return static::$connection + ->getConnection() + ->disconnect($driver); } }