Skip to content

Commit

Permalink
Add(helper): Add trigger_deprecation helper function
Browse files Browse the repository at this point in the history
- Implement the `trigger_deprecation` helper function in the `helpers.php` file
  • Loading branch information
guanguans committed Jul 30, 2023
1 parent a22f52e commit 3311838
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Concerns/WithRunable.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public function run($withOptions = [], ?callable $processTapper = null, ?callabl
*/
protected function exec($withOptions = [], ?callable $processTapper = null, ?callable $callback = null): string
{
@trigger_error(
sprintf(
'Since guanguans/soar-php 3.0: The "%s" method is deprecated and will be removed in version 4.0. Please use the "run" method instead.',
__METHOD__
),
E_USER_DEPRECATED
trigger_deprecation(
'guanguans/soar-php',
'3.0',
'The "%s" method is deprecated and will be removed in version 4.0. Please use the "run" method instead.',
__METHOD__
);

return $this->run($withOptions, $processTapper, $callback);
Expand Down
20 changes: 20 additions & 0 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,23 @@ function str_snake(string $str, string $delimiter = '_'): string
return strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $str));
}
}

if (! function_exists('trigger_deprecation')) {
/**
* Triggers a silenced deprecation notice.
*
* @param string $package The name of the Composer package that is triggering the deprecation
* @param string $version The version of the package that introduced the deprecation
* @param string $message The message of the deprecation
* @param mixed ...$args Values to insert in the message using printf() formatting
*
* @see https://github.com/symfony/deprecation-contracts
*/
function trigger_deprecation(string $package, string $version, string $message, ...$args): void
{
@trigger_error(
($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message),
\E_USER_DEPRECATED
);
}
}

0 comments on commit 3311838

Please sign in to comment.