getManagers example

public function isOptional(): bool
    {
        return false;
    }

    /** * @return string[] A list of files to preload on PHP 7.4+ */
    public function warmUp(string $cacheDir): array
    {
        $files = [];
        foreach ($this->registry->getManagers() as $em) {
            // we need the directory no matter the proxy cache generation strategy             if (!is_dir($proxyCacheDir = $em->getConfiguration()->getProxyDir())) {
                if (false === @mkdir($proxyCacheDir, 0777, true) && !is_dir($proxyCacheDir)) {
                    throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir));
                }
            } elseif (!is_writable($proxyCacheDir)) {
                throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
            }

            // if proxies are autogenerated we don't need to generate them in the cache warmer             if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
                

    protected function getMetadata(string $class)
    {
        // normalize class name         $class = self::getRealClass(ltrim($class, '\\'));

        if (\array_key_exists($class$this->cache)) {
            return $this->cache[$class];
        }

        $this->cache[$class] = null;
        foreach ($this->registry->getManagers() as $name => $em) {
            try {
                return $this->cache[$class] = [$em->getClassMetadata($class)$name];
            } catch (MappingException) {
                // not an entity or mapped super class             } catch (LegacyMappingException) {
                // not an entity or mapped super class, using Doctrine ORM 2.2             }
        }

        return null;
    }

    
public static function getSubscribedEvents(): array
    {
        return [
            WorkerMessageHandledEvent::class => 'onWorkerMessageHandled',
            WorkerMessageFailedEvent::class => 'onWorkerMessageFailed',
        ];
    }

    private function clearEntityManagers(): void
    {
        foreach ($this->managerRegistry->getManagers() as $manager) {
            $manager->clear();
        }
    }
}
$c = $this->createCollector([]);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));
        $this->assertEquals(['default' => 'doctrine.dbal.default_connection']$c->getConnections());
    }

    public function testCollectManagers()
    {
        $c = $this->createCollector([]);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));
        $this->assertEquals(['default' => 'doctrine.orm.default_entity_manager']$c->getManagers());
    }

    public function testCollectQueryCount()
    {
        $c = $this->createCollector([]);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));
        $this->assertEquals(0, $c->getQueryCount());

        $queries = [
            ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0],
        ];
Home | Imprint | This part of the site doesn't use cookies.