Wednesday, May 12. 2010Artikel zum Thema SoftwaremetrikenThis blog post is in German as the mentioned article was published in German.
In der heute erschienenen Ausgabe 4.10 des PHP Magazins ist auch ein Artikel von mir enthalten, und wie sollte es wohl anders sein *Trommelwirbel*, beschäftigt der sich mit dem Thema Softwaremetriken Über Kommentare, Anregungen und Kritik rund um den Artikel würde ich mich sehr freuen. Und sollte euch der Artikel gefallen haben, empfehle ich die Internationale PHP Conference 2010, die vom 30. Mai bis 2. Juni in Berlin stattfindet, an der ich teilnehmen und zwei Vorträge halten werden.
Posted by Manuel Pichler
in php, php_depend, phpmd, phpugdo, phpundercontrol, projects, staticReflection
at
09:04
| Comments (0)
| Trackbacks (0)
PHP-Magazin Artikel zum Thema SoftwaremetrikenThis blog post is in German as the mentioned article was published in German.
In der heute erschienenen Ausgabe 4.10 des PHP Magazins ist auch ein Artikel von mir enthalten, und wie sollte es wohl anders sein *Trommelwirbel*, beschäftigt der sich mit dem Thema Softwaremetriken Über Kommentare, Anregungen und Kritik rund um den Artikel würde ich mich sehr freuen. Und sollte euch der Artikel gefallen haben, empfehle ich die Internationale PHP Conference 2010, die vom 30. Mai bis 2. Juni in Berlin stattfindet, an der ich teilnehmen und zwei Vorträge halten werden.
Posted by Manuel Pichler
in php, php_depend, phpmd, phpugdo, phpundercontrol, projects, staticReflection
at
09:04
| Comments (0)
| Trackbacks (0)
Saturday, January 2. 2010staticReflection 0.1.4 releasedToday I have released version 0.1.4 of the staticReflection component. This release contains two critical bug fixes.
You can get the latest stable version of the staticReflection component through its PHP_Depend's PEAR channel: mapi@arwen ~ $ pear channel-discover pear.pdepend.org mapi@arwen ~ $ pear install pdepend/staticReflection-alpha or you can download the latest version from the staticReflection svn respository:
mapi@arwen ~ $ svn co http://svn.reflection.pdepend.org/trunk \
staticReflection
Posted by Manuel Pichler
in php, phpugdo, projects, staticReflection
at
23:38
| Comments (0)
| Trackbacks (0)
Sunday, November 29. 2009First release of the staticReflection component.Today I have released the first version of the staticReflection component. This component parses the source files of a project to provide reflection information identical to that provided by PHP's build in API, without loading the class declaration into the PHP runtime context. Due to the API compatibility the staticReflection component can simply be used as a drop-in replacement for the reflection extension. A few weeks ago I started just another script that utilized the tokenizer extension to extract some information from source code files. At that point I thought that the time had come to realize a project that was on my todo for a very long time. And here is the result of the first iteration, a userland reflection implementation that is api compatible with PHP's internal reflection extension. Beside the source parser and the reflection ast this component provides a unified interface to both reflection versions, which makes it easy to switch between different implementations. As a first use case for this component I have choosen autoload files, as they are used by the eZ Components. The generation of those files is really easy, simply parse a directory with source files and dump the result into a file.
<?php
use org\pdepend\reflection\Autoloader;
use org\pdepend\reflection\ReflectionSession;
// Include the bundled autoloader
include_once 'staticReflection/Autoloader.php';
// Register the autoload function
spl_autoload_register( array( new Autoloader(), 'autoload' ) );
// Create a new session
$session = new ReflectionSession();
// Create a directory query
$query = $session->createDirectoryQuery( );
$autoload = array();
foreach ( $query->find( __DIR__ . '/../../source/' ) as $class )
{
$autoload[$class->getName()] = $class->getFileName();
}
var_export( $autoload );
You can also use the static reflection implementation to analyze different versions of the same class in the same process, which is not possible with the build-in reflection API, because you cannot load multiple classes with the same name into the current runtime context. Beside parsing of a given directory or file the staticReflection component also supports direct access to a concrete class or interface through the name. Therefor it uses so called source resolvers, that perform a mapping between class names and the associated source files. The current release has two build-in resolvers, one using autoload arrays as they are used by the eZ Components and the other one uses the PEAR naming conventions and the configured include_paths to determine the source file for a given class name. The following example illustrates the usage of the PEAR source resolver.
<?php
use org\pdepend\reflection\Autoloader;
use org\pdepend\reflection\ReflectionSession;
use org\pdepend\reflection\factories\StaticReflectionClassFactory;
use org\pdepend\reflection\resolvers\PearNamingResolver;
include_once 'staticReflection/Autoloader.php';
spl_autoload_register( array( new Autoloader(), 'autoload' ) );
$session = ReflectionSession::createStaticSession(
new PearNamingResolver()
);
$class = $session->getClass( 'PEAR_Frontend' );
echo '- ', $class->getName(), PHP_EOL,
' ', $class->getFileName(), PHP_EOL;
This concept makes the component extremly flexible, because you can write your own source resolver that fulfills the requirements for your application.
Beside the source resolver concept the ReflectionSession can also be configured with a custom stack of ReflectionClassFactory objects that are used to retrieve a reflection class instance for a given class/interface name. To minimize the configuration overhead for common use cases the
But you can always build your own session configuration with a custom factory stack, by calling the <?php use org\pdepend\reflection\Autoloader; use org\pdepend\reflection\ReflectionSession; include_once 'staticReflection/Autoloader.php'; spl_autoload_register( array( new Autoloader(), 'autoload' ) ); $session = new ReflectionSession(); $session->addClassFactory( new MyFooFactory() ); $session->addClassFactory( new MyBarFactory() );
So how can you use this cool component in your application? This is really simple, just replace all <?php // ... // Previous instantiation // $ref = new ReflectionClass( 'Foo_Bar_Baz' ); // New cool solution $ref = ReflectionSessionInstance::get()->getClass( 'Foo_Bar_Baz' ); And add the following code to your bootstrap file:
<?php
// ...
ReflectionSessionInstance::set(
ReflectionSession::createInternalSession()
);
Finally some words to the requirements and the installation of this component. This component requires PHP in a version greater or equal 5.3.0. For installation you can use PHP_Depend's PEAR channel: mapi@arwen ~ $ pear channel-discover pear.pdepend.org mapi@arwen ~ $ pear install pdepend/staticReflection-alpha or you can download the latest version from the staticReflection svn respository:
mapi@arwen ~ $ svn co http://svn.reflection.pdepend.org/trunk \
staticReflection
Feel free to test this component and file bug-reports and/or feature-requests in the project issue tracker.
Posted by Manuel Pichler
in php, phpugdo, planet-php, projects, staticReflection
at
21:45
| Comments (2)
| Trackbacks (0)
(Page 1 of 1, totaling 4 entries)
|
ProjectsFurther stuffCategories |

