Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Trigger autoload for deprecated types
Browse files Browse the repository at this point in the history
By loading the deprecated types, we make sure the class alias they
contain exist, so that code type hinting against the old type accepts
the new. This is necessary because type hinting does not trigger
autoload, since it usually does not need to.
Also, we conditionally wrap the deprecation in an if statement checking
whether the new type already is loaded. That way we get the deprecation
only when really necessary.
  • Loading branch information
greg0ire committed Dec 16, 2018
1 parent 34fa80b commit cfdcb1d
Show file tree
Hide file tree
Showing 69 changed files with 338 additions and 200 deletions.
12 changes: 7 additions & 5 deletions src/CoreBundle/Component/Status/StatusClassRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Component\Status;

@trigger_error(
'The '.__NAMESPACE__.'\StatusClassRendererInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Twig\Status\StatusClassRendererInterface instead.',
E_USER_DEPRECATED
);
if (!interface_exists('\Sonata\Twig\Status\StatusClassRendererInterface', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\StatusClassRendererInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Twig\Status\StatusClassRendererInterface instead.',
E_USER_DEPRECATED
);
}

class_alias(
'\Sonata\Twig\Status\StatusClassRendererInterface',
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Date/MomentFormatConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Date;

@trigger_error(
'The '.__NAMESPACE__.'\MomentFormatConverter class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Date\MomentFormatConverter instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Date\MomentFormatConverter::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\MomentFormatConverter class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Date\MomentFormatConverter instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Date\MomentFormatConverter::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/FlashMessage/FlashManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\FlashMessage;

@trigger_error(
'The '.__NAMESPACE__.'\FlashManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Twig\FlashMessage\FlashManager instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Twig\FlashMessage\FlashManager::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\FlashManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Twig\FlashMessage\FlashManager instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Twig\FlashMessage\FlashManager::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\DataTransformer;

@trigger_error(
'The '.__NAMESPACE__.'\BooleanTypeToBooleanTransformer class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\DataTransformer\BooleanTypeToBooleanTransformer instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\DataTransformer\BooleanTypeToBooleanTransformer::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BooleanTypeToBooleanTransformer class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\DataTransformer\BooleanTypeToBooleanTransformer instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\DataTransformer\BooleanTypeToBooleanTransformer::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/BaseDoctrineORMSerializationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\BaseDoctrineORMSerializationType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BaseDoctrineORMSerializationType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\BaseDoctrineORMSerializationType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BaseDoctrineORMSerializationType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BaseDoctrineORMSerializationType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\BaseDoctrineORMSerializationType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/BasePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\BasePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BasePickerType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\BasePickerType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BasePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BasePickerType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\BasePickerType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/BaseStatusType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\BaseStatusType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BaseStatusType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\BaseStatusType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BaseStatusType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BaseStatusType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\BaseStatusType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\BooleanType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BooleanType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\BooleanType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BooleanType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\BooleanType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\BooleanType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/CollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\CollectionType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\CollectionType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\CollectionType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\CollectionType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\CollectionType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\CollectionType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/DateRangePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\DateRangePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateRangePickerType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\DateRangePickerType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DateRangePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateRangePickerType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\DateRangePickerType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/DateRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\DateRangeType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateRangeType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\DateRangeType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DateRangeType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateRangeType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\DateRangeType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/DateTimeRangePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\DateTimeRangePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateTimeRangePickerType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\DateTimeRangePickerType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DateTimeRangePickerType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateTimeRangePickerType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\DateTimeRangePickerType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/DateTimeRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\DateTimeRangeType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateTimeRangeType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\DateTimeRangeType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DateTimeRangeType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\DateTimeRangeType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\DateTimeRangeType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/EqualType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\EqualType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\EqualType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\EqualType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\EqualType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\EqualType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\EqualType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Form/Type/ImmutableArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Form\Type;

@trigger_error(
'The '.__NAMESPACE__.'\ImmutableArrayType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\ImmutableArrayType instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Form\Type\ImmutableArrayType::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\ImmutableArrayType class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Form\Type\ImmutableArrayType instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Form\Type\ImmutableArrayType::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/Adapter/AdapterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model\Adapter;

@trigger_error(
'The '.__NAMESPACE__.'\AdapterInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\AdapterChain instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Doctrine\Adapter\AdapterChain::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\AdapterChain class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\AdapterChain instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Adapter\AdapterChain::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model\Adapter;

@trigger_error(
'The '.__NAMESPACE__.'\AdapterInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\AdapterInterface instead.',
E_USER_DEPRECATED
);
if (!interface_exists(\Sonata\Doctrine\Adapter\AdapterInterface::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\AdapterInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\AdapterInterface instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Adapter\AdapterInterface::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/Adapter/DoctrineORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model\Adapter;

@trigger_error(
'The '.__NAMESPACE__.'\AdapterInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\ORM\DoctrineORMAdapter instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Doctrine\Adapter\ORM\DoctrineORMAdapter::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DoctrineORMAdapter class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\ORM\DoctrineORMAdapter instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Adapter\ORM\DoctrineORMAdapter::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/Adapter/DoctrinePHPCRAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model\Adapter;

@trigger_error(
'The '.__NAMESPACE__.'\AdapterInterface class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\PHPCR\DoctrinePHPCRAdapter instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Doctrine\Adapter\PHPCR\DoctrinePHPCRAdapter::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DoctrinePHPCRAdapter class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Adapter\PHPCR\DoctrinePHPCRAdapter instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Adapter\PHPCR\DoctrinePHPCRAdapter::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/BaseDocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model;

@trigger_error(
'The '.__NAMESPACE__.'\BaseDocumentManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Document\BaseDocumentManager instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Doctrine\Document\BaseDocumentManager::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BaseDocumentManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Document\BaseDocumentManager instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Document\BaseDocumentManager::class,
Expand Down
12 changes: 7 additions & 5 deletions src/CoreBundle/Model/BaseEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Sonata\CoreBundle\Model;

@trigger_error(
'The '.__NAMESPACE__.'\BaseEntityManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Entity\BaseEntityManager instead.',
E_USER_DEPRECATED
);
if (!class_exists(\Sonata\Doctrine\Entity\BaseEntityManager::class, false)) {
@trigger_error(
'The '.__NAMESPACE__.'\BaseEntityManager class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\Doctrine\Entity\BaseEntityManager instead.',
E_USER_DEPRECATED
);
}

class_alias(
\Sonata\Doctrine\Entity\BaseEntityManager::class,
Expand Down
Loading

0 comments on commit cfdcb1d

Please sign in to comment.