Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ on:

jobs:
coding-standards:
uses: "doctrine/.github/.github/workflows/coding-standards.yml@v12.2.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@13.0.0"
2 changes: 1 addition & 1 deletion .github/workflows/composer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
composer-lint:
name: "Composer Lint"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@v12.2.0"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@13.0.0"
12 changes: 6 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down Expand Up @@ -221,7 +221,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down Expand Up @@ -345,7 +345,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down Expand Up @@ -377,7 +377,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
documentation:
name: "Documentation"
uses: "doctrine/.github/.github/workflows/documentation.yml@v12.2.0"
uses: "doctrine/.github/.github/workflows/documentation.yml@13.0.0"
2 changes: 1 addition & 1 deletion .github/workflows/phpbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"
with:
fetch-depth: 2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
release:
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@v12.2.0"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@13.0.0"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: "Checkout code"
uses: "actions/checkout@v5"
uses: "actions/checkout@v6"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"doctrine/lexer": "^2 || ^3",
"doctrine/persistence": "^2.4 || ^3",
"psr/cache": "^1 || ^2 || ^3",
"symfony/console": "^4.2 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.2 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php80": "^1.16"
},
Expand All @@ -60,7 +60,7 @@
"psr/log": "^1 || ^2 || ^3",
"symfony/cache": "^4.4 || ^5.4 || ^6.4 || ^7.0",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6.2 || ^7.0",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
"symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 3.0"
Expand Down
15 changes: 15 additions & 0 deletions docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ Here is a complete list of ``Column``s attributes (all optional):
- ``options``: Key-value pairs of options that get passed
to the underlying database platform when generating DDL statements.

Specifying default values
~~~~~~~~~~~~~~~~~~~~~~~~~

While it is possible to specify default values for properties in your
PHP class, Doctrine also allows you to specify default values for
database columns using the ``default`` key in the ``options`` array of
the ``Column`` attribute.

.. configuration-block::
.. literalinclude:: basic-mapping/DefaultValues.php
:language: attribute

.. literalinclude:: basic-mapping/default-values.xml
:language: xml

.. _reference-php-mapping-types:

PHP Types Mapping
Expand Down
15 changes: 15 additions & 0 deletions docs/en/reference/basic-mapping/DefaultValues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;

#[Entity]
class Message
{
#[Column(options: ['default' => 'Hello World!'])]
private string $text;
}
9 changes: 9 additions & 0 deletions docs/en/reference/basic-mapping/default-values.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<doctrine-mapping>
<entity name="Message">
<field name="text">
<options>
<option name="default">Hello World!</option>
</options>
</field>
</entity>
</doctrine-mapping>
24 changes: 0 additions & 24 deletions docs/en/reference/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,6 @@ In your mapping configuration, the column definition (for example, the
the ``charset`` and ``collation``. The default values are ``utf8`` and
``utf8_unicode_ci``, respectively.

Entity Classes
--------------

How can I add default values to a column?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Doctrine does not support to set the default values in columns through the "DEFAULT" keyword in SQL.
This is not necessary however, you can just use your class properties as default values. These are then used
upon insert:

.. code-block:: php

class User
{
private const STATUS_DISABLED = 0;
private const STATUS_ENABLED = 1;

private string $algorithm = "sha1";
/** @var self::STATUS_* */
private int $status = self::STATUS_DISABLED;
}

.

Mapping
-------

Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ public function setLazyGhostObjectEnabled(bool $flag): void
if ($flag && ! trait_exists(LazyGhostTrait::class)) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
. ' version 6.2 or higher is not installed. Please run "composer require symfony/var-exporter:^6.2".'
. ' version 6.2 or 7 is not installed. Please run "composer require symfony/var-exporter:^6.4".'
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Tools/Console/ApplicationCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ trait ApplicationCompatibility
{
private static function addCommandToApplication(Application $application, Command $command): ?Command
{
// @phpstan-ignore function.alreadyNarrowedType (This method did not exist before Symfony 7.4)
if (method_exists(Application::class, 'addCommand')) {
// @phpstan-ignore method.notFound (This method will be added in Symfony 7.4)
return $application->addCommand($command);
}

// @phpstan-ignore method.notFound
return $application->add($command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class CollectionRegionCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:region:collection')
->setDescription('Clear a second-level cache collection region')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ClearCache/EntityRegionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class EntityRegionCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:region:entity')
->setDescription('Clear a second-level cache entity region')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ClearCache/MetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class MetadataCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:metadata')
->setDescription('Clear all metadata cache of the various cache drivers')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class QueryCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:query')
->setDescription('Clear all query cache of the various cache drivers')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ClearCache/QueryRegionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class QueryRegionCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:region:query')
->setDescription('Clear a second-level cache query region')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ClearCache/ResultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ResultCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:clear-cache:result')
->setDescription('Clear all result cache of the various cache drivers')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public function setMetadataExporter(ClassMetadataExporter $metadataExporter)
$this->metadataExporter = $metadataExporter;
}

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:convert-d1-schema')
->setAliases(['orm:convert:d1-schema'])
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/ConvertMappingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class ConvertMappingCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:convert-mapping')
->setAliases(['orm:convert:mapping'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class EnsureProductionSettingsCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:ensure-production-settings')
->setDescription('Verify that Doctrine is properly configured for a production environment')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/GenerateEntitiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class GenerateEntitiesCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:generate-entities')
->setAliases(['orm:generate:entities'])
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/GenerateProxiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class GenerateProxiesCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:generate-proxies')
->setAliases(['orm:generate:proxies'])
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/GenerateRepositoriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class GenerateRepositoriesCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:generate-repositories')
->setAliases(['orm:generate:repositories'])
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class InfoCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:info')
->setDescription('Show basic information about all mapped entities')
Expand Down
3 changes: 1 addition & 2 deletions src/Tools/Console/Command/RunDqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class RunDqlCommand extends AbstractEntityManagerCommand
{
use CommandCompatibility;

/** @return void */
protected function configure()
private function doConfigure(): void
{
$this->setName('orm:run-dql')
->setDescription('Executes arbitrary DQL directly from the command line')
Expand Down
4 changes: 4 additions & 0 deletions src/Tools/Console/Command/SchemaTool/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ abstract class AbstractCommand extends AbstractEntityManagerCommand
*/
abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui);

private function doConfigure(): void
{
}

private function doExecute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);
Expand Down
Loading