Giter Club home page Giter Club logo

plugin-twig's Introduction

License: MIT Qa workflow Packagist Version Packagist Pre Release Version Downloads

phpDocumentor

What is phpDocumentor?

phpDocumentor stands as the de-facto documentation tool for PHP projects, offering a robust solution for generating comprehensive documentation effortlessly. By analyzing your PHP source code and DocBlock comments, phpDocumentor generates a complete set of API documentation, making it an indispensable tool for developers striving for clear and well-documented codebases.

Beyond its prowess in API documentation, phpDocumentor goes further by providing additional features. It is equipped with the ability to create UML diagrams, making it a versatile tool for visualizing code structure. Additionally, phpDocumentor offers a full-featured markup language parser, supporting both RestructuredText and Markdown syntax. This flexibility allows you to document your project using the markup language that best suits your preferences.

A notable feature of phpDocumentor is its capability to include parts of your API documentation directly into your RestructuredText documentation. This integration ensures that your documentation and code remain in sync, saving you time and effort in maintaining accurate and up-to-date project documentation.

Inspired by its predecessors, phpDocumentor 1 and JavaDoc, phpDocumentor continues to innovate, staying up-to-date with the latest technologies and PHP language features. This commitment ensures that developers have access to the best possible documentation experience, aligning with modern development practices.

In this guide, we will explore the various features of phpDocumentor, from its core functionality in generating API documentation to its advanced capabilities in parsing markup languages. Whether you're a beginner or an experienced developer, phpDocumentor is your ally in creating well-documented, maintainable, and understandable PHP projects.

phpDocumentor v3 (Stable)

v3 is the latest stable release.

Documentation

For more detailed information, you can check our online documentation at https://docs.phpdoc.org/.

Features

phpDocumentor supports the following:

  • PHP 7.0+ compatible, full support for Namespaces, Closures and more are provided.
  • Docblock over types, docblocks can be more explicit about types not all formats are supported by native php.
  • Shows any tag, some tags add additional functionality to phpDocumentor (such as @link).
  • Low memory usage, peak memory usage for small projects is less than 20MB, medium projects 40MB, and large frameworks 100MB.
  • Incremental parsing, if you kept the Structure file from a previous run, you get an additional performance boost of up to 80% on top of the mentioned processing speed increase above.
  • Easy template building, if you want to make a branding you only have to call 1 task and edit 3 files.
  • Two-step process, phpDocumentor first generates a cache with your application structure before creating the output. If you'd like you can use that to power your own tools or formatters!
  • Generics support, with more static analysis in php types have become more complex. phpDocumentor understand these types. And will render them as first class types.

Installation

PhpDocumentor requires PHP 8.1 or higher to run. However, code of earlier PHP versions can be analyzed.

All templates provided with phpDocumentor have support for Class diagrams based on the read code base. This will require the application [PlantUml] to be installed on the machine running phpDocumentor. Rendering the class diagrams using [PlantUml] is optional, and warnings about missing [PlantUml] can be ignored. However, your documentation will contain some dead links in this case. Class diagram will be created with option --setting=graphs.enabled=true.

There are 4 ways to install phpDocumentor:

  1. Using phive (recommended)
  2. Using the PHAR (manual install)
  3. Via Docker
  4. Via Composer

Using Phive

$ phive install phpDocumentor

For more information about phive have a look at their website. Now you have phpDocumentor installed, it can be executed like this:

php tools/phpDocumentor

Using the PHAR

  1. Download the phar file from https://github.com/phpDocumentor/phpDocumentor/releases
  2. You can execute the phar like this: php phpDocumentor.phar

Via Docker

  1. $ docker pull phpdoc/phpdoc
  2. $ docker run --rm -v $(pwd):/data phpdoc/phpdoc

Via Composer (not recommended)

But wait? What about composer?

Ah, you discovered our secret. There is a phpdocumentor composer package that you can use to install phpDocumentor.

However: phpDocumentor is a complex application, and its libraries are used in countless other libraries and applications (2 of our libraries have more than 150 million downloads each); and this means that the chances for a conflict between one of our dependencies and yours is high. And when I say high, it is really high.

So, because of the above: we do not endorse nor actively support installing phpDocumentor using Composer.

How to use phpDocumentor?

The easiest way to run phpDocumentor is by running the following command:

$ phpdoc run -d <SOURCE_DIRECTORY> -t <TARGET_DIRECTORY>

This command will parse the source code provided using the -d argument and output it to the folder indicated by the -t argument.

phpDocumentor supports a whole range of options to configure the output of your documentation. You can execute the following command, or check our website, for a more detailed listing of available command-line options.

$ phpdoc run -h

Configuration file(s)

phpDocumentor also supports the use of configuration files (named phpdoc.xml or phpdoc.dist.xml by default). Please consult the documentation to see the format and supported options.

Nightly builds

PhpDocumentor doesn't have nightly releases. However, during each pipeline a phar artifact is built. If you want to test the bleeding edge version of phpDocumentor, have a look in the actions section of this repository. Each successful QA workflow has an Artifacts section at the bottom with the phar artifact built.

Contact

Reaching out to us is easy, and can be done with:

plugin-twig's People

Contributors

mvriel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

plugin-twig's Issues

Using $this when not in object context

I just fresh installed phpDocumentor via Pear (v2.6.0). I ran a vanilla parse and got a fatal error apparently in the Twig extension:

