public static function namespaceExists($namespace)
    {
        $namespace = trim($namespace, self::NAMESPACE_SEPARATOR);
        $namespace .= self::NAMESPACE_SEPARATOR;

        foreach (get_declared_classes() as $name) {
            if (strpos($name, $namespace) === 0) {
                return true;
            }
        }

        if (class_exists($_composer_loader = self::COMPOSER_AUTOLOADER_CLASSNAME)) {
            $_composer_reflection = new \ReflectionClass($_composer_loader);
            $_loader_filename = $_composer_reflection->getFilename();
            $_classmap_filename = dirname($_loader_filename)
                .DIRECTORY_SEPARATOR
                .self::COMPOSER_COMMON_NAMESPACES_AUTOLOADER;
            if (file_exists($_classmap_filename)) {
                $namespaces_map = include $_classmap_filename;
                foreach ($namespaces_map as $_ns=>$_dir) {
                    $_ns = trim($_ns, self::NAMESPACE_SEPARATOR);
                    if (strpos($_ns, $namespace) === 0) {
                        return true;
                    }
                    if (substr($namespace, 0, strlen($_ns))===$_ns) {
                        if (false !== $pos = strrpos($namespace, self::NAMESPACE_SEPARATOR)) {
                            // namespaced class name
                            $namespace_path = strtr(substr($namespace, 0, $pos), self::NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR);
                            $namespace_name = substr($namespace, $pos + 1);
                        } else {
                            // PEAR-like class name
                            $namespace_path = null;
                            $namespace_name = $namespace;
                        }
                        $namespace_path .= strtr($namespace_name, '_', DIRECTORY_SEPARATOR);
                        
                        if (!is_array($_dir)) {
                            $_dir = array($_dir);
                        }
                        foreach ($_dir as $_testdir) {
                            $_d = DirectoryHelper::slashDirname($_testdir) . $namespace_path;
                            if (file_exists($_d) && is_dir($_d)) {
                                return true;
                            }
                        }

                    }
                }
            }
        }

        return false;
    }