plantUML:run command to print UML diagrams

Future release 2.0.0RC3 adopt another new command

After conversion of concrete example "Measuring the size of a PHP project" to a new command (see previous post), I’ve decided to include in future release 2.0.0RC3 a new command plantUML:run (commit 566bf46).

This plugin will replace the concrete example "Make UML diagrams".

With this plugin you can make package UML diagram (http://plantuml.sourceforge.net/classes.html#Using), e.g : with such simple reflect.json config file.

{
    "source-providers": [
        {
            "in": "phar:///var/dist/phpreflect-2.0.0RC2-6-ge55464a.phar as Reflect2RC2",
            "path": "src/",
            "name": "*.php"
        }
    "plugins": [
        {
            "name": "PlantUML",
            "class": "Bartlett\\Reflect\\Plugin\\PlantUML\\PlantUMLPlugin"
        }
}
Example 1. Run the command below
$ php bin/reflect --profile --plantUML:run --alias Reflect2RC2 --package="Bartlett\Reflect\Model"

You will get such output.

package "Bartlett\\Reflect\\Model" {
abstract AbstractFunctionModel
abstract AbstractModel
class ClassModel
class ConstantModel
class DependencyModel
class FunctionModel
class IncludeModel
class MethodModel
class PackageModel
class ParameterModel
class PropertyModel
}

Put in in a file , e.g packageDiagram.plantuml, and send the result to plantUML

$ java -jar plantuml.jar packageDiagram.plantuml

and you will get a PNG image as this one :

bartlett_reflect_model.packagediagram.png
Example 2. Run the command below
$ php bin/reflect --profile --plantUML:run --alias Reflect2RC2 --class="Bartlett\Reflect"

You will get such output.

class Reflect{
    #pm
    #files
    +getProviderManager()
    +setProviderManager()
    +parse()
    +getPackages()
    +getFiles()
    -buildFromCache()
}
AbstractDispatcher <|-- Reflect
interface ManagerInterface {
}
ManagerInterface <|.. Reflect

Put in in a file , e.g classDiagram.plantuml, and send the result to plantUML

$ java -jar plantuml.jar classDiagram.plantuml

and you will get a PNG image as this one :

bartlett_reflect.classdiagram.png
Published by Laurent Laville on 2014-02-23

Analyser:run command with a structure report

Future release 2.0.0RC3 will adopt a new command

Current version 2.0.0RC2 is a bit useless in CLI mode. I’ve decided to include in next Release Candidate (commit f99c2bf) a new command analyser:run that will display a structure report equivalent to Sebastian Bergmann phploc solution.

With a such reflect.json config file:

{
    "source-providers": [
        {
            "in": "phar:///var/dist/PHP_Reflect-1.0.0.tar as Reflect1",
            "path": "PHP/",
            "name": "*.php"
        }
    "plugins": [
        {
            "name": "Analyser",
            "class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
        }
    ],
    "analysers" : [
        {
            "name": "Structure",
            "class": "Bartlett\\Reflect\\Analyser\\StructureAnalyser"
        }
    ]
}

Run the command below:

$ php bin/reflect --profile --analyser:run --alias Reflect1

You will get such output.

Data Source Analysed

Directories                                          2
Files                                                3

Structure
  Namespaces                                         1
  Interfaces                                         0
  Traits                                             0
  Classes                                          158
    Abstract Classes                                 4 (2.53%)
    Concrete Classes                               154 (97.47%)
  Methods                                           37
    Scope
      Non-Static Methods                            37 (100.00%)
      Static Methods                                 0 (0.00%)
    Visibility
      Public Method                                 34 (91.89%)
      Protected Method                               3 (8.11%)
      Private Method                                 0 (0.00%)
  Functions                                          1
    Named Functions                                  1 (100.00%)
    Anonymous Functions                              0 (0.00%)
  Constants                                         70
    Global Constants                                70 (100.00%)
    Class Constants                                  0 (0.00%)

Time: 4.05 seconds, Memory: 15.00Mb
Published by Laurent Laville on 2014-02-21

Reflect 2.0.0RC2 PHAR version FIXED

PHAR version of Reflect 2.0.0RC2 bundles now all dependencies.

The WARNING I’ve emitted in my previous post should be forgotten if you use the new version:

$ php phpreflect.phar --version
phpReflect version 2.0.0RC2-6-ge55464a build e55464ab5810ac7c8f8328342cc7fa273404ed81
Published by Laurent Laville on 2014-02-20

Reflect 2.0.0RC2 PHAR version WARNING

A little explain about Reflect 2.0.0RC2 and PHAR version.

When I’ve packaged the PHAR version, I’ve not used any specific stub, but just the same launcher as git source code version.

This is major reason you need to have previously installed PHP_Timer and Symfony/Class-Loader 2.4 or better.

I’ll fix this issue, to have a really phar version without any dependencies in first Release Candidate.

Be aware, and sorry for disappointment !

Published by Laurent Laville on 2014-02-20

Reflect 2.0.0RC2 has just been released.

After many tries to have the more evolutive parser as possible, I’ve finally adopted PHP-Parser 1.0-dev 5 days ago.

Be aware that I used the Nikita Popov version with a little patch (see Pull Request #95) relative to magic constants.

As there are no PEAR package available for PHP-Parser, Reflect 2.0.0RC2 will be available only on two formats :

  • a PHAR version that bundles all dependencies (PHP-Parser + patch (1.0.0-dev+gh95), Symfony Finder 2.4.1, EventDispatcher 2.4.1, Console 2.4.1) in a single file.

  • a composer version.

Caution about the composer version

To use my patch (1.0.0-dev+gh95) on base Nikita 1.0-dev version, add on your composer.json file the following contents:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/llaville/PHP-Parser"
        }
    ],
    "require": {
        "php": ">=5.3.0",
        "nikic/php-parser": "dev-MagicConst as 1.0.*@dev"
    }
}

You should get something like this output

Loading composer repositories with package information
Installing dependencies
  - Installing nikic/php-parser (dev-MagicConst d287cb4)
    Cloning d287cb42896ba8921fda64fc5868093647fd65de

Writing lock file
Generating autoload files

The PHAR version was built with the Box Project. The config file box.json is available on the github repository.

This phar version is both compatible with CLI and other SAPI

For web usage, just include the phar version, and use API as explained.

<?php
require '/path/to/dir/phpreflect.phar';
// ...
What is planned for the final stable version:
  • Fixes issues if users found something wrong.

  • Adds one analyser that will replace the concrete example that measure size of project.

  • Adds one plugin to generate PlantUML diagrams as presented in concrete example make UML diagrams.

Published by Laurent Laville on 2014-02-18

PHP-Parser migration is over

Reflect 2.0.0RC2 has adopted PHP-Parser 1.0-dev

I’ve just published the migration code that adopt PHP-Parser 1.0-dev

Take care, that I used the basic code of PHP-Parser 1.0-dev with a little modification about magic constants. See my Pull Request #95.

Current code of Reflect 2 is PSR2 standard compliant and unit tests are all OK.

PHPUnit 3.7.31 by Sebastian Bergmann.

...............................................................  63 / 125 ( 50%)
..............................................................

Time: 2.46 seconds, Memory: 6.50Mb

OK (125 tests, 125 assertions)

As I’m waiting approval of two Pull Requests :

I will release monday 17th February only a PHAR version that will embeded all vendor code to run correctly.

I will continue to test this base source code (that need again some minor fixes, I know) in real condition with well known packages : Symfony, Zend Framework, and more …

Be ready monday to test it by yourself. All feedback are welcome !

Published by Laurent Laville on 2014-02-13

A new parser for Reflect 2.0.0RC2

Future release 2.0.0RC2 will adopt PHP-Parser

Two weeks ago, I’ve detected performance issues with the core of Reflect parser. I’ve then begun to rewrite the core of the parser, and now I don’t like it.

It’s not enough stable, and I don’t want to loose my time to test all conditions.

So, that this the reason why I’ve adopted yesterday a new external parser written in PHP : PHP-Parser. This parser is awesome and fast. Easy to understand how to implement (uses visitors design and an Abstract Syntax Tree (AST)).

I’ve migrated in one day my code to use this new parser, and I’ve begin this morning to test it in real condition.

I should publish the latest version of my source code tomorrow.

It sound nice to me that the second release candidate will be available this monday 17th February.

Published by Laurent Laville on 2014-02-12

Preview of the Command-Line part of Reflect 2.0.0RC2

Even if full source code of RC2 is not yet available, I’ve just uploaded the command-line part that is common to CompatInfo.

Here is a screenshot preview, but you can test it yourself (independant from other software components).

There are three categories of command:

analyser
Allow to plug your own analysers without to change one line of Reflect core code (see the analysers section of reflect.json sample file).
plugin
Allow to extend features of Reflect without to hack the core code (see the plugins section of reflect.json sample file).
provider
Allow to identify data source to parse. Follow all Symfony Finder rules (see the source-providers section of reflect.json sample file).
Published by Laurent Laville on 2014-02-03

Release 2.0.0RC2 planned

A new core code for the second release candidate of version 2.0

After lot of test on huge source code, like Zend Framework 1.12, I’ve be faced on a major performance issue with the first RC code.

This is the reason, why I’ve decided to rewrite the core code of PHP Reflect one times again.

Even if I’m still under test protocol, I got good results, and the second release candidate of version 2.0 should come very soon now (probably next week).

Published by Laurent Laville on 2014-02-01