|
|
|
@ -44,7 +44,8 @@ class GeneratorOld
|
|
|
|
|
$this->setApplicationDirectories(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function isVerbose() : bool { |
|
|
|
|
public function isVerbose(): bool |
|
|
|
|
{ |
|
|
|
|
return $this->output->isVerbose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -56,14 +57,17 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @param string $branche Branche Git |
|
|
|
|
**/ |
|
|
|
|
public function generateFromSpip($branche) { |
|
|
|
|
public function generateFromSpip($branche) |
|
|
|
|
{ |
|
|
|
|
$url = "https://git.spip.net/spip/spip.git"; |
|
|
|
|
|
|
|
|
|
$prefixe = $this->input->getOption('prefixe'); |
|
|
|
|
$ok = $this->createDirectories($prefixe) |
|
|
|
|
&& $this->getGitSource($url, $branche, 'spip'); |
|
|
|
|
|
|
|
|
|
if (!$ok) return false; |
|
|
|
|
if (!$ok) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$titre = ""; |
|
|
|
@ -94,7 +98,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $chemin Chemin dans le git Zone |
|
|
|
|
* @param string $branche Branche |
|
|
|
|
**/ |
|
|
|
|
public function generateFromZone($chemin, $branche = 'master') { |
|
|
|
|
public function generateFromZone($chemin, $branche = 'master') |
|
|
|
|
{ |
|
|
|
|
$zone = "https://git.spip.net/$chemin.git"; |
|
|
|
|
return $this->generateFromGit($zone, $branche); |
|
|
|
|
} |
|
|
|
@ -104,7 +109,8 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @param string $source URL Git |
|
|
|
|
**/ |
|
|
|
|
public function generateFromGit($source, $branche = 'master') { |
|
|
|
|
public function generateFromGit($source, $branche = 'master') |
|
|
|
|
{ |
|
|
|
|
$prefixe = $this->input->getOption('prefixe'); |
|
|
|
|
$ok = $this->createDirectories($prefixe) |
|
|
|
|
&& $this->getGitSource($source, $branche) |
|
|
|
@ -120,7 +126,8 @@ class GeneratorOld
|
|
|
|
|
* @param bool $is_ready |
|
|
|
|
* Indique si les préparatifs (création des répertoires) sont déjà faits |
|
|
|
|
**/ |
|
|
|
|
public function generateFromDirectory($dir, $is_ready = false) { |
|
|
|
|
public function generateFromDirectory($dir, $is_ready = false) |
|
|
|
|
{ |
|
|
|
|
$prefixe = $this->input->getOption('prefixe'); |
|
|
|
|
$ok = true; |
|
|
|
|
|
|
|
|
@ -128,7 +135,9 @@ class GeneratorOld
|
|
|
|
|
# forcer le chemin de la source spécifique |
|
|
|
|
$this->options['dirs']['input'] = $dir; |
|
|
|
|
$ok = $this->createDirectories($prefixe); |
|
|
|
|
if (!$ok) return false; |
|
|
|
|
if (!$ok) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->retrouverInfoPaquetXml(); |
|
|
|
@ -155,8 +164,8 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @param string $file Chemin du fichier ou URL |
|
|
|
|
**/ |
|
|
|
|
public function generateFromFile($file) { |
|
|
|
|
|
|
|
|
|
public function generateFromFile($file) |
|
|
|
|
{ |
|
|
|
|
$timerStart = microtime(true); |
|
|
|
|
|
|
|
|
|
// Option boussole SPIP => topnav. |
|
|
|
@ -237,7 +246,7 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* Si la mise à jour ne modifie pas les fichiers, |
|
|
|
|
* la documentation n'est pas à actualiser (retourne null). |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param string $prefixe |
|
|
|
|
* Préfixe de cette documentation |
|
|
|
|
* @param array $description |
|
|
|
@ -247,7 +256,8 @@ class GeneratorOld
|
|
|
|
|
* - null : ok, mais mise à jour inutile |
|
|
|
|
* - False : erreur |
|
|
|
|
**/ |
|
|
|
|
public function obtenir_fichiers_a_documenter($prefixe, $description) { |
|
|
|
|
public function obtenir_fichiers_a_documenter($prefixe, $description) |
|
|
|
|
{ |
|
|
|
|
$this->output->writeln("\n"); |
|
|
|
|
$titre = "Générer la documentation de $prefixe"; |
|
|
|
|
$this->output->writeln("<comment>$titre</comment>"); |
|
|
|
@ -305,7 +315,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $outut_base |
|
|
|
|
* Répertoire où on été enregistré les documentations |
|
|
|
|
**/ |
|
|
|
|
public function generer_sommaire_documentations($presents, $output_base) { |
|
|
|
|
public function generer_sommaire_documentations($presents, $output_base) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
// générer un sommaire de toutes ces documentations |
|
|
|
|
$this->output->writeln("Création du sommaire des documentations"); |
|
|
|
@ -344,12 +355,12 @@ class GeneratorOld
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
usort($plugins, function($a, $b) { |
|
|
|
|
usort($plugins, function ($a, $b) { |
|
|
|
|
return ($a['nom'] < $b['nom']) ? -1 : 1; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// charger Twig, générer la page et l'enregitrer |
|
|
|
|
$loader = new \Twig_Loader_Filesystem( $this->dirs['helper'] . '/Template' ); |
|
|
|
|
$loader = new \Twig_Loader_Filesystem($this->dirs['helper'] . '/Template'); |
|
|
|
|
$twig = new \Twig_Environment($loader); |
|
|
|
|
|
|
|
|
|
$topnav = $this->getOption('topnav', ''); |
|
|
|
@ -372,9 +383,10 @@ class GeneratorOld
|
|
|
|
|
* @param string $outut_base |
|
|
|
|
* Répertoire où on été enregistré les documentations |
|
|
|
|
**/ |
|
|
|
|
public function generer_json_documentations($plugins, $output_base) { |
|
|
|
|
public function generer_json_documentations($plugins, $output_base) |
|
|
|
|
{ |
|
|
|
|
$this->output->writeln("Création du json des documentations"); |
|
|
|
|
usort($plugins, function($a, $b) { |
|
|
|
|
usort($plugins, function ($a, $b) { |
|
|
|
|
return ($a['prefixe'] < $b['prefixe']) ? -1 : 1; |
|
|
|
|
}); |
|
|
|
|
$plugins = array_column($plugins, null, 'prefixe'); |
|
|
|
@ -382,10 +394,10 @@ class GeneratorOld
|
|
|
|
|
unlink($file); |
|
|
|
|
} |
|
|
|
|
file_put_contents($file, json_encode( |
|
|
|
|
$plugins, |
|
|
|
|
$plugins, |
|
|
|
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -396,13 +408,14 @@ class GeneratorOld
|
|
|
|
|
* URL du fichier source (svn) de la liste des docémentations à générer |
|
|
|
|
* @return bool True si ok. |
|
|
|
|
**/ |
|
|
|
|
public function actualiser_liste_source($file) { |
|
|
|
|
public function actualiser_liste_source($file) |
|
|
|
|
{ |
|
|
|
|
// supprimer l'ancienne rotation |
|
|
|
|
if (file_exists( $this->files['autodoc.txt.bak'] )) { |
|
|
|
|
if (file_exists($this->files['autodoc.txt.bak'])) { |
|
|
|
|
unlink($this->files['autodoc.txt.bak']); |
|
|
|
|
} |
|
|
|
|
// rotation |
|
|
|
|
if (file_exists( $this->files['autodoc.txt'] )) { |
|
|
|
|
if (file_exists($this->files['autodoc.txt'])) { |
|
|
|
|
copy($this->files['autodoc.txt'], $this->files['autodoc.txt.bak']); |
|
|
|
|
unlink($this->files['autodoc.txt']); |
|
|
|
|
} |
|
|
|
@ -430,7 +443,7 @@ class GeneratorOld
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Effacte une ou plusieurs documentations qui ne sont plus listés |
|
|
|
@ -443,7 +456,8 @@ class GeneratorOld
|
|
|
|
|
* @return bool |
|
|
|
|
* True si au moins une documentation, et ses caches, ont été effacés. |
|
|
|
|
**/ |
|
|
|
|
public function supprimer_vieux_plugins($absents, $output_base) { |
|
|
|
|
public function supprimer_vieux_plugins($absents, $output_base) |
|
|
|
|
{ |
|
|
|
|
if ($absents) { |
|
|
|
|
$this->output->writeln("<comment>Certaines documentations ne sont plus à générer.</comment>"); |
|
|
|
|
foreach ($absents as $prefixe=>$absent) { |
|
|
|
@ -471,15 +485,24 @@ class GeneratorOld
|
|
|
|
|
* - source : url du git |
|
|
|
|
* - branche : branche à utiliser (défaut : master) |
|
|
|
|
**/ |
|
|
|
|
private function parseFile($file, $write_errors = true) { |
|
|
|
|
if (!file_exists($file)) return false; |
|
|
|
|
if (!$lines = file($file)) return false; |
|
|
|
|
private function parseFile($file, $write_errors = true) |
|
|
|
|
{ |
|
|
|
|
if (!file_exists($file)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (!$lines = file($file)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$liste = array(); |
|
|
|
|
foreach ($lines as $lineno => $line) { |
|
|
|
|
if (!$line) continue; |
|
|
|
|
if (!$line) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$line = trim($line); |
|
|
|
|
if (!$line OR $line[0] == '#') continue; |
|
|
|
|
if (!$line or $line[0] == '#') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$couples = explode(';', $line); |
|
|
|
|
$lineno++; |
|
|
|
|
if (count($couples) != 2) { |
|
|
|
@ -526,14 +549,16 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @return bool true si réussi |
|
|
|
|
**/ |
|
|
|
|
private function clearLogs() { |
|
|
|
|
private function clearLogs() |
|
|
|
|
{ |
|
|
|
|
return $this->deleteDirectoryContent($this->dirs['log']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Définit les répertoires utiles à l'application |
|
|
|
|
**/ |
|
|
|
|
private function setApplicationDirectories() { |
|
|
|
|
private function setApplicationDirectories() |
|
|
|
|
{ |
|
|
|
|
# ce répertoire |
|
|
|
|
$this->dirs['helper'] = realpath(__DIR__); |
|
|
|
|
|
|
|
|
@ -545,7 +570,7 @@ class GeneratorOld
|
|
|
|
|
$this->dirs['work'] = $this->dirs['root'] . '/work'; |
|
|
|
|
|
|
|
|
|
# répertoire du template zora |
|
|
|
|
$this->dirs['template'] = realpath( $this->dirs['helper'] . '/../../../templates/zora'); |
|
|
|
|
$this->dirs['template'] = realpath($this->dirs['helper'] . '/../../../templates/zora'); |
|
|
|
|
|
|
|
|
|
# fichier de config xml pour phpdocumentor |
|
|
|
|
$this->files['phpdoc.xml'] = $this->dirs['work'] . '/phpdoc.xml'; |
|
|
|
@ -558,7 +583,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $prefixe Préfixe utilisé pour cette génération |
|
|
|
|
* @return bool true si réussi |
|
|
|
|
**/ |
|
|
|
|
private function createDirectories($prefixe) { |
|
|
|
|
private function createDirectories($prefixe) |
|
|
|
|
{ |
|
|
|
|
$_work = $this->dirs['work']; |
|
|
|
|
$this->output->writeln("* Vérifier/créer les répertoires de travail dans <info>$_work</info>"); |
|
|
|
|
|
|
|
|
@ -583,7 +609,7 @@ class GeneratorOld
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (array('output', 'input', 'log', 'cache') as $dir) { |
|
|
|
|
if (!$this->createDirectory( $this->dirs[$dir] )) { |
|
|
|
|
if (!$this->createDirectory($this->dirs[$dir])) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -600,7 +626,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $chemin Répertoire à créer |
|
|
|
|
* @return bool true si réussi |
|
|
|
|
**/ |
|
|
|
|
private function createDirectory($dir) { |
|
|
|
|
private function createDirectory($dir) |
|
|
|
|
{ |
|
|
|
|
if (!is_dir($dir)) { |
|
|
|
|
$this->output->writeln(" - Création du répertoire <info>$dir</info>"); |
|
|
|
|
|
|
|
|
@ -610,7 +637,6 @@ class GeneratorOld
|
|
|
|
|
$this->output->writeln($error['message']); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (!is_writable($dir)) { |
|
|
|
|
$this->output->writeln("<error>Le répertoire $dir n'est pas accessible en écriture</error>"); |
|
|
|
@ -627,7 +653,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $branch Branche à utiliser |
|
|
|
|
* @return bool true si réussi |
|
|
|
|
**/ |
|
|
|
|
private function getGitSource(string $source, string $branch, string $type = 'git') : bool { |
|
|
|
|
private function getGitSource(string $source, string $branch, string $type = 'git'): bool |
|
|
|
|
{ |
|
|
|
|
$this->output->writeln("* Obtenir <info>$source</info>"); |
|
|
|
|
|
|
|
|
|
$this->git = array(); |
|
|
|
@ -637,7 +664,7 @@ class GeneratorOld
|
|
|
|
|
if (!$urlGit or $urlGit !== $source) { |
|
|
|
|
// erreur, donc pas un dossier ou pas le bon |
|
|
|
|
$this->output->writeln("<comment> - Source absente ou mauvaise, on le recrée</comment>"); |
|
|
|
|
$this->deleteDirectoryContent($this->dirs['input'], true); |
|
|
|
|
$this->deleteDirectoryContent($this->dirs['input'], true); |
|
|
|
|
} |
|
|
|
|
$checkout->run("$type -b$branch $source"); |
|
|
|
|
|
|
|
|
@ -654,7 +681,8 @@ class GeneratorOld
|
|
|
|
|
* @param bool $no_error true : Envoie les erreurs dans /dev/null |
|
|
|
|
* @return mixed|bool false en cas d'erreur |
|
|
|
|
**/ |
|
|
|
|
private function getCheckout() : Checkout { |
|
|
|
|
private function getCheckout(): Checkout |
|
|
|
|
{ |
|
|
|
|
$dir = $this->dirs['input']; |
|
|
|
|
return new Checkout($dir, new ConsoleLogger($this->output)); |
|
|
|
|
} |
|
|
|
@ -666,7 +694,8 @@ class GeneratorOld
|
|
|
|
|
* @param bool $no_error true : Envoie les erreurs dans /dev/null |
|
|
|
|
* @return mixed|bool false en cas d'erreur |
|
|
|
|
**/ |
|
|
|
|
private function makeCheckoutCommand($cmd, $no_error = true, $dir = null) { |
|
|
|
|
private function makeCheckoutCommand($cmd, $no_error = true, $dir = null) |
|
|
|
|
{ |
|
|
|
|
if (is_null($dir)) { |
|
|
|
|
$dir = $this->dirs['input']; |
|
|
|
|
} |
|
|
|
@ -685,15 +714,24 @@ class GeneratorOld
|
|
|
|
|
* @param string $delete_me Supprimer aussi le répertoire ? |
|
|
|
|
* @return bool Suppression reussie. |
|
|
|
|
*/ |
|
|
|
|
function deleteDirectoryContent($dir, $delete_me = false) { |
|
|
|
|
if (!file_exists($dir)) return true; |
|
|
|
|
if (!is_dir($dir) || is_link($dir)) return @unlink($dir); |
|
|
|
|
public function deleteDirectoryContent($dir, $delete_me = false) |
|
|
|
|
{ |
|
|
|
|
if (!file_exists($dir)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if (!is_dir($dir) || is_link($dir)) { |
|
|
|
|
return @unlink($dir); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (scandir($dir) as $item) { |
|
|
|
|
if ($item == '.' || $item == '..') continue; |
|
|
|
|
if ($item == '.' || $item == '..') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) { |
|
|
|
|
@chmod($dir . "/" . $item, 0777); |
|
|
|
|
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) return false; |
|
|
|
|
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -711,7 +749,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $name Nom de l'option |
|
|
|
|
* @return mixed |
|
|
|
|
**/ |
|
|
|
|
private function getOption($name, $default = null) { |
|
|
|
|
private function getOption($name, $default = null) |
|
|
|
|
{ |
|
|
|
|
if (strpos($name, '/') === false) { |
|
|
|
|
if ($this->input->hasOption($name) and $valeur = $this->input->getOption($name)) { |
|
|
|
|
return $valeur; |
|
|
|
@ -753,7 +792,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $name Nom de l'option |
|
|
|
|
* @param string $value Valeur de l'option |
|
|
|
|
**/ |
|
|
|
|
private function setOption($name, $value) { |
|
|
|
|
private function setOption($name, $value) |
|
|
|
|
{ |
|
|
|
|
$name = explode('/', $name); |
|
|
|
|
$n = array_shift($name); |
|
|
|
|
$pointeur = &$this->options; |
|
|
|
@ -773,7 +813,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $command Nom de la commande |
|
|
|
|
* @return mixed |
|
|
|
|
**/ |
|
|
|
|
private function getCommand($command) { |
|
|
|
|
private function getCommand($command) |
|
|
|
|
{ |
|
|
|
|
if (isset($this->commands[$command])) { |
|
|
|
|
$val = $this->commands[$command]; |
|
|
|
|
return " --$command=\"$val\""; |
|
|
|
@ -787,7 +828,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $command Nom de la commande |
|
|
|
|
* @param string $value Valeur de la commande |
|
|
|
|
**/ |
|
|
|
|
private function setCommand($command, $value) { |
|
|
|
|
private function setCommand($command, $value) |
|
|
|
|
{ |
|
|
|
|
$this->commands[$command] = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -800,7 +842,8 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @return bool true si on a trouvé un paquet.xml |
|
|
|
|
**/ |
|
|
|
|
private function retrouverInfoPaquetXml() { |
|
|
|
|
private function retrouverInfoPaquetXml() |
|
|
|
|
{ |
|
|
|
|
$source = $this->dirs['input']; |
|
|
|
|
$is_spip = false; |
|
|
|
|
|
|
|
|
@ -873,7 +916,6 @@ class GeneratorOld
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!$this->getOption('presentation')) { |
|
|
|
|
|
|
|
|
|
if ($is_spip) { |
|
|
|
|
$presentation = "Cette documentation est issue du code source PHP de SPIP $version. "; |
|
|
|
|
} else { |
|
|
|
@ -889,7 +931,7 @@ class GeneratorOld
|
|
|
|
|
$presentation = "Cette documentation est issue du code source PHP du plugin « ".$nom." », version $version$rev. "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!$is_spip OR $documentation OR $developpement) { |
|
|
|
|
if (!$is_spip or $documentation or $developpement) { |
|
|
|
|
if (!$is_spip) { |
|
|
|
|
$presentation .= "- [Description dans l'annuaire des plugins]($lien_plugins_spip) "; |
|
|
|
|
} |
|
|
|
@ -912,8 +954,8 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @return bool true si réussi. |
|
|
|
|
**/ |
|
|
|
|
private function prepareConfigXml() { |
|
|
|
|
|
|
|
|
|
private function prepareConfigXml() |
|
|
|
|
{ |
|
|
|
|
$this->output->write("* Préparer le fichier phpdoc.xml "); |
|
|
|
|
$template = $this->dirs['helper'] . '/phpdoc_helper.xml'; |
|
|
|
|
$template = file_get_contents($template); |
|
|
|
@ -958,7 +1000,8 @@ class GeneratorOld
|
|
|
|
|
* |
|
|
|
|
* @return bool true si réussi. |
|
|
|
|
**/ |
|
|
|
|
private function execute() { |
|
|
|
|
private function execute() |
|
|
|
|
{ |
|
|
|
|
$conf = $this->files['phpdoc.xml']; |
|
|
|
|
$command = "php phpDocumentor.phar --config=$conf"; |
|
|
|
|
if ($this->getOption('force')) { |
|
|
|
@ -979,7 +1022,8 @@ class GeneratorOld
|
|
|
|
|
* @param string $string |
|
|
|
|
* @return string |
|
|
|
|
**/ |
|
|
|
|
private function escape_xml_attr($string) { |
|
|
|
|
private function escape_xml_attr($string) |
|
|
|
|
{ |
|
|
|
|
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|