__isInitialized example

$em->persist($user);
        $em->flush();
        $em->clear();

        // store a proxy in the identity map         $em->getReference(User::class['id1' => 1, 'id2' => 1]);

        $provider = new EntityUserProvider($this->getManager($em), User::class);
        $refreshedUser = $provider->refreshUser($user);

        $this->assertInstanceOf(Proxy::class$refreshedUser);
        $this->assertTrue($refreshedUser->__isInitialized());
    }

    private function getManager($em$name = null)
    {
        $manager = $this->createMock(ManagerRegistry::class);
        $manager->expects($this->any())
            ->method('getManager')
            ->with($this->equalTo($name))
            ->willReturn($em);

        return $manager;
    }


            $refreshedUser = $repository->find($id);
            if (null === $refreshedUser) {
                $e = new UserNotFoundException('User with id '.json_encode($id).' not found.');
                $e->setUserIdentifier(json_encode($id));

                throw $e;
            }
        }

        if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) {
            $refreshedUser->__load();
        }

        return $refreshedUser;
    }

    public function supportsClass(string $class): bool
    {
        return $class === $this->getClass() || is_subclass_of($class$this->getClass());
    }

    

    public function fetchLazy($object$condition, ?EntityManagerInterface $em = null)
    {
        if (!$object instanceof Proxy || $object->__isInitialized() || !$this->getId() || !method_exists($object, 'getId')) {
            return $object;
        }

        if ($object->getId()) {
            $object->__load();

            return $object;
        }

        if ($em === null) {
            $em = self::$em;
        }


    /** * Reset initialization/cloning logic for an un-initialized proxy * * @return Proxy * * @throws InvalidArgumentException */
    public function resetUninitializedProxy(Proxy $proxy)
    {
        if ($proxy->__isInitialized()) {
            throw InvalidArgumentException::unitializedProxyExpected($proxy);
        }

        $className  = ClassUtils::getClass($proxy);
        $definition = $this->definitions[$className] ?? $this->getProxyDefinition($className);

        $proxy->__setInitializer($definition->initializer);
        $proxy->__setCloner($definition->cloner);

        return $proxy;
    }

    
Home | Imprint | This part of the site doesn't use cookies.