9 changed files with 127 additions and 117 deletions
@ -1,30 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Spip\Autodoc; |
||||
|
||||
use Spip\Autodoc\Loader\LoaderInterface; |
||||
use Symfony\Component\Console\Style\SymfonyStyle; |
||||
|
||||
class Generator |
||||
{ |
||||
private SymfonyStyle $io; |
||||
private LoaderInterface $loader; |
||||
|
||||
public function __construct(SymfonyStyle $io) |
||||
{ |
||||
$this->io = $io; |
||||
} |
||||
|
||||
public function setLoader(LoaderInterface $loader) |
||||
{ |
||||
$this->loader = $loader; |
||||
} |
||||
|
||||
public function run() |
||||
{ |
||||
$this->loader->load(); |
||||
|
||||
$directories = $this->loader->getDirectories(); |
||||
dump($directories); |
||||
} |
||||
} |
@ -1,42 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Spip\Autodoc\Loader; |
||||
|
||||
use Spip\Autodoc\Loader\LoaderInterface; |
||||
use Symfony\Component\Console\Style\SymfonyStyle; |
||||
|
||||
abstract class AbstractLoader implements LoaderInterface |
||||
{ |
||||
protected SymfonyStyle $io; |
||||
private string $inputDirectory; |
||||
|
||||
public function __construct(SymfonyStyle $io) |
||||
{ |
||||
$this->io = $io; |
||||
} |
||||
|
||||
abstract public function load(): void; |
||||
|
||||
/** |
||||
* Get the value of directories to document |
||||
*/ |
||||
public function getDirectories(): array |
||||
{ |
||||
return [ $this->inputDirectory ]; |
||||
} |
||||
|
||||
public function setInputDirectory(string $directory): self |
||||
{ |
||||
$this->inputDirectory = $directory; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get the value of inputDirectory |
||||
*/ |
||||
public function getInputDirectory(): string |
||||
{ |
||||
return $this->inputDirectory; |
||||
} |
||||
} |
@ -1,36 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Spip\Autodoc\Loader; |
||||
|
||||
class Collection implements LoaderInterface |
||||
{ |
||||
/** @var LoaderInterface[] */ |
||||
private array $loaders; |
||||
|
||||
public function add(LoaderInterface $loader) |
||||
{ |
||||
$this->loaders[] = $loader; |
||||
} |
||||
|
||||
public function load(): void |
||||
{ |
||||
foreach ($this->loaders as $loader) { |
||||
$loader->load(); |
||||
} |
||||
} |
||||
|
||||
public function getDirectories(): array |
||||
{ |
||||
$dirs = []; |
||||
foreach ($this->loaders as $loader) { |
||||
$dirs = [...$dirs, ...$loader->getDirectories()]; |
||||
} |
||||
return $dirs; |
||||
} |
||||
|
||||
/** @return LoaderInterface[] */ |
||||
public function getLoaders(): array |
||||
{ |
||||
return $this->loaders; |
||||
} |
||||
} |
@ -1,9 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Spip\Autodoc\Loader; |
||||
|
||||
interface LoaderInterface |
||||
{ |
||||
public function getDirectories(): array; |
||||
public function load(): void; |
||||
} |
@ -0,0 +1,60 @@
|
||||
<?php |
||||
|
||||
namespace Spip\Autodoc\Stage; |
||||
|
||||
use Spip\Autodoc\Context; |
||||
use Spip\Autodoc\Exception\ContextException; |
||||
|
||||
/** Create index.html page with links of all available documentations */ |
||||
class IndexStage implements StageInterface { |
||||
public function __invoke(Context $context): Context |
||||
{ |
||||
$context->add('stages', $this::class); |
||||
$context->get('logger')->debug("Pass: ".$this::class); |
||||
|
||||
if ( |
||||
!$context->get('output_base_directory') |
||||
or !is_dir($context->get('output_base_directory')) |
||||
) { |
||||
throw new ContextException(sprintf('Key "%s" needs to be a valid directory.', 'output_base_directory')); |
||||
} |
||||
|
||||
$output_base_directory = $context->get('output_base_directory'); |
||||
|
||||
$list = $this->load($output_base_directory); |
||||
$sorted = $this->sort($list); |
||||
dump($sorted); |
||||
|
||||
return $context; |
||||
} |
||||
|
||||
/** @return array<string, stdClass> */ |
||||
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<string, stdClass> */ |
||||
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; |
||||
} |
||||
} |
Loading…
Reference in new issue