Skip to content

Commit

Permalink
Use symfony/deprecation-contracts to trigger deprecation warnings (see
Browse files Browse the repository at this point in the history
…contao#1946)

Description
-----------

We might want to adjust the legacy code as well.

Commits
-------

8324edb Use symfony/deprecation-contracts to trigger deprecation warnings
28bb837 Adjust the @expectedDeprecation annotations
d888f80 Adjust all trigger_error() occurrences in the legacy code
18434da Final touches
6a8ff19 Adjust the new classes as well
  • Loading branch information
leofeyer committed Jul 21, 2020
1 parent fb1cb28 commit f0fa5d5
Show file tree
Hide file tree
Showing 129 changed files with 349 additions and 345 deletions.
1 change: 1 addition & 0 deletions calendar-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"patchwork/utf8": "^1.2",
"symfony/config": "4.4.*",
"symfony/dependency-injection": "4.4.*",
"symfony/deprecation-contracts": "^2.1",
"symfony/http-foundation": "4.4.*",
"symfony/http-kernel": "4.4.*",
"symfony/yaml": "4.4.*"
Expand Down
2 changes: 1 addition & 1 deletion calendar-bundle/src/Resources/contao/classes/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected function addEvent($objEvents, $intStart, $intEnd, $intBegin, $intLimit
// Backwards compatibility (4th argument was $strUrl)
if (\func_num_args() > 6)
{
@trigger_error('Calling Events::addEvent() with 7 arguments has been deprecated and will no longer work in Contao 5.0. Do not pass $strUrl as 4th argument anymore.', E_USER_DEPRECATED);
trigger_deprecation('contao/calendar-bundle', '4.0', 'Calling "Contao\Events::addEvent()" with 7 arguments has been deprecated and will no longer work in Contao 5.0. Do not pass $strUrl as 4th argument anymore.');

$intLimit = func_get_arg(5);
$intCalendar = func_get_arg(6);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"symfony/debug": "4.4.*",
"symfony/debug-bundle": "4.4.*",
"symfony/dependency-injection": "4.4.*",
"symfony/deprecation-contracts": "^2.1",
"symfony/doctrine-bridge": "4.4.*",
"symfony/dom-crawler": "4.4.*",
"symfony/dotenv": "4.4.*",
Expand Down
1 change: 1 addition & 0 deletions core-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"symfony/config": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dependency-injection": "4.4.*",
"symfony/deprecation-contracts": "^2.1",
"symfony/dom-crawler": "4.4.*",
"symfony/event-dispatcher": "4.4.*",
"symfony/expression-language": "4.4.*",
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Command/AbstractLockedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractLockedCommand extends ContainerAwareCommand
{
final protected function execute(InputInterface $input, OutputInterface $output): int
{
@trigger_error('Using the "AbstractLockedCommand" has been deprecated and will no longer work in Contao 5.0. Use the Symfony Lock component instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.7', 'Using the "AbstractLockedCommand" has been deprecated and will no longer work in Contao 5.0. Use the Symfony Lock component instead.');

$store = new FlockStore($this->getTempDir());
$factory = new Factory($store);
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function executeMigrations(): bool
$runOnceFiles = $this->getRunOnceFiles();

if ($runOnceFiles) {
@trigger_error('Using runonce.php files has been deprecated and will no longer work in Contao 5.0. Use the migration framework instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.9', 'Using "runonce.php" files has been deprecated and will no longer work in Contao 5.0. Use the migration framework instead.');
}

foreach ($runOnceFiles as $file) {
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function indexAction(): Response
{
$this->initializeContaoFramework();

@trigger_error('Using FrontendController::indexAction() has been deprecated and will no longer work in Contao 5.0. Use the Symfony routing instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.10', 'Using "Contao\FrontendController::indexAction()" has been deprecated and will no longer work in Contao 5.0. Use the Symfony routing instead.');

$controller = new FrontendIndex();

Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Controller/InitializeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class InitializeController extends AbstractController
*/
public function indexAction(): InitializeControllerResponse
{
@trigger_error('Custom entry points are deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using custom entry points has been deprecated and will no longer work in Contao 5.0.');

$masterRequest = $this->get('request_stack')->getMasterRequest();

Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Cron/LegacyCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function runLegacyCrons(string $interval): void
$system->loadLanguageFile('default');

foreach ($GLOBALS['TL_CRON'][$interval] as $cron) {
@trigger_error('Using $GLOBALS[\'TL_CRON\'] has been deprecated and will be removed in Contao 5.0. Use the "contao.cronjob" service tag instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.9', 'Using $GLOBALS[\'TL_CRON\'] has been deprecated and will be removed in Contao 5.0. Use the "contao.cronjob" service tag instead.');

$system->importStatic($cron[0])->{$cron[1]}();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ private function getResourcesPaths(ContainerBuilder $container): array
}

if (is_dir($path = Path::join($projectDir, 'app/Resources/contao'))) {
@trigger_error('Using "app/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.9', 'Using "app/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.');
$paths[] = $path;
}

if (is_dir($path = Path::join($projectDir, 'src/Resources/contao'))) {
@trigger_error('Using "src/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.9', 'Using "src/Resources/contao" has been deprecated and will no longer work in Contao 5.0. Use the "contao" folder instead.');
$paths[] = $path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RegisterFragmentsPass implements CompilerPassInterface
public function __construct(string $tag = null)
{
if (null === $tag) {
@trigger_error('Using "new RegisterFragmentsPass()" without passing the tag name has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.9', 'Initializing "Contao\CoreBundle\DependencyInjection\Compiler\RegisterFragmentsPass" objects without passing the tag name as argument has been deprecated and will no longer work in Contao 5.0.');
}

$this->tag = $tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private function overwriteImageTargetDir(array $config, ContainerBuilder $contai
Path::join($container->getParameter('kernel.project_dir'), $config['image']['target_path'])
);

@trigger_error('Using the "contao.image.target_path" parameter has been deprecated and will no longer work in Contao 5.0. Use the "contao.image.target_dir" parameter instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.4', 'Using the "contao.image.target_path" parameter has been deprecated and will no longer work in Contao 5.0. Use the "contao.image.target_dir" parameter instead.');
}

private function handleTokenCheckerConfig(array $config, ContainerBuilder $container): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function __construct(array $allowList = [])
*/
public function getWhitelist(): array
{
@trigger_error('Using the "getWhitelist()" method has been deprecated and will no longer work in Contao 5.0. Use the "getAllowList()" method instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.10', 'Using the "getWhitelist()" method has been deprecated and will no longer work in Contao 5.0. Use the "getAllowList()" method instead.');

return $this->getAllowList();
}
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/src/EventListener/RequestTokenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ public function __invoke(RequestEvent $event): void
$config = $this->framework->getAdapter(Config::class);

if (\defined('BYPASS_TOKEN_CHECK')) {
@trigger_error('Defining the BYPASS_TOKEN_CHECK constant has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Defining the BYPASS_TOKEN_CHECK constant has been deprecated and will no longer work in Contao 5.0.');

return;
}

if ($config->get('disableRefererCheck')) {
@trigger_error('Using the "disableRefererCheck" setting has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using the "disableRefererCheck" setting has been deprecated and will no longer work in Contao 5.0.');

return;
}

if ($config->get('requestTokenWhitelist')) {
@trigger_error('Using the "requestTokenWhitelist" setting has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using the "requestTokenWhitelist" setting has been deprecated and will no longer work in Contao 5.0.');

$hostname = gethostbyaddr($request->getClientIp());

Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/EventListener/UserAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

@trigger_error('Using the "UserAwareTrait" has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.3', 'Using the "Contao\CoreBundle\EventListener\UserAwareTrait" trait has been deprecated and will no longer work in Contao 5.0.');

/**
* @deprecated Deprecated since Contao 4.3, to be removed in Contao 5.0
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Exception/PaletteNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Contao\CoreBundle\Exception;

@trigger_error('Using the "Contao\CoreBundle\Exception\PaletteNotFoundException" class has been deprecated and will no longer work in Contao 5.0. Use the "Contao\CoreBundle\DataContainer\PaletteNotFoundException" class instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.7', 'Using the "Contao\CoreBundle\Exception\PaletteNotFoundException" class has been deprecated and will no longer work in Contao 5.0. Use the "Contao\CoreBundle\DataContainer\PaletteNotFoundException" class instead.');

/**
* @deprecated Deprecated since Contao 4.7, to be removed in Contao 5.0; use the
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Exception/PalettePositionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Contao\CoreBundle\Exception;

@trigger_error('Using the "Contao\CoreBundle\Exception\PalettePositionException" class has been deprecated and will no longer work in Contao 5.0. Use the "Contao\CoreBundle\DataContainer\PalettePositionException" class instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.7', 'Using the "Contao\CoreBundle\Exception\PalettePositionException" class has been deprecated and will no longer work in Contao 5.0. Use the "Contao\CoreBundle\DataContainer\PalettePositionException" class instead.');

/**
* @deprecated Deprecated since Contao 4.7, to be removed in Contao 5.0; use the
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Exception/ServiceUnavailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Contao\CoreBundle\Exception;

@trigger_error('Using the "Contao\CoreBundle\Exception\ServiceUnavailableException" class has been deprecated and will no longer work in Contao 5.0. Use the "Lexik\Bundle\MaintenanceBundle\Exception\ServiceUnavailableException" class instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.1', 'Using the "Contao\CoreBundle\Exception\ServiceUnavailableException" class has been deprecated and will no longer work in Contao 5.0. Use the "Lexik\Bundle\MaintenanceBundle\Exception\ServiceUnavailableException" class instead.');

/**
* @deprecated Deprecated since Contao 4.1, to be removed in Contao 5.0; use the
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Framework/ContaoFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private function triggerInitializeSystemHook(): void
}

if ($this->filesystem->exists($filePath = Path::join($this->projectDir, 'system/config/initconfig.php'))) {
@trigger_error('Using the "initconfig.php" file has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using the "initconfig.php" file has been deprecated and will no longer work in Contao 5.0.');
include $filePath;
}
}
Expand Down
5 changes: 1 addition & 4 deletions core-bundle/src/Framework/FrameworkAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public function setFramework(ContaoFramework $framework = null): void
*/
public function getFramework(): ContaoFramework
{
@trigger_error(
'Using FrameworkAwareTrait::getFramework() has been deprecated and will no longer work in Contao 5.0.',
E_USER_DEPRECATED
);
trigger_deprecation('contao/core-bundle', '4.3', 'Using "Contao\CoreBundle\Framework\FrameworkAwareTrait::getFramework()" has been deprecated and will no longer work in Contao 5.0.');

if (null === $this->framework) {
throw new \LogicException('The framework service has not been set.');
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Framework/ScopeAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpKernel\Event\KernelEvent;

@trigger_error('Using the "Contao\CoreBundle\Framework\ScopeAwareTrait" trait has been deprecated and will no longer work in Contao 5.0. Use the "contao.routing.scope_matcher" service instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.4', 'Using the "Contao\CoreBundle\Framework\ScopeAwareTrait" trait has been deprecated and will no longer work in Contao 5.0. Use the "contao.routing.scope_matcher" service instead.');

/**
* @deprecated Deprecated since Contao 4.4, to be removed in Contao 5.0; use
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Image/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private function createImportantPart(ImageInterface $image): ?ImportantPart
(float) $file->importantPartX + (float) $file->importantPartWidth >= 2
|| (float) $file->importantPartY + (float) $file->importantPartHeight >= 2
) {
@trigger_error(sprintf('Defining the important part in absolute pixels has been deprecated and will no longer work in Contao 5.0. Run the database migration to migrate to the new format.'), E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.8', 'Defining the important part in absolute pixels has been deprecated and will no longer work in Contao 5.0. Run the database migration to migrate to the new format.');

if ($this->logger) {
$this->logger->warning(
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Image/LegacyResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function resize(ImageInterface $image, ResizeConfiguration $config, Resiz
$projectDir = System::getContainer()->getParameter('kernel.project_dir');

if ($this->hasExecuteResizeHook() || $this->hasGetImageHook()) {
@trigger_error('Using the "executeResize" and "getImage" hooks has been deprecated and will no longer work in Contao 5.0. Replace the "contao.image.resizer" service instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using the "executeResize" and "getImage" hooks has been deprecated and will no longer work in Contao 5.0. Replace the "contao.image.resizer" service instead.');

$this->legacyImage = null;
$legacyPath = $image->getPath();
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Monolog/ContaoTableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function executeHook(string $message, ContaoContext $context): void
return;
}

@trigger_error('Using the "addLogEntry" hook has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Using the "addLogEntry" hook has been deprecated and will no longer work in Contao 5.0.');

/** @var System $system */
$system = $framework->getAdapter(System::class);
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/src/Picker/AbstractPickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function createMenuItem(PickerConfig $config)
$name = $this->getName();

if (null === $this->translator) {
@trigger_error('Using a picker provider without injecting the translator service has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.4', 'Using a picker provider without injecting the translator service has been deprecated and will no longer work in Contao 5.0.');
$label = $GLOBALS['TL_LANG']['MSC'][$name];
} else {
$label = $this->translator->trans('MSC.'.$name, [], 'contao_default');
Expand All @@ -80,7 +80,7 @@ public function createMenuItem(PickerConfig $config)
*/
public function setTokenStorage(TokenStorageInterface $tokenStorage): void
{
@trigger_error('Using AbstractPickerProvider::setTokenStorage() has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.8', 'Using "Contao\CoreBundle\Picker\AbstractPickerProvider::setTokenStorage()" has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.');

$this->tokenStorage = $tokenStorage;
}
Expand All @@ -100,7 +100,7 @@ public function isCurrent(PickerConfig $config)
*/
protected function getUser(): BackendUser
{
@trigger_error('Using AbstractPickerProvider::getUser() has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.8', 'Using "Contao\CoreBundle\Picker\AbstractPickerProvider::getUser()" has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.');

if (null === $this->tokenStorage) {
throw new \RuntimeException('No token storage provided');
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/src/Resources/contao/classes/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public static function findSearchablePages($pid=0, $domain='', $blnIsXmlSitemap=
*/
public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid)
{
@trigger_error('Using Backend::addFileMetaInformationToRequest() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.4', 'Using "Contao\Backend::addFileMetaInformationToRequest()" has been deprecated and will no longer work in Contao 5.0.');

$objFile = FilesModel::findByUuid($strUuid);

Expand Down Expand Up @@ -1289,7 +1289,7 @@ public function createFileList($strFilter='', $filemount=false)
// Deprecated since Contao 4.0, to be removed in Contao 5.0
if ($strFilter === true)
{
@trigger_error('Passing "true" to Backend::createFileList() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Passing "true" to "Contao\Backend::createFileList()" has been deprecated and will no longer work in Contao 5.0.');

$strFilter = 'gif,jpg,jpeg,png';
}
Expand Down Expand Up @@ -1339,7 +1339,7 @@ protected function doCreateFileList($strFolder=null, $level=-1, $strFilter='')
// Deprecated since Contao 4.0, to be removed in Contao 5.0
if ($strFilter === true)
{
@trigger_error('Passing "true" to Backend::doCreateFileList() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.0', 'Passing "true" to "Contao\Backend::doCreateFileList()" has been deprecated and will no longer work in Contao 5.0.');

$strFilter = 'gif,jpg,jpeg,png';
}
Expand Down
4 changes: 2 additions & 2 deletions core-bundle/src/Resources/contao/classes/BackendUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function __get($strKey)
*/
public function authenticate()
{
@trigger_error('Using BackendUser::authenticate() has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.5', 'Using "Contao\BackendUser::authenticate()" has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.');

// Do not redirect if authentication is successful
if (System::getContainer()->get('contao.security.token_checker')->hasBackendUser())
Expand Down Expand Up @@ -237,7 +237,7 @@ public function authenticate()
*/
public function login()
{
@trigger_error('Using BackendUser::login() has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.', E_USER_DEPRECATED);
trigger_deprecation('contao/core-bundle', '4.5', 'Using "Contao\BackendUser::login()" has been deprecated and will no longer work in Contao 5.0. Use Symfony security instead.');

return System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
}
Expand Down
Loading

0 comments on commit f0fa5d5

Please sign in to comment.