Skip to content
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

Mark classes as @final and deprecate extending them #2008

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/Doctrine/ODM/MongoDB/DocumentNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@

namespace Doctrine\ODM\MongoDB;

use Throwable;

/**
* Class for exception when encountering proxy object that has
* an identifier that does not exist in the database.
*
* @final
* @since 1.0
*/
class DocumentNotFoundException extends MongoDBException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($message, $code, $previous);
}

public static function documentNotFound($className, $identifier)
{
return new self(sprintf(
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/**
* Provides event arguments for the documentNotFound event.
*
* @final
* @since 1.1
*/
class DocumentNotFoundEventArgs extends LifecycleEventArgs
Expand All @@ -49,6 +50,9 @@ class DocumentNotFoundEventArgs extends LifecycleEventArgs
*/
public function __construct($document, DocumentManager $dm, $identifier)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($document, $dm);
$this->identifier = $identifier;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/LoadClassMetadataEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@
namespace Doctrine\ODM\MongoDB\Event;

use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;

/**
* Class that holds event arguments for a loadMetadata event.
*
* @final
* @since 1.0
*/
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
{
public function __construct(ClassMetadata $classMetadata, ObjectManager $objectManager)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($classMetadata, $objectManager);
}

/**
* Retrieves the associated DocumentManager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* This object is mutable by design, allowing callbacks having access to it to set the
* found metadata in it, and therefore "cancelling" a `onClassMetadataNotFound` event
*
* @final
*/
class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
{
Expand All @@ -29,6 +31,9 @@ class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
*/
public function __construct($className, DocumentManager $dm)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
$this->className = (string) $className;

parent::__construct($dm);
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
/**
* Provides event arguments for the onClear event.
*
* @final
* @since 1.0
*/
class OnClearEventArgs extends BaseOnClearEventArgs
{
public function __construct($objectManager, $entityClass = null)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($objectManager, $entityClass);
}

/**
* Retrieves the associated DocumentManager.
*
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/OnFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@

namespace Doctrine\ODM\MongoDB\Event;

use Doctrine\Common\Persistence\ObjectManager;

/**
* Provides event arguments for the onFlush event.
*
* @final
* @since 1.0
*/
class OnFlushEventArgs extends ManagerEventArgs
{
public function __construct(ObjectManager $objectManager)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($objectManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* Class that holds arguments for postCollectionLoad event.
*
* @final
* @since 1.1
*/
class PostCollectionLoadEventArgs extends ManagerEventArgs
Expand All @@ -23,6 +24,9 @@ class PostCollectionLoadEventArgs extends ManagerEventArgs
*/
public function __construct(PersistentCollectionInterface $collection, DocumentManager $dm)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($dm);
$this->collection = $collection;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/PostFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@

namespace Doctrine\ODM\MongoDB\Event;

use Doctrine\Common\Persistence\ObjectManager;

/**
* Provides event arguments for the postFlush event.
*
* @final
* @since 1.0
*/
class PostFlushEventArgs extends ManagerEventArgs
{
public function __construct(ObjectManager $objectManager)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($objectManager);
}
}
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/PreFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@

namespace Doctrine\ODM\MongoDB\Event;

use Doctrine\Common\Persistence\ObjectManager;

/**
* Provides event arguments for the preFlush event.
*
* @final
* @since 1.0
*/
class PreFlushEventArgs extends ManagerEventArgs
{
public function __construct(ObjectManager $objectManager)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($objectManager);
}
}
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/PreLoadEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Class that holds event arguments for a preLoad event.
*
* @final
* @since 1.0
*/
class PreLoadEventArgs extends LifecycleEventArgs
Expand All @@ -42,6 +43,9 @@ class PreLoadEventArgs extends LifecycleEventArgs
*/
public function __construct($document, DocumentManager $dm, array &$data)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($document, $dm);
$this->data =& $data;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Class that holds event arguments for a preUpdate event.
*
* @final
* @since 1.0
*/
class PreUpdateEventArgs extends LifecycleEventArgs
Expand All @@ -42,6 +43,9 @@ class PreUpdateEventArgs extends LifecycleEventArgs
*/
public function __construct($document, DocumentManager $dm, array $changeSet)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($document, $dm);
$this->documentChangeSet = $changeSet;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Hydrator/HydratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@
namespace Doctrine\ODM\MongoDB\Hydrator;

use Doctrine\ODM\MongoDB\MongoDBException;
use Throwable;

/**
* MongoDB ODM Hydrator Exception
*
* @final
* @since 1.0
*/
class HydratorException extends MongoDBException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($message, $code, $previous);
}

public static function hydratorDirectoryNotWritable()
{
return new self('Your hydrator directory must be writable.');
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* The HydratorFactory class is responsible for instantiating a correct hydrator
* type based on document's ClassMetadata
*
* @final
* @since 1.0
*/
class HydratorFactory
Expand Down Expand Up @@ -97,6 +98,9 @@ class HydratorFactory
*/
public function __construct(DocumentManager $dm, EventManager $evm, $hydratorDir, $hydratorNs, $autoGenerate)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
if ( ! $hydratorDir) {
throw HydratorException::hydratorDirectoryRequired();
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Id/AlnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
* The character set used for ID generation can be explicitly set with the "chars" option (e.g. base36, etc.)
*
* @final
* @since 1.0
*/
class AlnumGenerator extends IncrementGenerator
Expand All @@ -46,6 +47,13 @@ class AlnumGenerator extends IncrementGenerator

protected $awkwardSafeChars = '0123456789BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz';

public function __construct()
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
}

/**
* Set padding on generated id
*
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Id/AutoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@
/**
* AutoGenerator generates a native MongoId
*
* @final
* @since 1.0
*/
class AutoGenerator extends AbstractIdGenerator
{
public function __construct()
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
}

/** @inheritDoc */
public function generate(DocumentManager $dm, $document)
{
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Id/IncrementGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* collection. If not specified it defaults to the name of the collection for the
* document.
*
* @final
* @since 1.0
*/
class IncrementGenerator extends AbstractIdGenerator
Expand All @@ -40,6 +41,13 @@ class IncrementGenerator extends AbstractIdGenerator
protected $key = null;
protected $startingId = 1;

public function __construct()
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
}

public function setCollection($collection)
{
$this->collection = $collection;
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Generates UUIDs.
*
* @final
* @since 1.0
*/
class UuidGenerator extends AbstractIdGenerator
Expand All @@ -35,6 +36,13 @@ class UuidGenerator extends AbstractIdGenerator
*/
protected $salt = null;

public function __construct()
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
}

/**
* Used to set the salt that will be applied to each id
*
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/LockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* LockException
*
* @final
* @since 1.0
*/
class LockException extends MongoDBException
Expand All @@ -30,6 +31,9 @@ class LockException extends MongoDBException

public function __construct($msg, $document = null)
{
if (self::class !== static::class) {
@trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
}
parent::__construct($msg);
$this->document = $document;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/LockMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* Contains all MongoDB ODM LockModes
*
* @final
* @since 1.0
*/
class LockMode
Expand Down
Loading