12 changed files with 260 additions and 56 deletions
@ -0,0 +1,47 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Permet l'extraction des informations VCS d'un répertoire |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Compiler\Pass\VcsInformations; |
||||
|
||||
/** |
||||
* Extraction d'informations d'un dossier utilisant un Vcs |
||||
**/ |
||||
class Finder |
||||
{ |
||||
/** |
||||
* Retourne la description git ou svn d’un répertoire |
||||
* |
||||
* @param string $root Chemin racine le plus bas (on ne cherche pas en deça) |
||||
* @param string $dir Répertoire depuis la racine (on cherche un .git ou .svn en remontant vers root) |
||||
* @return VcsInformationsAbstract |
||||
*/ |
||||
public static function find($root, $dir) { |
||||
// liste des répertoires déjà analysés |
||||
static $dirs = array(); |
||||
|
||||
$_dir = rtrim($root . $dir, '/') . '/'; |
||||
if (!isset($dirs[$_dir])) { |
||||
if (file_exists($_dir . '.git')) { |
||||
$vcs = new Git(); |
||||
$vcs->extractWithDirectory($_dir); |
||||
} elseif (file_exists($_dir . '.svn')) { |
||||
$vcs = new Svn(); |
||||
$vcs->extractWithDirectory($_dir); |
||||
} elseif ($dir) { |
||||
$vcs = clone self::find($root, dirname($dir)); |
||||
$vcs->setInnerPath(ltrim($vcs->getInnerPath() . '/' . basename($dir), '/')); |
||||
} else { |
||||
// on a tout épuisé jusqu’à root sans trouver de .git ou .svn |
||||
$vcs = new None(); |
||||
$vcs->extractWithDirectory($_dir); |
||||
} |
||||
$dirs[$dir] = $vcs; |
||||
} |
||||
|
||||
return $dirs[$dir]; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Permet l'extraction des informations d'un répertoire |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Compiler\Pass\VcsInformations; |
||||
|
||||
/** |
||||
* Extraction d'informations d'un dossier utilisant un Vcs |
||||
**/ |
||||
class None extends VcsInformationsAbstract |
||||
{ |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
**/ |
||||
public function extractWithDirectory($dir) { |
||||
$this->clear(); |
||||
$this->setUrlPath( $dir ); |
||||
$this->setUrlRoot( $dir ); |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Permettre le calcul d'URL vers un Gitea d'une source issues d'un Vcs |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Compiler\Pass\VcsViewer; |
||||
|
||||
/** |
||||
* Calcul d'URL pour visualiser des fichiers sources en ligne sur un Gitea |
||||
**/ |
||||
class Gitea extends DefaultViewer |
||||
{ |
||||
/** |
||||
* {@inheritDoc} |
||||
**/ |
||||
public function getUrl() { |
||||
$vcs = $this->getVcs(); |
||||
$url = $this->getUrlViewerRoot(); |
||||
$url = rtrim($url . '/' . $vcs->getProjectPath(), '/'); |
||||
$url .= '/src/branch/'; |
||||
$url .= $vcs->getBranch() . '/'; |
||||
$url = rtrim($url . $vcs->getInnerPath(), '/'); |
||||
if ($this->getFilename()) $url .= '/' . $this->getFilename(); |
||||
if ($this->getLine()) $url .= '#L' . $this->getLine(); |
||||
return $url; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Permettre le calcul d'URL vers un Github d'une source issues d'un Vcs |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Compiler\Pass\VcsViewer; |
||||
|
||||
/** |
||||
* Calcul d'URL pour visualiser des fichiers sources en ligne sur un Github |
||||
**/ |
||||
class Github extends DefaultViewer |
||||
{ |
||||
/** |
||||
* {@inheritDoc} |
||||
**/ |
||||
public function getUrl() { |
||||
// https://github.com/marcimat/bigup/tree/master/saisies |
||||
// https://github.com/marcimat/bigup/blob/master/saisies/bigup.html |
||||
$vcs = $this->getVcs(); |
||||
$url = $this->getUrlViewerRoot(); |
||||
$url = rtrim($url . '/' . $vcs->getProjectPath(), '/'); |
||||
if ($this->isDirFilename()) { |
||||
$url .= '/tree/'; |
||||
} else { |
||||
$url .= '/blob/'; |
||||
} |
||||
$url = rtrim($url . $vcs->getBranch(), '/'); |
||||
$url = rtrim($url . '/' . $vcs->getInnerPath(), '/'); |
||||
if ($this->getFilename()) $url .= '/' . $this->getFilename(); |
||||
if ($this->getLine()) $url .= '#L' . $this->getLine(); |
||||
return $url; |
||||
} |
||||
|
||||
protected function isDirFilename() { |
||||
return false === strpos($this->getFilename(), '.'); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Permettre le calcul d'URL vers un Gitlab d'une source issues d'un Vcs |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Compiler\Pass\VcsViewer; |
||||
|
||||
/** |
||||
* Calcul d'URL pour visualiser des fichiers sources en ligne sur un Gitlab |
||||
**/ |
||||
class Gitlab extends DefaultViewer |
||||
{ |
||||
/** |
||||
* {@inheritDoc} |
||||
**/ |
||||
public function getUrl() { |
||||
// https://gitlab.com/magraine/depublication/-/tree/master/prive |
||||
// https://gitlab.com/magraine/depublication/-/blob/master/depublication_fonctions.php |
||||
$vcs = $this->getVcs(); |
||||
$url = $this->getUrlViewerRoot(); |
||||
$url = rtrim($url . '/' . $vcs->getProjectPath(), '/'); |
||||
if ($this->isDirFilename()) { |
||||
$url .= '/-/tree/'; |
||||
} else { |
||||
$url .= '/-/blob/'; |
||||
} |
||||
$url = rtrim($url . $vcs->getBranch(), '/'); |
||||
$url = rtrim($url . '/' . $vcs->getInnerPath(), '/'); |
||||
if ($this->getFilename()) $url .= '/' . $this->getFilename(); |
||||
if ($this->getLine()) $url .= '#L' . $this->getLine(); |
||||
return $url; |
||||
} |
||||
|
||||
protected function isDirFilename() { |
||||
return false === strpos($this->getFilename(), '.'); |
||||
} |
||||
} |
Loading…
Reference in new issue