$ sudo phpdoc -d CheddarGetter -t CheddarGetter/docs --ignore CheddarGetter/docs
Collecting files .. OK
Initializing parser .. OK
Parsing files
Parsing /vagrant/cheddargetter/library/CheddarGetter/Client/AdapterInterface.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Client/CurlAdapter.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Client/Exception.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Client/ZendAdapter.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Client.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/example/example.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Http/AdapterInterface.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Http/NativeAdapter.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Http/ZendAdapter.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Response/Exception.php
Parsing /vagrant/cheddargetter/library/CheddarGetter/Response.php
Storing cache in "/vagrant/cheddargetter/library/CheddarGetter/docs" .. OK
Load cache                                                         ..    0.045s
Preparing template "clean"                                         ..    0.020s
Preparing 15 transformations                                       ..    0.000s
Build "elements" index                                             ..    0.003s
Replace textual FQCNs with object aliases                          ..    0.029s
Resolve @link and @see tags in descriptions                        ..    0.004s
Build "packages" index                                             ..    0.002s
Collect all markers embedded in tags                               ..    0.001s
Build "namespaces" index and add namespaces to "elements"          ..    0.001s
Transform analyzed project into artifacts                          .. PHP Fatal error:  Using $this when not in object context in /usr/share/php/phpDocumentor/src/phpDocumentor/Plugin/Twig/Extension.php on line 192
[2014-07-01 12:04:51] phpDocumentor.ALERT: Fatal Error (E_ERROR): Using $this when not in object context {"file":"/usr/share/php/phpDocumentor/src/phpDocumentor/Plugin/Twig/Extension.php","line":192} []

Plugin-twig doesn't load to its lastest version with the 'dev' installer.php

When I run

php installer.php dev

This plugin doesn't have the latest version of the files. For example, this correction is not there : 8395fca

I need to have lastest commits :

rm -rf vendor/phpdocumentor/plugin-twig
git clone https://github.com/phpDocumentor/plugin-twig.git  vendor/phpdocumentor/plugin-twig

I wonder if this is a normal action ?

Send whole ast to twig plugins and twig templates

It's sometimes interesting to have whole SimpleXMLElement ast an not only a SimpleXMLElement node.

A simple example is trying to write the phpDocumentor version in a class or method template : with only the node, we can't retrieve parents (simpleXMLElement can't access parents) and we do not have ast root either.

A twig plugin could also add a global variable 'ast', but unfortunaly, they don't too have ast root. They just have the node.

So I suggest

  • to send 'ast' and 'ast_node' into twig templates
  • to send to twig plugins :
    • SimpleXMLElement $structure The whole ast
    • SimpleXMLElement $node The ast node

With hope that my english is understandable !

Add a Twig extension from template.xml create error

Hi,

I'm just discover this twig plugin and I want to add the "dump" twig function to my twig templates to test something.
2 things are needed to do that :

    1. add Twig_Extention_Debug class to twig extension
    1. active 'debug' option on Twig_Environnement instance

I don't know how to do 2) without making a twig extension or add anywhere $env->enableDebug(); (maybe it is possible directly in a twig template ?)

But this is for 1) I write this issue.

When I add in template.xml :

<parameters>
    <twig-extension>
        Twig_Extension_Debug
    </twig-extension>
</parameters>

I got 2 errors :

  1. First is here https://github.com/phpDocumentor/plugin-twig/blob/master/src/phpDocumentor/Plugin/Twig/Transformer/Writer/Twig.php#L208 . $extension is something like "\n Twig_Extension_Debug\n " and class_exists won't work.
    This need a $extension = trim($extension)

  2. Second is more strange and here : https://github.com/phpDocumentor/plugin-twig/blob/master/src/phpDocumentor/Plugin/Twig/Transformer/Writer/Twig.php#L220 . The class_implements('ExtensionInterface') doesn't load the class and I got error «PHP Warning: class_implements(): Class ExtensionInterface does not exist and could not be loaded in /home/marcimat/www/documentation/phpdoc/vendor/phpdocumentor/plugin-twig/src/phpDocumentor/Plugin/Twig/Transformer/Writer/Twig.php on line 221»
    Writing something like that run :
    $extension_object = (class_exists('ExtensionInterface') and class_implements('ExtensionInterface'))

But, isn't this test strange ? because $extension name isn't tested . Is this test shouldn't be something like :
(in_array('ExtensionInterface', class_implements($extension)) ?

MM.

Two problems with `<twig-extension>` parameters in template.xml

There is two problems with this declaration into template.xml :

    <parameters>
        <twig-extension>
            Twig_Extension_Debug
        </twig-extension>
        <twig-extension>
            phpDocumentor\Plugin\Zora\TwigZora
        </twig-extension>
    </parameters>
  1. The PHP Class witch is intended to be load like Twig_Extension_Debug contains spaces beetween the word and the class isn't found. This need a trim for exemple here https://github.com/phpDocumentor/plugin-twig/blob/master/src/phpDocumentor/Plugin/Twig/Transformer/Writer/Twig.php#L208
  2. When there is at least two tag <twig-extension>, only the second one is kept. The function convertSimpleXmlToArray() into phpDocumentor\Transformer\Transformation seems to rewrite previous entry and so keep only the last one.

But for 2. point, maybe it's my writing witch isn't good ? How-to start multiple twig extensions ?

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.