1414use Doctrine \ODM \MongoDB \PersistentCollection \DefaultPersistentCollectionGenerator ;
1515use Doctrine \ODM \MongoDB \PersistentCollection \PersistentCollectionFactory ;
1616use Doctrine \ODM \MongoDB \PersistentCollection \PersistentCollectionGenerator ;
17- use Doctrine \ODM \MongoDB \Proxy \FileLocator ;
1817use Doctrine \ODM \MongoDB \Repository \DefaultGridFSRepository ;
1918use Doctrine \ODM \MongoDB \Repository \DefaultRepositoryFactory ;
2019use Doctrine \ODM \MongoDB \Repository \DocumentRepository ;
2120use Doctrine \ODM \MongoDB \Repository \GridFSRepository ;
2221use Doctrine \ODM \MongoDB \Repository \RepositoryFactory ;
2322use Doctrine \Persistence \Mapping \Driver \MappingDriver ;
2423use Doctrine \Persistence \ObjectRepository ;
25- use InvalidArgumentException ;
26- use LogicException ;
2724use MongoDB \Client ;
2825use MongoDB \Driver \Manager ;
2926use MongoDB \Driver \WriteConcern ;
30- use ProxyManager \Configuration as ProxyManagerConfiguration ;
31- use ProxyManager \Factory \LazyLoadingGhostFactory ;
32- use ProxyManager \GeneratorStrategy \EvaluatingGeneratorStrategy ;
33- use ProxyManager \GeneratorStrategy \FileWriterGeneratorStrategy ;
3427use Psr \Cache \CacheItemPoolInterface ;
3528use ReflectionClass ;
3629use stdClass ;
37- use Symfony \Component \VarExporter \LazyGhostTrait ;
3830use Throwable ;
3931
4032use function array_diff_key ;
4133use function array_intersect_key ;
4234use function array_key_exists ;
43- use function class_exists ;
4435use function interface_exists ;
4536use function is_string ;
46- use function trait_exists ;
4737use function trigger_deprecation ;
4838use function trim ;
4939
6353class Configuration
6454{
6555 /**
66- * Never autogenerate a proxy/hydrator/persistent collection and rely that
67- * it was generated by some process before deployment. Copied from
68- * \Doctrine\Common\Proxy\AbstractProxyFactory.
56+ * Never autogenerate a hydrator/persistent collection and rely that
57+ * it was generated by some process before deployment.
6958 */
7059 public const int AUTOGENERATE_NEVER = 0 ;
7160
7261 /**
73- * Always generates a new proxy/ hydrator/persistent collection in every request.
62+ * Always generates a new hydrator/persistent collection in every request.
7463 *
7564 * This is only sane during development.
76- * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory.
7765 */
7866 public const int AUTOGENERATE_ALWAYS = 1 ;
7967
8068 /**
81- * Autogenerate the proxy/ hydrator/persistent collection class when the file does not exist.
69+ * Autogenerate the hydrator/persistent collection class when the file does not exist.
8270 *
83- * This strategy causes a file exists call whenever any proxy/ hydrator is used the
84- * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory.
71+ * This strategy causes a file exists call whenever any hydrator is used the
72+ * first time in a request.
8573 */
8674 public const int AUTOGENERATE_FILE_NOT_EXISTS = 2 ;
8775
8876 /**
89- * Generate the proxy/ hydrator/persistent collection classes using eval().
77+ * Generate the hydrator/persistent collection classes using eval().
9078 *
9179 * This strategy is only sane for development.
92- * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory.
9380 */
9481 public const int AUTOGENERATE_EVAL = 3 ;
9582
9683 /**
97- * Autogenerate the proxy class when the proxy file does not exist or
84+ * Autogenerate the class when the file does not exist or
9885 * when the proxied file changed.
9986 *
100- * This strategy causes a file_exists() call whenever any proxy is used the
101- * first time in a request. When the proxied file is changed, the proxy will
87+ * This strategy causes a file_exists() call whenever any class is used the
88+ * first time in a request. When the proxied file is changed, the class will
10289 * be updated.
10390 */
10491 public const int AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED = 4 ;
@@ -109,7 +96,6 @@ class Configuration
10996 * @phpstan-var array{
11097 * autoGenerateHydratorClasses?: self::AUTOGENERATE_*,
11198 * autoGeneratePersistentCollectionClasses?: self::AUTOGENERATE_*,
112- * autoGenerateProxyClasses?: self::AUTOGENERATE_*,
11399 * classMetadataFactoryName?: class-string<ClassMetadataFactoryInterface>,
114100 * defaultCommitOptions?: CommitOptions,
115101 * defaultDocumentRepositoryClassName?: class-string<ObjectRepository<object>>,
@@ -128,8 +114,6 @@ class Configuration
128114 * persistentCollectionGenerator?: PersistentCollectionGenerator,
129115 * persistentCollectionDir?: string,
130116 * persistentCollectionNamespace?: string,
131- * proxyDir?: string,
132- * proxyNamespace?: string,
133117 * repositoryFactory?: RepositoryFactory,
134118 * kmsProvider?: KmsProvider,
135119 * defaultMasterKey?: array<string, mixed>|null,
@@ -140,14 +124,8 @@ class Configuration
140124
141125 private ?CacheItemPoolInterface $ metadataCache = null ;
142126
143- /** @deprecated */
144- private ProxyManagerConfiguration $ proxyManagerConfiguration ;
145-
146127 private bool $ useTransactionalFlush = false ;
147128
148- private bool $ lazyGhostObject = false ;
149- private bool $ nativeLazyObject = false ;
150-
151129 private static string $ version ;
152130
153131 /**
@@ -298,65 +276,6 @@ public function setMetadataCache(CacheItemPoolInterface $cache): void
298276 $ this ->attributes ['metadataCacheImpl ' ] = DoctrineProvider::wrap ($ cache );
299277 }
300278
301- /**
302- * Sets the directory where Doctrine generates any necessary proxy class files.
303- *
304- * @deprecated Since 2.16, proxy directory is no longer used when native lazy objects are enabled.
305- */
306- public function setProxyDir (string $ dir ): void
307- {
308- $ this ->attributes ['proxyDir ' ] = $ dir ;
309- unset($ this ->proxyManagerConfiguration );
310- }
311-
312- /**
313- * Gets the directory where Doctrine generates any necessary proxy class files.
314- *
315- * @deprecated Since 2.16, proxy directory is no longer used when native lazy objects are enabled.
316- */
317- public function getProxyDir (): ?string
318- {
319- if ($ this ->isNativeLazyObjectEnabled ()) {
320- trigger_deprecation ('doctrine/mongodb-odm ' , '2.16 ' , 'Using "%s" is deprecated when native lazy objects are enabled. ' , __METHOD__ );
321- }
322-
323- return $ this ->attributes ['proxyDir ' ] ?? null ;
324- }
325-
326- /**
327- * Gets an int flag that indicates whether proxy classes should always be regenerated
328- * during each script execution.
329- *
330- * @return self::AUTOGENERATE_*
331- */
332- public function getAutoGenerateProxyClasses (): int
333- {
334- return $ this ->attributes ['autoGenerateProxyClasses ' ] ?? self ::AUTOGENERATE_FILE_NOT_EXISTS ;
335- }
336-
337- /**
338- * Sets an int flag that indicates whether proxy classes should always be regenerated
339- * during each script execution.
340- *
341- * @param self::AUTOGENERATE_* $mode
342- */
343- public function setAutoGenerateProxyClasses (int $ mode ): void
344- {
345- $ this ->attributes ['autoGenerateProxyClasses ' ] = $ mode ;
346- unset($ this ->proxyManagerConfiguration );
347- }
348-
349- public function getProxyNamespace (): ?string
350- {
351- return $ this ->attributes ['proxyNamespace ' ] ?? null ;
352- }
353-
354- public function setProxyNamespace (string $ ns ): void
355- {
356- $ this ->attributes ['proxyNamespace ' ] = $ ns ;
357- unset($ this ->proxyManagerConfiguration );
358- }
359-
360279 public function setHydratorDir (string $ dir ): void
361280 {
362281 $ this ->attributes ['hydratorDir ' ] = $ dir ;
@@ -634,41 +553,6 @@ public function getPersistentCollectionGenerator(): PersistentCollectionGenerato
634553 return $ this ->attributes ['persistentCollectionGenerator ' ];
635554 }
636555
637- /** @deprecated */
638- public function buildGhostObjectFactory (): LazyLoadingGhostFactory
639- {
640- return new LazyLoadingGhostFactory ($ this ->getProxyManagerConfiguration ());
641- }
642-
643- /** @deprecated */
644- public function getProxyManagerConfiguration (): ProxyManagerConfiguration
645- {
646- if (isset ($ this ->proxyManagerConfiguration )) {
647- return $ this ->proxyManagerConfiguration ;
648- }
649-
650- $ proxyManagerConfiguration = new ProxyManagerConfiguration ();
651- $ proxyManagerConfiguration ->setProxiesTargetDir ($ this ->getProxyDir ());
652- $ proxyManagerConfiguration ->setProxiesNamespace ($ this ->getProxyNamespace ());
653-
654- switch ($ this ->getAutoGenerateProxyClasses ()) {
655- case self ::AUTOGENERATE_FILE_NOT_EXISTS :
656- $ proxyManagerConfiguration ->setGeneratorStrategy (new FileWriterGeneratorStrategy (
657- new FileLocator ($ proxyManagerConfiguration ->getProxiesTargetDir ()),
658- ));
659-
660- break ;
661- case self ::AUTOGENERATE_EVAL :
662- $ proxyManagerConfiguration ->setGeneratorStrategy (new EvaluatingGeneratorStrategy ());
663-
664- break ;
665- default :
666- throw new InvalidArgumentException ('Invalid proxy generation strategy given - only AUTOGENERATE_FILE_NOT_EXISTS and AUTOGENERATE_EVAL are supported. ' );
667- }
668-
669- return $ this ->proxyManagerConfiguration = $ proxyManagerConfiguration ;
670- }
671-
672556 public function setUseTransactionalFlush (bool $ useTransactionalFlush ): void
673557 {
674558 $ this ->useTransactionalFlush = $ useTransactionalFlush ;
@@ -679,51 +563,6 @@ public function isTransactionalFlushEnabled(): bool
679563 return $ this ->useTransactionalFlush ;
680564 }
681565
682- /**
683- * Generate proxy classes using Symfony VarExporter's LazyGhostTrait if true.
684- * Otherwise, use ProxyManager's LazyLoadingGhostFactory (deprecated)
685- */
686- public function setUseLazyGhostObject (bool $ flag ): void
687- {
688- if ($ this ->nativeLazyObject ) {
689- throw new LogicException ('Cannot enable or disable LazyGhostObject when native lazy objects are enabled. ' );
690- }
691-
692- if ($ flag && ! trait_exists (LazyGhostTrait::class)) {
693- throw new LogicException ('Package "symfony/var-exporter" >= 8.0 does not provide lazy ghost objects, use native lazy objects instead. ' );
694- }
695-
696- if (! $ flag ) {
697- if (! class_exists (ProxyManagerConfiguration::class)) {
698- throw new LogicException ('Package "friendsofphp/proxy-manager-lts" is required to disable LazyGhostObject. ' );
699- }
700-
701- trigger_deprecation ('doctrine/mongodb-odm ' , '2.10 ' , 'Using "friendsofphp/proxy-manager-lts" is deprecated. Use "symfony/var-exporter" LazyGhostObjects instead. ' );
702- }
703-
704- $ this ->lazyGhostObject = $ flag ;
705- }
706-
707- public function isLazyGhostObjectEnabled (): bool
708- {
709- // Always false if native lazy objects are enabled
710- return $ this ->lazyGhostObject && ! $ this ->nativeLazyObject ;
711- }
712-
713- public function setUseNativeLazyObject (bool $ nativeLazyObject ): void
714- {
715- $ this ->nativeLazyObject = $ nativeLazyObject ;
716- }
717-
718- public function isNativeLazyObjectEnabled (): bool
719- {
720- if (! $ this ->nativeLazyObject ) {
721- trigger_deprecation ('doctrine/mongodb-odm ' , '2.14 ' , 'Not using native lazy objects is deprecated and will be impossible in Doctrine MongoDB ODM 3.0. ' );
722- }
723-
724- return $ this ->nativeLazyObject ;
725- }
726-
727566 /**
728567 * Set the KMS provider to use for auto-encryption. The name of the KMS provider
729568 * must be specified in the 'type' key of the array.
0 commit comments