Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 authored Mar 28, 2024
1 parent 344f495 commit 06a525a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class App extends Container
/**
* Constructor for the Application class.
*/
public function __construct()
private function __construct()
{
$this->loadEnv();
$this->configureEnvironment();
Expand Down
54 changes: 26 additions & 28 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ function config(string $key = null, string $value = null)
*/
function app(?string $alias = null, $value = null): object
{
static $instance;
$instance ??= new App;
$instance = App::getInstance();

if ($alias === null) {
if (is_null($alias)) {
return $instance;
}

if ($alias !== null && $value === null) {
return $instance->$alias;
}

if ($alias !== null && $value !== null) {
if (!is_null($value)) {
return $instance->$alias = $value;
}

return $instance;
return $instance->$alias;
}
}

Expand All @@ -67,7 +62,8 @@ function env(string $params, string|bool $default = null)

function is_cli(): bool
{
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) return true;
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true))
return true;

return !isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['REQUEST_METHOD']);
}
Expand Down Expand Up @@ -159,7 +155,7 @@ function endSection()

if (!function_exists('partials')) {

function partials(string $partial_name, array $data = [])
function partials(string $partial_name, array $data = [])
{
$partialsPath = config('paths.partialsPath'); // Make sure we have our paths set up!

Expand All @@ -180,16 +176,16 @@ function partials(string $partial_name, array $data = [])
function cleanInput($data)
{
return match (true) {
is_array($data) => array_map('cleanInput', $data),
is_array($data) => array_map('cleanInput', $data),
is_object($data) => cleanInput((array) $data),
is_email($data) => filter_var($data, FILTER_SANITIZE_EMAIL),
is_url($data) => filter_var($data, FILTER_SANITIZE_URL),
is_ip($data) => filter_var($data, FILTER_VALIDATE_IP),
is_email($data) => filter_var($data, FILTER_SANITIZE_EMAIL),
is_url($data) => filter_var($data, FILTER_SANITIZE_URL),
is_ip($data) => filter_var($data, FILTER_VALIDATE_IP),
is_string($data) => preg_replace('/[\x00-\x1F\x7F]/u', '', filter_var(trim($data), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES)),
is_int($data) => filter_var($data, FILTER_SANITIZE_NUMBER_INT),
is_float($data) => filter_var($data, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION),
is_bool($data) => filter_var($data, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
is_null($data) => settype($data, 'NULL'),
is_int($data) => filter_var($data, FILTER_SANITIZE_NUMBER_INT),
is_float($data) => filter_var($data, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION),
is_bool($data) => filter_var($data, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
is_null($data) => settype($data, 'NULL'),

default => filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS),
};
Expand Down Expand Up @@ -250,7 +246,8 @@ function is_ip($ip): bool
function show($data = null, bool $return = false): string
{
$output = $data ?? '';
if ($return) return $output;
if ($return)
return $output;

echo $output . PHP_EOL;
return '';
Expand Down Expand Up @@ -368,7 +365,7 @@ function baseUrl(string $path = '/'): string
*/
function asset(string $path, ?string $basePath = null): string
{
$basePath = $basePath ?? 'app/resources/assets/';
$basePath = $basePath ?? 'app/resources/assets/';
$base = rtrim($basePath, '/') . '/' . ltrim($path, '/');

return baseUrl($base);
Expand Down Expand Up @@ -441,7 +438,8 @@ function refresh()
**/
function post($key = null)
{
if (!($post = app()->request->post())) return false;
if (!($post = app()->request->post()))
return false;

if ($key !== null) {
return htmlspecialchars($post[$key], ENT_QUOTES, 'UTF-8');
Expand Down Expand Up @@ -538,7 +536,8 @@ function once($fn)
{
$hasRun = false;
return function (...$params) use ($fn, &$hasRun) {
if ($hasRun) return;
if ($hasRun)
return;

$hasRun = true;

Expand All @@ -559,8 +558,7 @@ function str($string = null)
{
if (is_null($string)) {
// Return a new class instance for chaining string methods
return new class
{
return new class {
public function __call($method, $params)
{
// Delegate method calls to the Str class
Expand Down Expand Up @@ -641,22 +639,22 @@ function helpers($helpers, string $customPath = null, string $separator = '_')
if ($customPath) {
$customHelperFile = $customPath . DIRECTORY_SEPARATOR . $helper;
if (is_file($customHelperFile)) {
require_once($customHelperFile);
require_once ($customHelperFile);
continue;
}
}

// Try to load the helper from the default application path
$appHelperFile = $appPath . DIRECTORY_SEPARATOR . $helper;
if (is_file($appHelperFile)) {
require_once($appHelperFile);
require_once ($appHelperFile);
continue;
}

// Try to load the helper from the Axm system path
$axmHelperFile = $axmHelpersPath . DIRECTORY_SEPARATOR . $helper;
if (is_file($axmHelperFile)) {
require_once($axmHelperFile);
require_once ($axmHelperFile);
continue;
}

Expand Down

0 comments on commit 06a525a

Please sign in to comment.