|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* autodoc
|
|
|
|
*
|
|
|
|
* Permettre le calcul d'URL vers un type de visualisation
|
|
|
|
* en ligne (trac, redmine, …) d'une sources issues de Vcs
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace autodoc\Plugin\Core\Compiler\Pass\VcsViewer;
|
|
|
|
|
|
|
|
use autodoc\Plugin\Core\Compiler\Pass\VcsInformations\VcsInformationsAbstract;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calcul d'URL pour visualiser des fichiers sources en ligne
|
|
|
|
**/
|
|
|
|
class DefaultViewer
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Informations du Vcs
|
|
|
|
* @var VcsInformationsAbstract
|
|
|
|
**/
|
|
|
|
private $vcsInformations;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ligne dans le fichier
|
|
|
|
* @var int
|
|
|
|
**/
|
|
|
|
private $line;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nom du fichier
|
|
|
|
* @var string
|
|
|
|
**/
|
|
|
|
private $filename;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Racine du viewer en ligne
|
|
|
|
* @var string
|
|
|
|
**/
|
|
|
|
private $urlViewerRoot;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur.
|
|
|
|
*
|
|
|
|
* @param VcsInformationsAbstract $vcsInformations
|
|
|
|
* @param string $urlViewerRoot URL de la page d'accueil du viewer (trac, redmine, ...)
|
|
|
|
**/
|
|
|
|
public function __construct(VcsInformationsAbstract $vcsInformations, $urlViewerRoot) {
|
|
|
|
$this->vcsInformations = $vcsInformations;
|
|
|
|
$this->urlViewerRoot = $urlViewerRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculer et retourner l'URL pour voir le fichier et la ligne
|
|
|
|
* @return string URL
|
|
|
|
**/
|
|
|
|
public function getUrl() {
|
|
|
|
$url = $this->getUrlViewerRoot();
|
|
|
|
$url = rtrim($url . $this->getVcs()->getProjectPath(), '/');
|
|
|
|
$url = rtrim($url . $this->getVcs()->getInnerPath(), '/');
|
|
|
|
if ($this->getFilename()) $url .= '/' . $this->getFilename();
|
|
|
|
if ($this->getLine()) $url .= '#L' . $this->getLine();
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le numéro de ligne
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
**/
|
|
|
|
public function getLine() {
|
|
|
|
return $this->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Définit le numéro de ligne
|
|
|
|
*
|
|
|
|
* @param int $line
|
|
|
|
**/
|
|
|
|
public function setLine($line) {
|
|
|
|
$this->line = $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le nom du fichier
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
**/
|
|
|
|
public function getFilename() {
|
|
|
|
return $this->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Définit le nom du fichier
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
**/
|
|
|
|
public function setFilename($filename) {
|
|
|
|
$this->filename = $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne les informations du vcs
|
|
|
|
*
|
|
|
|
* @return VcsInformationsAbstract
|
|
|
|
**/
|
|
|
|
public function getVcs() {
|
|
|
|
return $this->vcsInformations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le chemin de la racine du viewer en ligne
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
**/
|
|
|
|
public function getUrlViewerRoot() {
|
|
|
|
return $this->urlViewerRoot;
|
|
|
|
}
|
|
|
|
}
|