Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Change log_reference_length to log_reference_params #34

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions config/pay-pocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
| This configuration allows you to customize the generation of log reference strings
| within the LaravelPayPocket package.
|
| - log_reference_length: The length of the generated reference string.
| - log_reference_prefix: The prefix for the generated reference string.
| - log_reference_generator_class: The fully qualified name of the class containing static methods for generation.
| - log_reference_generator_method: The name of the static method available in the generator class.
| - [array] log_reference_params: The parameters to pass to the log reference generator.
| - [string] log_reference_prefix: The prefix for the generated reference string.
| - [class-string] log_reference_generator_class: The fully qualified name of the class containing static methods for generation.
| - [string] log_reference_generator_method: The name of the static method available in the generator class.
|
| This is how it works by default in the code:
| Illuminate\Support\Str::random(12)
|
*/

'log_reference_length' => 12,
'log_reference_params' => [12],
'log_reference_prefix' => '',
'log_reference_generator_class' => Illuminate\Support\Str::class,
'log_reference_generator_method' => 'random',
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/BalanceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ protected function generateReference(): string
{
$className = config('pay-pocket.log_reference_generator_class');
$methodName = config('pay-pocket.log_reference_generator_method');
$length = config('pay-pocket.log_reference_length');
$params = (array)config('pay-pocket.log_reference_params', [12]);
$prefix = config('pay-pocket.log_reference_prefix');

if (! is_callable([$className, $methodName])) {
throw new InvalidArgumentException('Invalid configuration: The combination of log_reference_generator_class and log_reference_generator_method is not callable.');
}

$reference = call_user_func([$className, $methodName], $length);
$reference = call_user_func([$className, $methodName], ...$params);

return $prefix.$reference;
return $prefix . $reference;
}
}