add('stages', $this::class); $context->get('logger')->debug("Pass: ".$this::class); if ( $context->directory->empty('output_base') or !is_dir($context->directory->output_base) ) { throw new ContextException(sprintf('Key "%s" needs to be a valid directory.', 'output_base_directory')); } $list = $this->load($context->directory->output_base); $sorted = $this->sort($list); dump($sorted); return $context; } /** @return array */ public function load(string $output_base_directory): array { $list = []; $projects = glob($output_base_directory . '/*/autodoc.json'); foreach ($projects as $project) { $dir = basename(dirname($project)); $json = json_decode(file_get_contents($project)); $list[$dir] = $json; } return $list; } /** @return array */ public function sort(array $list): array { $groups = []; foreach ($list as $project) { $organization = basename(dirname($project->urls->repository ?: '')) ?: 'other'; if ($organization === 'spip' and $project->prefix !== 'spip') { $organization = 'spip-core'; } $groups[$organization][] = $project; } foreach ($groups as $organization => &$group) { usort($group, function ($a, $b) { return $a->title <=> $b->title; }); } return $groups; } }