Skip to content

New Command: make:document #1330

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1940346
New Command: `make:document` to generate document classes for `doctri…
constantable Jun 28, 2023
4d429ab
LF
constantable Jun 28, 2023
53cf817
Downgrade mongodb service to 4.4 and remove healthchecks
constantable Jun 28, 2023
0b2b0da
Fix coding standards
constantable Jun 28, 2023
a20beab
Handle mongodb in the AppVeyor
constantable Jun 28, 2023
0a6c3c3
Download mongodb PHP extension from GitHub
constantable Jun 28, 2023
1478ed6
Download mongodb PHP extension from GitHub
constantable Jun 28, 2023
06c8a5c
Fix the php_mongodb.dll ext
constantable Jun 28, 2023
3a6cab3
Switch to the non thread safe version of the ext-mongodb
constantable Jun 29, 2023
8a09a7a
Prevent cache AppVeyor
constantable Jun 29, 2023
bd4da81
Prevent cache AppVeyor
constantable Jun 29, 2023
14608eb
Merge branch 'symfony:main' into main
constantable Jul 10, 2023
5fdb3fe
Save and remove repository methods removed, to keep in sync with #132…
constantable Jul 11, 2023
4bae9f6
Support for embedded documents
constantable Jul 30, 2023
f283e97
Add extra line to meet Coding Standards
constantable Jul 30, 2023
95f00b5
Do not allow to embed a class that is not EmbeddedDocument. Print the…
constantable Aug 8, 2023
d098ef0
Merge branch 'main' into make-document
constantable Sep 12, 2023
e5b23ba
Merge branch 'symfony:main' into make-document
constantable Sep 28, 2023
69c8734
Update appveyor to use php_mongodb-1.15.3-8.1 extension
constantable Sep 28, 2023
b9da241
Skip makeDocument tests for Symfony 7
constantable Oct 1, 2023
3967b92
Merge branch 'symfony:main' into make-document
constantable Nov 11, 2023
b89bf81
Merge branch 'symfony:main' into make-document
constantable Dec 9, 2023
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ jobs:
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mongodb:
image: mongo:4.4
env:
MONGO_INITDB_ROOT_USERNAME: test
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: test_maker
ports:
- 27017:27017
mercure:
image: dunglas/mercure
env:
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cache:

services:
- mysql
- mongodb

init:
- SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH%
Expand All @@ -25,6 +26,7 @@ init:

environment:
TEST_DATABASE_DSN: mysql://root:[email protected]:3306/test_maker
TEST_MONGODB_URL: mongodb://127.0.0.1:27017
matrix:
- dependencies: highest
php_ver_target: 8.1.23
Expand All @@ -50,6 +52,9 @@ install:
- IF %PHP%==0 echo extension=php_curl.dll >> php.ini
- IF %PHP%==0 echo extension=php_pdo_mysql.dll >> php.ini
- echo extension=php_pdo_sqlite.dll >> php.ini
- echo extension=php_mongodb.dll >> php.ini
- appveyor-retry appveyor DownloadFile https://github.com/mongodb/mongo-php-driver/releases/download/1.15.3/php_mongodb-1.15.3-8.1-nts-x64.zip
- 7z e -y -oext php_mongodb-1.15.3-8.1-nts-x64.zip
- IF %PHP%==0 echo @php %%~dp0composer.phar %%* > composer.bat
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer-stable.phar
- del composer.phar
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"require-dev": {
"composer/semver": "^3.0",
"doctrine/doctrine-bundle": "^2.5.0",
"doctrine/mongodb-odm-bundle": "^4.4",
"doctrine/orm": "^2.10.0",
"symfony/http-client": "^6.3|^7.0",
"symfony/phpunit-bridge": "^6.3|^7.0",
Expand Down
12 changes: 7 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
Expand All @@ -12,6 +12,8 @@
<php>
<ini name="error_reporting" value="-1" />
<env name="TEST_DATABASE_DSN" value="mysql://root:[email protected]:3306/test_maker?serverVersion=5.7" />
<env name="TEST_MONGODB_URL" value="mongodb://test:[email protected]:27017" />
<env name="TEST_MONGODB_DB" value="test_maker" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
</php>

Expand All @@ -27,9 +29,9 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class SetDoctrineODMAnnotatedPrefixesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$annotatedPrefixes = null;
foreach ($container->findTaggedServiceIds('doctrine.odm.configuration') as $id => $tags) {
$metadataDriverImpl = null;
foreach ($container->getDefinition($id)->getMethodCalls() as [$method, $arguments]) {
if ('setMetadataDriverImpl' === $method) {
$metadataDriverImpl = $container->getDefinition($arguments[0]);
break;
}
}

if (null === $metadataDriverImpl || !preg_match('/^doctrine_mongodb\.odm\.(.+)_configuration$/D', $id, $m)) {
continue;
}

$managerName = $m[1];
$methodCalls = $metadataDriverImpl->getMethodCalls();

foreach ($methodCalls as $i => [$method, $arguments]) {
if ('addDriver' !== $method) {
continue;
}

if ($arguments[0] instanceof Definition) {
$class = $arguments[0]->getClass();
$namespace = substr($class, 0, strrpos($class, '\\'));

$id = sprintf('.%d_doctrine_metadata_driver~%s', $i, ContainerBuilder::hash($arguments));
$container->setDefinition($id, $arguments[0]);
$arguments[0] = new Reference($id);
$methodCalls[$i] = [$method, $arguments];
}

$annotatedPrefixes[$managerName][] = [
$arguments[1],
new Reference($arguments[0]),
];
}

$metadataDriverImpl->setMethodCalls($methodCalls);
}

if (null !== $annotatedPrefixes) {
$container->getDefinition('maker.doctrine_odm_helper')->setArgument(2, $annotatedPrefixes);
}
}
}
3 changes: 3 additions & 0 deletions src/DependencyInjection/MakerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function load(array $configs, ContainerBuilder $container): void
$doctrineHelperDefinition = $container->getDefinition('maker.doctrine_helper');
$doctrineHelperDefinition->replaceArgument(0, $rootNamespace.'\\Entity');

$doctrineODMHelperDefinition = $container->getDefinition('maker.doctrine_odm_helper');
$doctrineODMHelperDefinition->replaceArgument(0, $rootNamespace.'\\Document');

$container->registerForAutoconfiguration(MakerInterface::class)
->addTag(MakeCommandRegistrationPass::MAKER_TAG);
}
Expand Down
30 changes: 30 additions & 0 deletions src/Doctrine/BaseCollectionEmbed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

use Symfony\Bundle\MakerBundle\Str;

/**
* @internal
*/
abstract class BaseCollectionEmbed extends BaseEmbed
{
public function getAdderMethodName(): string
{
return 'add'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}

public function getRemoverMethodName(): string
{
return 'remove'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}
}
32 changes: 32 additions & 0 deletions src/Doctrine/BaseCollectionReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

use Symfony\Bundle\MakerBundle\Str;

/**
* @internal
*/
abstract class BaseCollectionReference extends BaseReference
{
abstract public function getTargetSetterMethodName(): string;

public function getAdderMethodName(): string
{
return 'add'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}

public function getRemoverMethodName(): string
{
return 'remove'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}
}
40 changes: 40 additions & 0 deletions src/Doctrine/BaseEmbed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

/**
* @internal
*/
abstract class BaseEmbed
{
public function __construct(
private string $propertyName,
private string $targetClassName,
private bool $isNullable = false,
) {
}

public function getPropertyName(): string
{
return $this->propertyName;
}

public function getTargetClassName(): string
{
return $this->targetClassName;
}

public function isNullable(): bool
{
return $this->isNullable;
}
}
88 changes: 88 additions & 0 deletions src/Doctrine/BaseReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

/**
* @internal
*/
abstract class BaseReference
{
public function __construct(
private string $propertyName,
private string $targetDocument,
private ?string $targetPropertyName = null,
private bool $isSelfReferencing = false,
private bool $mapInverseRelation = true,
private bool $avoidSetter = false,
private bool $isCustomReturnTypeNullable = false,
private ?string $customReturnType = null,
private bool $isOwning = false,
private bool $orphanRemoval = false,
private bool $isNullable = false,
) {
}

public function getPropertyName(): string
{
return $this->propertyName;
}

public function getTargetDocument(): string
{
return $this->targetDocument;
}

public function getTargetPropertyName(): ?string
{
return $this->targetPropertyName;
}

public function isSelfReferencing(): bool
{
return $this->isSelfReferencing;
}

public function getMapInverseRelation(): bool
{
return $this->mapInverseRelation;
}

public function shouldAvoidSetter(): bool
{
return $this->avoidSetter;
}

public function getCustomReturnType(): ?string
{
return $this->customReturnType;
}

public function isCustomReturnTypeNullable(): bool
{
return $this->isCustomReturnTypeNullable;
}

public function isOwning(): bool
{
return $this->isOwning;
}

public function getOrphanRemoval(): bool
{
return $this->orphanRemoval;
}

public function isNullable(): bool
{
return $this->isNullable;
}
}
Loading