public static function getManager(ManagerRegistry $or, $class)
    {
        $manager = $or->getManagerForClass($class);

        if (null === $manager) {
            foreach ($or->getManagers() as $objectManager) {
                if ($objectManager->getMetadataFactory()->hasMetadataFor($class)
                        && self::isValidManager($objectManager, $class)) {
                    $manager = $objectManager;

                    break;
                }
            }
        }

        return $manager;
    }