Skip to content

Commit

Permalink
[Contracts/Deprecation] Provide a generic function and convention to …
Browse files Browse the repository at this point in the history
…trigger deprecation notices
  • Loading branch information
nicolas-grekas committed Jan 30, 2020
1 parent f0fbdee commit b85243a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Contracts/Deprecation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
phpunit.xml
19 changes: 19 additions & 0 deletions src/Symfony/Contracts/Deprecation/LICENSE
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.
22 changes: 22 additions & 0 deletions src/Symfony/Contracts/Deprecation/README.md
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 environment
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 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 `sprintf()`

Example:
```php
@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.`
31 changes: 31 additions & 0 deletions src/Symfony/Contracts/Deprecation/composer.json
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.0-dev"
}
}
}
22 changes: 22 additions & 0 deletions src/Symfony/Contracts/Deprecation/deprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
function deprecated($package, $version, $message)
{
assert(trigger_error("Since $package $version: ".sprintf($message, ...array_slice(func_get_args(), 3)), E_USER_DEPRECATED));
}
2 changes: 2 additions & 0 deletions src/Symfony/Contracts/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"replace": {
"symfony/cache-contracts": "self.version",
"symfony/deprecation-contracts": "self.version",
"symfony/event-dispatcher-contracts": "self.version",
"symfony/http-client-contracts": "self.version",
"symfony/service-contracts": "self.version",
Expand All @@ -40,6 +41,7 @@
},
"autoload": {
"psr-4": { "Symfony\\Contracts\\": "" },
"file": [ "Deprecation/deprecated.php" ],
"exclude-from-classmap": [
"**/Tests/"
]
Expand Down

0 comments on commit b85243a

Please sign in to comment.