private function publishClasses($register, $subfolder)
    {
        // read middleware from folder
        $path = $this->path . '/src/' . $subfolder;
        if (!file_exists($path)) {
            return;
        }

        $classes = [];
        $ns = $this->namespace . $subfolder;
        list_classes($classes, $path, $ns);

        // update manifest

        $manifest = $this->getManifest(lcfirst($subfolder));
        /** @noinspection PhpIncludeInspection */
        $list = file_exists($manifest) ? include $manifest : [];
        $len = strlen($ns);
        foreach ($classes as $class) {
            if (strpos($class, '\\Contracts\\') !== false) {
                continue; // contracts
            }
            $name = substr($class, $len + 1);
            if ($register) {
                if (!isset($list[$name])) {
                    $list[$name] = [];
                }
                if (($i = array_search($class, $list[$name])) === false) {
                    $list[$name][] = $class;
                }
            }
            else {
                if (isset($list[$name]) && ($i = array_search($class, $list[$name])) !== false) {
                    unset($list[$name][$i]);
                    if (empty($list[$name])) {
                        unset($list[$name]);
                    }
                    else {
                        $list[$name] = array_values($list[$name]);
                    }
                }
            }
        }

        $this->saveArray($manifest, $list);
    }