Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f1593da

Browse filesBrowse files
[Contracts/Deprecation] Provide a generic function and convention to trigger deprecation notices
1 parent f0fbdee commit f1593da
Copy full SHA for f1593da

File tree

6 files changed

+105
-0
lines changed
Filter options

6 files changed

+105
-0
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Symfony Deprecation Contracts
2+
=============================
3+
4+
A generic function and convention to trigger deprecation notices.
5+
6+
This package provides a single global function named `deprecated()`.
7+
Its purpose is to trigger deprecations in a way that can be silenced on production environments
8+
by using the `zend.assertions` ini setting and that can be caught during development to generate reports.
9+
10+
The function requires at least 3 arguments:
11+
- the name of the package that is triggering the deprecation
12+
- the version of the package that introduced the deprecation
13+
- the message of the deprecation
14+
- more arguments can be provided: they will be inserted in the message using `sprintf()`
15+
16+
Example:
17+
```php
18+
deprecated('symfony/blockchain', 8.9, 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin');
19+
```
20+
21+
This will generate the following message:
22+
`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.`
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "symfony/deprecation-contracts",
3+
"type": "library",
4+
"description": "A generic function and convention to trigger deprecation notices",
5+
"homepage": "https://symfony.com",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Nicolas Grekas",
10+
"email": "p@tchwork.com"
11+
},
12+
{
13+
"name": "Symfony Community",
14+
"homepage": "https://symfony.com/contributors"
15+
}
16+
],
17+
"require": {
18+
"php": "^7.0"
19+
},
20+
"autoload": {
21+
"files": [
22+
"deprecated.php"
23+
]
24+
},
25+
"minimum-stability": "dev",
26+
"extra": {
27+
"branch-alias": {
28+
"dev-master": "2.0-dev"
29+
}
30+
}
31+
}
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
/**
13+
* Triggers a deprecation.
14+
*
15+
* As recommended for prod, turn the "zend.assertions" ini setting to 0 or -1 to disable deprecation notices.
16+
*
17+
* The function doesn't use type hints nor variadics on purpose, to make it as fast as possibly achievable.
18+
*
19+
* @param string $package The name of the package that is triggering the deprecation
20+
* @param string|float $version The version of the package that introduced the deprecation
21+
* @param string $message The message of the deprecation; more arguments can be provided: they will be inserted in the message using sprintf()
22+
*
23+
* @author Nicolas Grekas <p@tchwork.com>
24+
*/
25+
function deprecated($package, $version, $message)
26+
{
27+
assert(@trigger_error("Since $package $version: ".sprintf($message, ...array_slice(func_get_args(), 3)), E_USER_DEPRECATED));
28+
}

‎src/Symfony/Contracts/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/composer.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"replace": {
2828
"symfony/cache-contracts": "self.version",
29+
"symfony/deprecation-contracts": "self.version",
2930
"symfony/event-dispatcher-contracts": "self.version",
3031
"symfony/http-client-contracts": "self.version",
3132
"symfony/service-contracts": "self.version",
@@ -40,6 +41,7 @@
4041
},
4142
"autoload": {
4243
"psr-4": { "Symfony\\Contracts\\": "" },
44+
"file": [ "Deprecation/deprecated.php" ],
4345
"exclude-from-classmap": [
4446
"**/Tests/"
4547
]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.