public function discover()
    {
        $classes = [];

        foreach ($this->doFileSearch() as $file) {
            $classinfo = $this->parse($file);
            $classname = $classinfo['class'];
            $classpath = $file->getRealPath() ?: "$classname.php";

            if (!empty($this->searchMatches)) {
                foreach ($this->searchMatches as $type => $value) {
                    if (!isset($classinfo[$type])) {
                        continue;
                    }
                    $instances = !is_array($classinfo[$type])
                        ? [$classinfo[$type]]
                        : $classinfo[$type];

                    $matches = array_intersect($value, $instances);

                    if (empty($matches)) {
                        continue;
                    }

                    $classes[$classpath] = $classname;
                }
            } else {
                $classes[$classpath] = $classname;
            }
        }

        $this->requireClasses($classes);

        return $classes;
    }