Browse Source
Nombreuses adaptations : 1) les binaires sont maintenant sans extension .php 2) Pour tenir compte des <options> que l'ont passait dans phpdoc.xml, spécifique à l'autodoc, il faut grandement ruser maintenant car le sérialiseur / désérialiseur utilisé maintenant par phpdocumentor ne conserve que les éléments qui lui sont déclarés. Pour cela, on surcharge donc la classe Configuration de phpdocumentor pour ajouter notre tableau d'options. À noter que la syntaxe est légèrement différente (voir Helpers/phpdoc_helper.xml) 3) Pour faire parvenir les données de configuration au template Twig, et suite toujours au changement dans la gestion de la configuration de phpdocumentor, on transmet directement aux template la configuration connue (sans la recalculer). Mais pour cela, on doit surcharger le Writer/Twig pour ajouter notre élément. La surcharge est minime heureusement. 4) L'autoloader est déclaré différemment également. Il est appelé avant le chargement de phpDocumentor et lui est transmis lors de la création (new Application(...)). On s'adapte (dans bin/autodoc) et on adapte toutes les commandes Helpers pour transmettre cet autoloader… Pfiou. Du coup, pour simplifier un peu, on crée une Application pour le Helpers, et on déporte de bin/autodoc_helper vers l'application la déclaration des commandes utilisables.svn/root/trunk

