Skip to content

Commit

Permalink
Merge pull request #7 from abbadon1334/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
abbadon1334 committed Jul 11, 2019
2 parents 105c520 + 3d53917 commit 1d45cb1
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ An example for the documentation output can be found in our [own documentation](

Install phpdoc-to-rst to your project directory:

composer require --dev juliushaertl/phpdoc-to-rst
composer require --dev abbadon1334/phpdoc-to-rst

Run the command line tool to parse the folders containing your PHP tree and render the reStructuredText files to the output directory:

Expand Down
63 changes: 63 additions & 0 deletions docs/api/JuliusHaertl/PHPDocToRst/ApiDocBuilder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,66 @@ Methods



.. rst-class:: private

.. php:method:: private parseInterfaces( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: array



.. rst-class:: private

.. php:method:: private parseClasses( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: array



.. rst-class:: private

.. php:method:: private parseTraits( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)





.. rst-class:: private

.. php:method:: private parseFunctions( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: bool | string



.. rst-class:: private

.. php:method:: private parseConstants( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)





157 changes: 99 additions & 58 deletions src/ApiDocBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,71 +194,20 @@ private function parseFiles()
foreach ($this->extensions as $extension) {
$extension->prepare();
}

$this->log('Start building files');

foreach ($this->project->getFiles() as $file) {
/*
* Go though interfaces/classes/functions of files and build documentation
*/
foreach ($file->getInterfaces() as $interface) {
$fqsen = $interface->getFqsen();
$builder = new InterfaceFileBuilder($file, $interface, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $interface->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addInterface($fqsen);
}
$this->debug('Written interface documentation to '.$filename);
}

foreach ($file->getClasses() as $class) {
$fqsen = $class->getFqsen();
$builder = new ClassFileBuilder($file, $class, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $class->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($class->getFqsen(), 1), '\\') === false) {
$this->project->getRootNamespace()->addClass($fqsen);
}
$this->debug('Written class documentation to '.$filename);
}
$this->parseInterfaces($file);
$this->parseClasses($file);
$this->parseTraits($file);
$this->parseFunctions($file);
$this->parseConstants($file);

foreach ($file->getTraits() as $trait) {
$fqsen = $trait->getFqsen();
$builder = new TraitFileBuilder($file, $trait, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $trait->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addTrait($fqsen);
}
$this->debug('Written trait documentation to '.$filename);
}

// build array of functions per namespace
foreach ($file->getFunctions() as $function) {
$namespace = substr(PhpDomainBuilder::getNamespace($function), 0, -2);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->functions)) {
$this->functions[$namespace] = [];
}
$this->functions[$namespace][] = $function;
}
// build array of constants per namespace
foreach ($file->getConstants() as $constant) {
$namespace = PhpDomainBuilder::getNamespace($constant);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->constants)) {
$this->constants[$namespace] = [];
}
$this->constants[$namespace][] = $constant;
}
}
}

Expand Down Expand Up @@ -337,4 +286,96 @@ public function addExtension($class, $arguments = [])
$this->extensionNames[] = $class;
$this->extensionArguments[$class] = $arguments;
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseInterfaces(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getInterfaces() as $interface) {
$fqsen = $interface->getFqsen();
$builder = new InterfaceFileBuilder($file, $interface, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $interface->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addInterface($fqsen);
}
$this->debug('Written interface documentation to '.$filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseClasses(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getClasses() as $class) {
$fqsen = $class->getFqsen();
$builder = new ClassFileBuilder($file, $class, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $class->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($class->getFqsen(), 1), '\\') === false) {
$this->project->getRootNamespace()->addClass($fqsen);
}
$this->debug('Written class documentation to '.$filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseTraits(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getTraits() as $trait) {
$fqsen = $trait->getFqsen();
$builder = new TraitFileBuilder($file, $trait, $this->extensions);
$filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string) $trait->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string) substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addTrait($fqsen);
}
$this->debug('Written trait documentation to '.$filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseFunctions(\phpDocumentor\Reflection\Php\File $file) :void
{
// build array of functions per namespace
foreach ($file->getFunctions() as $function) {
$namespace = substr(PhpDomainBuilder::getNamespace($function), 0, -2);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->functions)) {
$this->functions[$namespace] = [];
}
$this->functions[$namespace][] = $function;
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseConstants(\phpDocumentor\Reflection\Php\File $file): void
{
// build array of constants per namespace
foreach ($file->getConstants() as $constant) {
$namespace = PhpDomainBuilder::getNamespace($constant);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->constants)) {
$this->constants[$namespace] = [];
}
$this->constants[$namespace][] = $constant;
}
}
}

0 comments on commit 1d45cb1

Please sign in to comment.