|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the "andrey-helldar/support" project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Andrey Helldar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @copyright 2021 Andrey Helldar |
|
11
|
|
|
* |
|
12
|
|
|
* @license MIT |
|
13
|
|
|
* |
|
14
|
|
|
* @see https://github.com/andrey-helldar/support |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Helldar\Support\Concerns; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* If you use this trait, you need to install the dependency:. |
|
21
|
|
|
* |
|
22
|
|
|
* composer require symfony/deprecation-contracts |
|
23
|
|
|
*/ |
|
24
|
|
|
trait Deprecation |
|
25
|
|
|
{ |
|
26
|
|
|
protected static $next_version = '5.0'; |
|
27
|
|
|
|
|
28
|
|
|
protected static function deprecatedClass(string $new_class, string $old_class = null): void |
|
29
|
|
|
{ |
|
30
|
|
|
$old_class = static::getDeprecatedNamespace($old_class); |
|
31
|
|
|
|
|
32
|
|
|
static::deprecated( |
|
33
|
|
|
'The %s class has been deprecated and will be removed in version %s, use %s instead.', |
|
34
|
|
|
$old_class, |
|
35
|
|
|
static::$next_version, |
|
36
|
|
|
$new_class |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected static function deprecatedMethod(string $old_method, string $new_class, string $new_method = null): void |
|
41
|
|
|
{ |
|
42
|
|
|
$namespace = static::getDeprecatedNamespace(); |
|
43
|
|
|
|
|
44
|
|
|
static::deprecated( |
|
45
|
|
|
'The %s::%s() method has been deprecated and will be removed in version %s, use %s::%s() instead.', |
|
46
|
|
|
$namespace, |
|
47
|
|
|
$old_method, |
|
48
|
|
|
static::$next_version, |
|
49
|
|
|
$new_class, |
|
50
|
|
|
$new_method ?: $old_method |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected static function getDeprecatedNamespace(string $old_namespace = null): string |
|
55
|
|
|
{ |
|
56
|
|
|
return $old_namespace ?: static::class; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected static function deprecated(string $message, ...$args): void |
|
60
|
|
|
{ |
|
61
|
|
|
trigger_deprecation('andrey-helldar/support', static::$next_version, $message, ...$args); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|