-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Contracts/Deprecation] Provide a generic function and convention to trigger deprecation notices #35526
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
Merged
Merged
[Contracts/Deprecation] Provide a generic function and convention to trigger deprecation notices #35526
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Contracts/Deprecation] Provide a generic function and convention to …
…trigger deprecation notices
- Loading branch information
commit f0f41cbfc56a6b5bbe6a267ee86414b8b53a1c09
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2020 Fabien Potencier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Symfony Deprecation Contracts | ||
============================= | ||
|
||
A generic function and convention to trigger deprecation notices. | ||
|
||
This package provides a single global function named `deprecated()`. | ||
Its purpose is to trigger deprecations in a way that can be silenced on production environments | ||
by using the `zend.assertions` ini setting and that can be caught during development to generate reports. | ||
|
||
The function requires at least 3 arguments: | ||
- the name of the Composer package that is triggering the deprecation | ||
- the version of the package that introduced the deprecation | ||
- the message of the deprecation | ||
- more arguments can be provided: they will be inserted in the message using `printf()` formatting | ||
fabpot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example: | ||
```php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 8.9 should be a string ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #35526 (comment) |
||
deprecated('symfony/blockchain', 8.9, 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin'); | ||
``` | ||
|
||
This will generate the following message: | ||
`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "symfony/deprecation-contracts", | ||
"type": "library", | ||
"description": "A generic function and convention to trigger deprecation notices", | ||
"homepage": "https://symfony.com", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nicolas Grekas", | ||
"email": "p@tchwork.com" | ||
}, | ||
{ | ||
"name": "Symfony Community", | ||
"homepage": "https://symfony.com/contributors" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.0" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"deprecated.php" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "2.1-dev" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Triggers a deprecation. | ||
* | ||
* As recommended for prod, turn the "zend.assertions" ini setting to 0 or -1 to disable deprecation notices. | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Alternatively, provide your own implementation of the function and list "symfony/deprecation-contracts" | ||
* in the "replace" section of your root composer.json if you need any custom behavior. | ||
* | ||
* The function doesn't use type hints to make it as fast as possible. | ||
* | ||
* @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 scalar ...$args Values to insert in the message using printf() formatting | ||
* | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
function deprecated($package, $version, $message, ...$args) | ||
{ | ||
assert(@trigger_error( | ||
($package || $version ? "Since $package $version: " : '') | ||
.($args ? vsprintf($message, $args) : $message), | ||
E_USER_DEPRECATED | ||
)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.