Skip to content

Commit

Permalink
Merge branch '2.13.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.13.x:
  Allow doctrine/deprecations 1.0 (doctrine#9723)
  Allow setting column options like `charset` and `collation` everywhere (doctrine#9655)
  Fix psalm annotation
  • Loading branch information
derrabus committed May 5, 2022
2 parents 7e83c92 + 05560f2 commit ee83302
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"doctrine/collections": "^1.5",
"doctrine/common": "^3.3",
"doctrine/dbal": "^3.3",
"doctrine/deprecations": "^0.5.3",
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/instantiator": "^1.3",
Expand Down
4 changes: 4 additions & 0 deletions docs/en/reference/attributes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ Optional parameters:
- ``comment``: The comment of the column in the schema (might not
be supported by all vendors).

- ``charset``: The charset of the column (only supported by Mysql, PostgreSQL, Sqlite and SQLServer).

- ``collation``: The collation of the column (only supported by Mysql, PostgreSQL, Sqlite and SQLServer).

- ``check``: Adds a check constraint type to the column (might not
Expand Down Expand Up @@ -681,6 +683,8 @@ Optional parameters:
"columnDefinition" attribute on :ref:`#[Column] <attrref_column>` also sets
the related ``#[JoinColumn]``'s columnDefinition. This is necessary to
make foreign keys work.
- **options**:
See "options" attribute on :ref:`#[Column] <attrref_column>`.

Example:

Expand Down
15 changes: 13 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ private function loadRelationShipMapping(
'schema' => $joinTableAnnot->schema,
];

if ($joinTableAnnot->options) {
$joinTable['options'] = $joinTableAnnot->options;
}

foreach ($joinTableAnnot->joinColumns as $joinColumn) {
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
}
Expand Down Expand Up @@ -699,19 +703,26 @@ private function getMethodCallbacks(ReflectionMethod $method): array
* nullable: bool,
* onDelete: mixed,
* columnDefinition: string|null,
* referencedColumnName: string
* referencedColumnName: string,
* options?: array<string, mixed>
* }
*/
private function joinColumnToArray(Mapping\JoinColumn $joinColumn): array
{
return [
$mapping = [
'name' => $joinColumn->name,
'unique' => $joinColumn->unique,
'nullable' => $joinColumn->nullable,
'onDelete' => $joinColumn->onDelete,
'columnDefinition' => $joinColumn->columnDefinition,
'referencedColumnName' => $joinColumn->referencedColumnName,
];

if ($joinColumn->options) {
$mapping['options'] = $joinColumn->options;
}

return $mapping;
}

/**
Expand Down
15 changes: 13 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
'name' => $joinTableAttribute->name,
'schema' => $joinTableAttribute->schema,
];

if ($joinTableAttribute->options) {
$joinTable['options'] = $joinTableAttribute->options;
}
}

foreach ($this->reader->getPropertyAnnotationCollection($property, Mapping\JoinColumn::class) as $joinColumn) {
Expand Down Expand Up @@ -640,19 +644,26 @@ private function getMethodCallbacks(ReflectionMethod $method): array
* nullable: bool,
* onDelete: mixed,
* columnDefinition: string|null,
* referencedColumnName: string
* referencedColumnName: string,
* options?: array<string, mixed>
* }
*/
private function joinColumnToArray($joinColumn): array
{
return [
$mapping = [
'name' => $joinColumn->name,
'unique' => $joinColumn->unique,
'nullable' => $joinColumn->nullable,
'onDelete' => $joinColumn->onDelete,
'columnDefinition' => $joinColumn->columnDefinition,
'referencedColumnName' => $joinColumn->referencedColumnName,
];

if ($joinColumn->options) {
$mapping['options'] = $joinColumn->options;
}

return $mapping;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
$joinTable['schema'] = (string) $joinTableElement['schema'];
}

if (isset($joinTableElement->options)) {
$joinTable['options'] = $this->parseOptions($joinTableElement->options->children());
}

foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
}
Expand Down Expand Up @@ -669,6 +673,10 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
'schema' => (string) $joinTableElement['schema'],
];

if (isset($joinTableElement->options)) {
$joinTable['options'] = $this->parseOptions($joinTableElement->options->children());
}

if (isset($joinTableElement->{'join-columns'})) {
foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
Expand Down Expand Up @@ -773,7 +781,8 @@ private function parseOptions(SimpleXMLElement $options): array
* unique?: bool,
* nullable?: bool,
* onDelete?: string,
* columnDefinition?: string
* columnDefinition?: string,
* options?: mixed[]
* }
*/
private function joinColumnToArray(SimpleXMLElement $joinColumnElement): array
Expand All @@ -799,6 +808,10 @@ private function joinColumnToArray(SimpleXMLElement $joinColumnElement): array
$joinColumn['columnDefinition'] = (string) $joinColumnElement['column-definition'];
}

if (isset($joinColumnElement['options'])) {
$joinColumn['options'] = $this->parseOptions($joinColumnElement['options']->children());
}

return $joinColumn;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Mapping/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
* @Annotation
* @NamedArgumentConstructor()
* @Target("CLASS")
* @template T of object
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class Entity implements Annotation
{
/**
* @var string|null
* @psalm-var class-string<EntityRepository>|null
* @psalm-var class-string<EntityRepository<T>>|null
*/
public $repositoryClass;

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

/**
* @psalm-param class-string<EntityRepository>|null $repositoryClass
* @psalm-param class-string<EntityRepository<T>>|null $repositoryClass
*/
public function __construct(?string $repositoryClass = null, bool $readOnly = false)
{
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Mapping/InverseJoinColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ final class InverseJoinColumn implements Annotation
*/
public $fieldName;

/** @var array<string, mixed> */
public $options = [];

/**
* @param array<string, mixed> $options
*/
public function __construct(
?string $name = null,
string $referencedColumnName = 'id',
bool $unique = false,
bool $nullable = true,
$onDelete = null,
?string $columnDefinition = null,
?string $fieldName = null
?string $fieldName = null,
array $options = []
) {
$this->name = $name;
$this->referencedColumnName = $referencedColumnName;
Expand All @@ -51,5 +58,6 @@ public function __construct(
$this->onDelete = $onDelete;
$this->columnDefinition = $columnDefinition;
$this->fieldName = $fieldName;
$this->options = $options;
}
}
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Mapping/JoinColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ final class JoinColumn implements Annotation
*/
public $fieldName;

/** @var array<string, mixed> */
public $options = [];

/**
* @param array<string, mixed> $options
*/
public function __construct(
?string $name = null,
string $referencedColumnName = 'id',
bool $unique = false,
bool $nullable = true,
$onDelete = null,
?string $columnDefinition = null,
?string $fieldName = null
?string $fieldName = null,
array $options = []
) {
$this->name = $name;
$this->referencedColumnName = $referencedColumnName;
Expand All @@ -56,5 +63,6 @@ public function __construct(
$this->onDelete = $onDelete;
$this->columnDefinition = $columnDefinition;
$this->fieldName = $fieldName;
$this->options = $options;
}
}
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Mapping/JoinTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ final class JoinTable implements Annotation
/** @var array<\Doctrine\ORM\Mapping\JoinColumn> */
public $inverseJoinColumns = [];

/** @var array<string, mixed> */
public $options = [];

/**
* @param array<string, mixed> $options
*/
public function __construct(
?string $name = null,
?string $schema = null,
$joinColumns = [],
$inverseJoinColumns = []
$inverseJoinColumns = [],
array $options = []
) {
$this->name = $name;
$this->schema = $schema;
$this->joinColumns = $joinColumns instanceof JoinColumn ? [$joinColumns] : $joinColumns;
$this->inverseJoinColumns = $inverseJoinColumns instanceof JoinColumn
? [$inverseJoinColumns]
: $inverseJoinColumns;
$this->options = $options;
}
}
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ private function gatherRelationsSql(
$this->quoteStrategy->getJoinTableName($mapping, $foreignClass, $this->platform)
);

if (isset($joinTable['options'])) {
foreach ($joinTable['options'] as $key => $val) {
$theJoinTable->addOption($key, $val);
}
}

$primaryKeyColumns = [];

// Build first FK constraint (relation table => source table)
Expand Down Expand Up @@ -723,6 +729,8 @@ private function gatherRelationJoinColumns(
$columnOptions['precision'] = $fieldMapping['precision'];
}

$columnOptions = $this->gatherColumnOptions($joinColumn) + $columnOptions;

$theJoinTable->addColumn($quotedColumnName, $fieldMapping['type'], $columnOptions);
}

Expand Down

0 comments on commit ee83302

Please sign in to comment.