Skip to content

Commit

Permalink
[FrameworkExtraBundle] Support for odm/orm manager registry
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jan 2, 2024
1 parent 9df6077 commit 046b885
Show file tree
Hide file tree
Showing 14 changed files with 634 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen

#MONGODB
RUN pecl install mongodb 1.17.2 && docker-php-ext-enable mongodb

ARG PUID=1000
ARG PGID=1000

Expand Down
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ ENTITY_MIGRATOR_LOCK_DSN=flock
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=flock
###< symfony/lock ###

###> doctrine/mongodb-odm-bundle ###
MONGODB_URL=mongodb://draw_mongodb
MONGODB_DB=symfony
###< doctrine/mongodb-odm-bundle ###
30 changes: 30 additions & 0 deletions app/src/Controller/Api/TestDocumentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Controller\Api;

use App\Document\TestDocument;
use Doctrine\Persistence\ManagerRegistry;
use Draw\Component\OpenApi\Request\ValueResolver\RequestBody;
use Symfony\Component\Routing\Attribute\Route;

#[Route('/test-documents', name: 'testDocument')]
class TestDocumentController
{
public function __construct(private ManagerRegistry $odmManagerRegistry)
{
}

#[Route(name: 'Create', methods: ['POST'])]
public function create(
#[RequestBody]
TestDocument $testDocument,
): TestDocument {
$manager = $this->odmManagerRegistry->getManagerForClass(TestDocument::class);

$manager->persist($testDocument);

$manager->flush();

return $testDocument;
}
}
12 changes: 12 additions & 0 deletions app/src/Document/TestDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\Document]
class TestDocument
{
#[ODM\Id]
public string $id;
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-mongodb": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"aws/aws-sdk-php": "^3.171",
Expand Down Expand Up @@ -56,7 +57,8 @@
"symfony/yaml": "^6.4.0",
"twig/twig": "^3.3",
"friendsofphp/php-cs-fixer": "^3.13",
"nesbot/carbon": "^2.0"
"nesbot/carbon": "^2.0",
"doctrine/mongodb-odm-bundle": "*"
},
"require-dev": {
"ext-pcntl": "*",
Expand Down
Loading

0 comments on commit 046b885

Please sign in to comment.