Skip to content

Commit

Permalink
Merge pull request #28 from tanhongit/main
Browse files Browse the repository at this point in the history
Fix: conflict with laravel framework
  • Loading branch information
tanhongit committed Nov 4, 2023
2 parents b8d5da1 + b41efea commit 695c927
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/common',
])
->name('*.php')
->ignoreDotFiles(true)
Expand Down
70 changes: 39 additions & 31 deletions common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/**
* The reverse of pluralizing, returns the singular form of a word in a string.
*
* @param $word
* @param string $word
*
* @return bool|string
* @return string|null
*/
function tgn_singularity($word): bool|string
function tgn_singularity(string $word): string|null
{
static $singular_rules = [
'/(quiz)zes$/i' => '$1',
Expand All @@ -36,8 +36,9 @@ function tgn_singularity($word): bool|string
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '$1$2sis',
'/([ti])a$/i' => '$1um',
'/(n)ews$/i' => '$1ews',
'/(.)s$/i' => '$1'
'/(.)s$/i' => '$1',
];

return preg_replace(
array_keys($singular_rules),
array_values($singular_rules),
Expand All @@ -50,13 +51,14 @@ function tgn_singularity($word): bool|string
/**
* Convert a string to a snack case
*
* @param $string
* @param string $string
*
* @return string
*/
function tgn_snake_case($string): string
function tgn_snake_case(string $string): string
{
$string = preg_replace('/\s+/', '_', $string);

return strtolower($string);
}
}
Expand Down Expand Up @@ -103,32 +105,38 @@ function tgn_convert_action_name(string $action): string
}
}

if (!function_exists('config')) {
/**
* Return config value by string
*
* @param string $string
*
* @return mixed
*/
function config(string $string): mixed
{
return (new ConfigHelper())->execConfig($string);
if (!class_exists('Illuminate\Foundation\Application')) {
if (!function_exists('config')) {
/**
* Return config value by string
*
* @param string $string
*
* @return mixed
*/
function config(string $string): mixed
{
return (new ConfigHelper())->execConfig($string);
}
}
}

if (!function_exists('view')) {
/**
* Get view template
*
* @param string $partialPath
* @param array $data
*
* @return null|string
*/
function view(string $partialPath, array $data = []): null|string
{
$content = (new ConfigHelper())->getTemplateData($partialPath, $data);
return $content ?: null;
if (!function_exists('view')) {
/**
* Get view template
*
* @param string $partialPath
* @param array $data
*
* @return null|string
*/
function view(string $partialPath, array $data = []): null|string
{
$content = (new ConfigHelper())->getTemplateData(
$partialPath,
$data
);

return $content ?: null;
}
}
}

0 comments on commit 695c927

Please sign in to comment.