25 changed files with 375 additions and 155 deletions
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env php |
||||
<?php |
||||
/** |
||||
* Autodoc. |
||||
* |
||||
* phpDocumentor pour le code source de SPIP |
||||
* |
||||
* Cet exécutable charge l'application autodoc (= phpdocumentor + plugins pour SPIP) |
||||
* et utilise les mêmes arguments d'entrée que l'application phpDocumentor. |
||||
* |
||||
* Pour un usage simplifié, utiliser autodoc_helper.php |
||||
*/ |
||||
|
||||
# charger l'autoloader |
||||
$bootstrap_folder = __DIR__ . '/../src'; |
||||
$autoloader_base_path = '/../vendor/autoload.php'; |
||||
$autoloader_location = $bootstrap_folder . $autoloader_base_path; |
||||
|
||||
if (! file_exists($autoloader_location) || ! is_readable($autoloader_location)) { |
||||
throw new \RuntimeException('Unable to find autoloader at ' . $autoloader_location); |
||||
} |
||||
|
||||
$autoloader = require $autoloader_location; |
||||
|
||||
|
||||
$app = new autodoc\Application($autoloader); |
||||
$app->run(); |
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env php |
||||
<?php |
||||
/** |
||||
* Autodoc. |
||||
* |
||||
* phpDocumentor pour le code source de SPIP |
||||
* |
||||
* Cet exécutable charge l'application autodoc (= phpdocumentor + plugins pour SPIP) |
||||
* et utilise les mêmes arguments d'entrée que l'application phpDocumentor. |
||||
* |
||||
* Pour un usage simplifié, utiliser autodoc_helper.php |
||||
*/ |
||||
|
||||
require_once __DIR__ . '/../src/autodoc/Application.php'; |
||||
|
||||
$app = new autodoc\Application(); |
||||
$app->run(); |
@ -0,0 +1,45 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
*/ |
||||
|
||||
namespace autodoc; |
||||
|
||||
use JMS\Serializer\Annotation as Serializer; |
||||
use phpDocumentor\Configuration as phpDocumentorConfiguration; |
||||
use phpDocumentor\Configuration\Merger\Annotation as Merger; |
||||
use autodoc\Configuration\Options; |
||||
|
||||
/** |
||||
* The definition for the configuration of autodoc. |
||||
*/ |
||||
class Configuration extends phpDocumentorConfiguration |
||||
{ |
||||
|
||||
/** |
||||
* @var Options[] contains a list of options |
||||
* @Serializer\Type("autodoc\Configuration\Options") |
||||
*/ |
||||
protected $options; |
||||
|
||||
|
||||
/** |
||||
* Initializes all settings with their default values. |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
$this->options = new Options(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Returns the configuration related to options for autodoc. |
||||
* |
||||
* @return autodoc\Configuration\Options |
||||
*/ |
||||
public function getOptions() |
||||
{ |
||||
return $this->options; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
<?php |
||||
|
||||
|
||||
namespace autodoc\Configuration; |
||||
|
||||
use JMS\Serializer\Annotation as Serializer; |
||||
|
||||
/** |
||||
* Configuration object for an option |
||||
*/ |
||||
class Option |
||||
{ |
||||
/** |
||||
* @var string |
||||
* |
||||
* @Serializer\XmlAttribute |
||||
* @Serializer\Type("string") |
||||
*/ |
||||
protected $name; |
||||
/** |
||||
* @var string |
||||
* |
||||
* @Serializer\XmlAttribute |
||||
* @Serializer\Type("string") |
||||
*/ |
||||
protected $value; |
||||
|
||||
/** |
||||
* Registers the option name and value |
||||
* |
||||
* @param string $name |
||||
* @param string $value |
||||
*/ |
||||
public function __construct($name, $value) |
||||
{ |
||||
$this->name = $name; |
||||
$this->value = $value; |
||||
} |
||||
|
||||
/** |
||||
* Returns the option name. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getName() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* Returns the option value. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getValue() |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
<?php |
||||
|
||||
namespace autodoc\Configuration; |
||||
|
||||
use JMS\Serializer\Annotation as Serializer; |
||||
use phpDocumentor\Configuration\Merger\Annotation as Merger; |
||||
|
||||
/** |
||||
* Represents the settings in the phpdoc.xml related to options for autodoc |
||||
*/ |
||||
class Options |
||||
{ |
||||
|
||||
/** |
||||
* @var Option[] a list of options for autodoc |
||||
* |
||||
* @Serializer\Type("array<autodoc\Configuration\Option>") |
||||
* @Serializer\XmlList(inline = true, entry = "option") |
||||
* @Merger\Replace |
||||
*/ |
||||
protected $options; |
||||
|
||||
|
||||
/** |
||||
* Initializes this configuration directive with the required options. |
||||
* |
||||
* @param Option[] $options |
||||
*/ |
||||
public function __construct($options = array()) |
||||
{ |
||||
$this->options = $options; |
||||
} |
||||
|
||||
/** |
||||
* Returns a list of options. |
||||
* |
||||
* @return \Option[] |
||||
*/ |
||||
public function getOptions() |
||||
{ |
||||
return $this->options; |
||||
} |
||||
|
||||
/** |
||||
* Returns an option value. |
||||
* |
||||
* @return \Option |
||||
*/ |
||||
public function get($name) |
||||
{ |
||||
foreach ($this->options as $option) { |
||||
if ($option->getName() == $name) { |
||||
return $option; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
<?php |
||||
/** |
||||
* autodoc helper : aide à l'exécution de l'autodoc de spip |
||||
* |
||||
* Note: Surcharge de Cilex pour transmettre l'autoloader |
||||
*/ |
||||
|
||||
namespace autodoc\Helpers; |
||||
|
||||
use Cilex\Application as Cilex; |
||||
|
||||
/** |
||||
* Application class for autodoc helper. |
||||
* |
||||
* Can be used as bootstrap when the run method is not invoked. |
||||
*/ |
||||
class Application extends Cilex |
||||
{ |
||||
|
||||
public static $VERSION = '1.0.0'; |
||||
|
||||
|
||||
/** |
||||
* Registers the autoloader and necessary components. |
||||
* |
||||
* @param string $name Name for this application. |
||||
* @param string|null $version Version number for this application. |
||||
*/ |
||||
public function __construct($autoloader = null) |
||||
{ |
||||
parent::__construct('Autodoc Generator Helper', self::$VERSION); |
||||
$this['autoloader'] = $autoloader; |
||||
|
||||
// liste des commandes |
||||
$this->command(new Command\FromSpip()); |
||||
$this->command(new Command\FromPlugin()); |
||||
$this->command(new Command\FromZone()); |
||||
$this->command(new Command\FromSvn()); |
||||
$this->command(new Command\FromDirectory()); |
||||
$this->command(new Command\FromFile()); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,52 @@
|
||||
<?php |
||||
/** |
||||
* autodoc |
||||
* |
||||
* Surcharger l'écriveur Twig pour transmettre |
||||
* - la configuration de phpdocumentor |
||||
* - la version de phpdocumentor |
||||
*/ |
||||
|
||||
namespace autodoc\Plugin\Core\Transformer\Writer; |
||||
|
||||
|
||||
use phpDocumentor\Plugin\Twig\Writer\Twig as TwigPhpDoc; |
||||
use phpDocumentor\Configuration; |
||||
use phpDocumentor\Descriptor\ProjectDescriptor; |
||||
use phpDocumentor\Transformer\Transformation; |
||||
|
||||
class Twig extends TwigPhpDoc |
||||
{ |
||||
|
||||
/** @var Configuration */ |
||||
private $configuration; |
||||
|
||||
/** @var array */ |
||||
private $phpdocInfos = array(); |
||||
|
||||
|
||||
public function setPhpDocumentorVersion($version) { |
||||
$this->phpdocInfos['version'] = $version; |
||||
} |
||||
|
||||
public function getPhpDocumentorInfos() { |
||||
return $this->phpdocInfos; |
||||
} |
||||
|
||||
|
||||
public function setConfiguration(Configuration $configuration) { |
||||
$this->configuration = $configuration; |
||||
} |
||||
|
||||
public function getConfiguration() { |
||||
return $this->configuration; |
||||
} |
||||
|
||||
|
||||
protected function initializeEnvironment(ProjectDescriptor $project, Transformation $transformation, $destination) { |
||||
$environment = parent::initializeEnvironment($project, $transformation, $destination); |
||||
$environment->addGlobal('configuration', $this->getConfiguration()); |
||||
$environment->addGlobal('phpDocumentor', $this->getPhpDocumentorInfos()); |
||||
return $environment; |
||||
} |
||||
} |
@ -1,5 +1,6 @@
|
||||
{% block footer %} |
||||
Documentation automatique créée avec |
||||
<a href="http://www.phpdoc.org/">PHPDocumentor</a> {{ configuration.phpDocumentor.version }} |
||||
<a href="http://www.phpdoc.org/">PHPDocumentor</a> {{ phpDocumentor.version }} |
||||
- générée le {{ "now"|date("j/m/Y à H:i") }} |
||||
{% endblock %} |
||||
|
||||
|
Loading…
Reference in new issue