private function getRegistryConfig($bundleId, $scopePerContext, $scopePerEnvironment)
    {
        $registry = null;

        try {
            if (null !== $em = $this->application->getEntityManager()) {
                $registry = $em->getRepository('BackBee\Bundle\Registry')->findOneBy(array(
                    'key' => $bundleId,
                    'scope' => $this->getRegistryScope('BUNDLE_CONFIG', $scopePerContext, $scopePerEnvironment),
                ));
            }
        } catch (DBALException $e) {
            $expectedError = false;
            if (null !== $e->getPrevious() && $e->getPrevious() instanceof \PDOException) {
                // expected error is if we try to get overrided config in registry on application installation process
                // PDOException has two methods for retrieving information about an error
                // @see http://php.net/manual/en/class.pdoexception.php
                $expectedError = (
                    '42S02' === $e->getPrevious()->getCode()
                    || false !== strpos($e->getPrevious()->getMessage(), 'SQLSTATE[42S02]')
                );
            }

            if (false === $expectedError) {
                throw $e;
            }
        }

        return $registry;
    }