Skip to content

Commit

Permalink
Use NamedArgumentConstructorAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Nov 9, 2020
1 parent 9992f2a commit 45bfb60
Show file tree
Hide file tree
Showing 45 changed files with 473 additions and 180 deletions.
13 changes: 12 additions & 1 deletion UPGRADE-2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ to the `Query` class.
The `Doctrine\ODM\MongoDB\Aggregation\Builder::execute()` method was deprecated
and will be removed in ODM 3.0.

## Document indexes (annotations)
## Aannotations

### Base class

All ODM's annotations no longer extend the `Doctrine\Common\Annotations\Annotation`
class and may require passing arguments to their constructors.

### `@Indexes`

Using `@Index` annotation(s) on a class level is a preferred way for defining
indexes for documents. Using `@Index` in the `@Indexes` annotation or an `indexes`
property of other annotations was deprecated and will be removed in ODM 3.0.

### `@Inheritance`

The annotation class served no purpose and was removed.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^7.2",
"ext-mongodb": "^1.5",
"doctrine/annotations": "^1.6",
"doctrine/annotations": "^1.11",
"doctrine/cache": "^1.7",
"doctrine/collections": "^1.5",
"doctrine/event-manager": "^1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;

abstract class AbstractDocument extends Annotation
abstract class AbstractDocument
{
}
30 changes: 23 additions & 7 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,44 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use function sprintf;

abstract class AbstractField extends Annotation
abstract class AbstractField implements NamedArgumentConstructorAnnotation
{
/** @var string */
public $name;

/** @var string */
public $type = 'string';
/** @var string|null */
public $type;

/** @var bool */
public $nullable = false;
public $nullable;

/** @var mixed[] */
public $options = [];
public $options;

/** @var string|null */
public $strategy;

/** @var bool */
public $notSaved = false;
public $notSaved;

public function __construct(
?string $name = null,
?string $type = 'string',
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = false
) {
$this->name = $name;
$this->type = $type;
$this->nullable = $nullable;
$this->options = $options;
$this->strategy = $strategy;
$this->notSaved = $notSaved;
}

/**
* Gets deprecation message. The method *WILL* be removed in 2.0.
Expand Down
36 changes: 29 additions & 7 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

abstract class AbstractIndex extends Annotation
abstract class AbstractIndex implements NamedArgumentConstructorAnnotation
{
/** @var string[] */
public $keys = [];
public $keys;

/** @var string */
public $name;
Expand All @@ -24,14 +24,36 @@ abstract class AbstractIndex extends Annotation
public $order;

/** @var bool */
public $unique = false;
public $unique;

/** @var bool */
public $sparse = false;
public $sparse;

/** @var mixed[] */
public $options = [];
public $options;

/** @var array */
public $partialFilterExpression = [];
public $partialFilterExpression;

public function __construct(
array $keys = [],
?string $name = null,
?bool $background = null,
?int $expireAfterSeconds = null,
$order = null,
bool $unique = false,
bool $sparse = false,
array $options = [],
array $partialFilterExpression = []
) {
$this->keys = $keys;
$this->name = $name;
$this->background = $background;
$this->expireAfterSeconds = $expireAfterSeconds;
$this->order = $order;
$this->unique = $unique;
$this->sparse = $sparse;
$this->options = $options;
$this->partialFilterExpression = $partialFilterExpression;
}
}
15 changes: 12 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AlsoLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Loads data from a different field if the original field is not set
*
* @Annotation
*/
final class AlsoLoad extends Annotation
final class AlsoLoad implements NamedArgumentConstructorAnnotation
{
/** @var string */
/** @var string|string[] */
public $value;

/** @var string|null */
public $name;

public function __construct($value, ?string $name = null)
{
$this->value = $value;
$this->name = $name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Specifies the change tracking policy for a document
*
* @Annotation
*/
final class ChangeTrackingPolicy extends Annotation
final class ChangeTrackingPolicy implements NamedArgumentConstructorAnnotation
{
/** @var string */
public $value;

public function __construct(string $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Specifies a default discriminator value to be used when the discriminator
* field is not set in a document
*
* @Annotation
*/
final class DefaultDiscriminatorValue extends Annotation
final class DefaultDiscriminatorValue implements NamedArgumentConstructorAnnotation
{
/** @var string */
public $value;

public function __construct(string $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Specify a field name to store a discriminator value
*
* @Annotation
*/
final class DiscriminatorField extends Annotation
final class DiscriminatorField implements NamedArgumentConstructorAnnotation
{
/** @var string */
public $value;

public function __construct(string $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Specify a map of discriminator values and classes
*
* @Annotation
*/
final class DiscriminatorMap extends Annotation
final class DiscriminatorMap implements NamedArgumentConstructorAnnotation
{
/** @var string[] */
public $value;

public function __construct(array $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Use the specified discriminator for this class
*
* @Annotation
*/
final class DiscriminatorValue extends Annotation
final class DiscriminatorValue implements NamedArgumentConstructorAnnotation
{
/** @var string */
public $value;

public function __construct(string $value)
{
$this->value = $value;
}
}
24 changes: 22 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
* Identifies a class as a document that can be stored in the database
*
* @Annotation
*/
final class Document extends AbstractDocument
final class Document extends AbstractDocument implements NamedArgumentConstructorAnnotation
{
/** @var string|null */
public $db;

/** @var string|null */
/** @var array|string|null */
public $collection;

/** @var string|null */
Expand All @@ -31,4 +33,22 @@ final class Document extends AbstractDocument

/** @var string|int|null */
public $writeConcern;

public function __construct(
?string $db = null,
$collection = null,
?string $repositoryClass = null,
array $indexes = [],
bool $readOnly = false,
?string $shardKey = null,
$writeConcern = null
) {
$this->db = $db;
$this->collection = $collection;
$this->repositoryClass = $repositoryClass;
$this->indexes = $indexes;
$this->readOnly = $readOnly;
$this->shardKey = $shardKey;
$this->writeConcern = $writeConcern;
}
}
28 changes: 22 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/EmbedMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;

/**
Expand All @@ -13,9 +14,6 @@
*/
final class EmbedMany extends AbstractField
{
/** @var string */
public $type = 'many';

/** @var bool */
public $embedded = true;

Expand All @@ -31,9 +29,27 @@ final class EmbedMany extends AbstractField
/** @var string|null */
public $defaultDiscriminatorValue;

/** @var string */
public $strategy = CollectionHelper::DEFAULT_STRATEGY;

/** @var string|null */
public $collectionClass;

public function __construct(
?string $name = null,
bool $nullable = false,
array $options = [],
string $strategy = CollectionHelper::DEFAULT_STRATEGY,
bool $notSaved = false,
?string $targetDocument = null,
?string $discriminatorField = null,
?array $discriminatorMap = null,
?string $defaultDiscriminatorValue = null,
?string $collectionClass = null
) {
parent::__construct($name, ClassMetadata::MANY, $nullable, $options, $strategy, $notSaved);

$this->targetDocument = $targetDocument;
$this->discriminatorField = $discriminatorField;
$this->discriminatorMap = $discriminatorMap;
$this->defaultDiscriminatorValue = $defaultDiscriminatorValue;
$this->collectionClass = $collectionClass;
}
}
Loading

0 comments on commit 45bfb60

Please sign in to comment.