Skip to content

Commit

Permalink
Remove deprecations using Symfony 6.4 (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored Dec 9, 2023
1 parent 2a43549 commit 8a31e71
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 109 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
- "stable"
symfony-version:
- "5.4.*"
- "6.2.*"
- "6.3.*"
- "6.4.*"
driver-version:
- "stable"
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion CacheWarmer/HydratorCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function isOptional()
}

/** @return string[] */
public function warmUp(string $cacheDir)
public function warmUp(string $cacheDir, ?string $buildDir = null)
{
// we need the directory no matter the hydrator cache generation strategy.
$hydratorCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir');
Expand Down
2 changes: 1 addition & 1 deletion CacheWarmer/PersistentCollectionCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function isOptional()
}

/** @return string[] */
public function warmUp(string $cacheDir)
public function warmUp(string $cacheDir, ?string $buildDir = null)
{
// we need the directory no matter the hydrator cache generation strategy.
$collCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.persistent_collection_dir');
Expand Down
2 changes: 1 addition & 1 deletion CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function isOptional()
}

/** @return string[] */
public function warmUp(string $cacheDir)
public function warmUp(string $cacheDir, ?string $buildDir = null)
{
// we need the directory no matter the proxy cache generation strategy.
$proxyCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.proxy_dir');
Expand Down
10 changes: 8 additions & 2 deletions Command/TailCursorDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Throwable;

use function sleep;
Expand All @@ -28,7 +27,8 @@
*/
class TailCursorDoctrineODMCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;
/** @var ContainerInterface|null */
protected $container;

/** @return void */
protected function configure()
Expand Down Expand Up @@ -108,6 +108,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

/** @return void */
public function setContainer(?ContainerInterface $container = null)
{
$this->container = $container;
}

/** @return ContainerInterface|null */
protected function getContainer()
{
Expand Down
15 changes: 13 additions & 2 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,31 @@
use Doctrine\Bundle\MongoDBBundle\Fixture\FixtureGroupInterface;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Loader;
use LogicException;
use ReflectionClass;
use RuntimeException;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

use function array_key_exists;
use function array_values;
use function get_class;
use function sprintf;

final class SymfonyFixturesLoader extends ContainerAwareLoader implements SymfonyFixturesLoaderInterface
final class SymfonyFixturesLoader extends Loader implements SymfonyFixturesLoaderInterface
{
/** @var FixtureInterface[] */
private array $loadedFixtures = [];

/** @var array<string, array<string, bool>> */
private array $groupsFixtureMapping = [];

public function __construct(
private ContainerInterface $container,
) {
}

/**
* @internal
*
Expand Down Expand Up @@ -60,6 +67,10 @@ public function addFixture(FixtureInterface $fixture): void
$this->addGroupsFixtureMapping($class, $fixture::getGroups());
}

if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
}

parent::addFixture($fixture);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document(repositoryClass=TestCustomClassRepoRepository::class) */
#[ODM\Document(repositoryClass: TestCustomClassRepoRepository::class)]
class TestCustomClassRepoDocument
{
/** @ODM\Id */
#[ODM\Id]
private string $id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoDocumentRepository;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document(repositoryClass=TestCustomServiceRepoDocumentRepository::class) */
#[ODM\Document(repositoryClass: TestCustomServiceRepoDocumentRepository::class)]
class TestCustomServiceRepoDocument
{
/** @ODM\Id */
#[ODM\Id]
private string $id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoGridFSRepository;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\File(repositoryClass=TestCustomServiceRepoGridFSRepository::class) */
#[ODM\File(repositoryClass: TestCustomServiceRepoGridFSRepository::class)]
class TestCustomServiceRepoFile
{
/** @ODM\Id */
#[ODM\Id]
private string $id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

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

/** @ODM\Document */
#[ODM\Document]
class TestDefaultRepoDocument
{
/** @ODM\Id */
#[ODM\Id]
private string $id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

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

/** @ODM\File */
#[ODM\File]
class TestDefaultRepoFile
{
/** @ODM\Id */
#[ODM\Id]
private string $id;
}
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/Fixtures/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'default' => [
'mappings' => [
'RepositoryServiceBundle' => [
'type' => 'annotation',
'type' => 'attribute',
'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Document',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Document',
],
Expand Down
10 changes: 5 additions & 5 deletions Tests/Fixtures/Cache/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
#[ODM\Document]
class Collections
{
/** @ODM\Id */
#[ODM\Id]
public ?ObjectId $id = null;

/** @ODM\EmbedMany(collectionClass=SomeCollection::class) */
#[ODM\EmbedMany(collectionClass: SomeCollection::class)]
public SomeCollection $coll;

/** @ODM\ReferenceMany(collectionClass=SomeCollection::class) */
#[ODM\ReferenceMany(collectionClass: SomeCollection::class)]
public SomeCollection $refs;

/** @ODM\EmbedMany(collectionClass=AnotherCollection::class) */
#[ODM\EmbedMany(collectionClass: AnotherCollection::class)]
public AnotherCollection $another;
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/CommandBundle/Document/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

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

/** @ODM\Document */
#[ODM\Document]
class User
{
/** @ODM\Id */
#[ODM\Id]
private ?string $id = null;
}
7 changes: 4 additions & 3 deletions Tests/Fixtures/DataCollector/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\DataCollector;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Types\Type;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
#[ODM\Document]
class Category
{
/** @ODM\Id */
#[ODM\Id]
protected ?ObjectId $id = null;

/** @ODM\Field(type="string") */
#[ODM\Field(type: Type::STRING)]
public string $name;

public function __construct(string $name)
Expand Down
20 changes: 9 additions & 11 deletions Tests/Fixtures/Form/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Types\Type;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
#[ODM\Document]
class Category
{
/** @ODM\Id */
#[ODM\Id]
protected ObjectId|string|null $id;

/** @ODM\Field(type="string") */
#[ODM\Field(type: Type::STRING)]
public string $name;

/**
* @ODM\ReferenceMany(
* targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document",
* mappedBy="categories"
* )
*
* @var Collection<int, Document>
*/
/** @var Collection<int, Document> */
#[ODM\ReferenceMany(
targetDocument: Document::class,
mappedBy: 'categories',
)]
public Collection $documents;

public function __construct(string $name)
Expand Down
23 changes: 11 additions & 12 deletions Tests/Fixtures/Form/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Types\Type;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
#[ODM\Document]
class Document
{
/** @ODM\Id(strategy="none") */
#[ODM\Id(strategy: 'none')]
protected ObjectId $id;

/** @ODM\Field(type="string") */
#[ODM\Field(type: Type::STRING)]
public string $name;

/**
* @ODM\ReferenceMany(
* targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category",
* inversedBy="documents",
* strategy="atomicSetArray"
* )
*
* @var Collection<int, Category>
*/
/** @var Collection<int, Category> */
#[ODM\ReferenceMany(
targetDocument: Category::class,
inversedBy: 'documents',
strategy: ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
)]
public Collection $categories;

public function __construct(ObjectId $id, string $name)
Expand Down
40 changes: 18 additions & 22 deletions Tests/Fixtures/Form/Guesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,44 @@
use DateTime;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Types\Type;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
#[ODM\Document]
class Guesser
{
/** @ODM\Id(strategy="none") */
#[ODM\Id(strategy: 'none')]
protected ?ObjectId $id = null;

/** @ODM\Field() */
#[ODM\Field]
public ?string $name = null;

/** @ODM\Field(type="date") */
#[ODM\Field(type: Type::DATE)]
public ?DateTime $date = null;

/** @ODM\Field(type="timestamp") */
#[ODM\Field(type: Type::TIMESTAMP)]
public DateTime $ts;

/**
* @ODM\ReferenceMany(
* targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category",
* inversedBy="documents",
* strategy="atomicSetArray"
* )
*
* @var Collection<int, Category>
*/
/** @var Collection<int, Category> */
#[ODM\ReferenceMany(
targetDocument: Category::class,
inversedBy: 'documents',
strategy: ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
)]
public Collection $categories;

/** @ODM\Field(type="bool") */
#[ODM\Field(type: Type::BOOL)]
public ?bool $boolField = null;

/** @ODM\Field(type="float") */
#[ODM\Field(type: Type::FLOAT)]
public ?float $floatField = null;

/** @ODM\Field(type="int") */
#[ODM\Field(type: Type::INT)]
public ?int $intField = null;

/**
* @ODM\Field(type="collection")
*
* @var array
*/
/** @var array */
#[ODM\Field(type: Type::COLLECTION)]
public array $collectionField;

public mixed $nonMappedField;
Expand Down
7 changes: 4 additions & 3 deletions Tests/Fixtures/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Security;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Types\Type;
use MongoDB\BSON\ObjectId;
use Symfony\Component\Security\Core\User\UserInterface;

/** @ODM\Document */
#[ODM\Document]
class User implements UserInterface
{
/** @ODM\Id(strategy="none") */
#[ODM\Id(strategy: 'none')]
protected ObjectId $id;

/** @ODM\Field(type="string") */
#[ODM\Field(type: Type::STRING)]
public string $name;

public function __construct(ObjectId $id, string $name)
Expand Down
Loading

0 comments on commit 8a31e71

Please sign in to comment.