Skip to content
This repository has been archived by the owner on Aug 9, 2018. It is now read-only.

masterexploder/DocumentingReflectionMethod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Documenting Reflection Method Class

This class is designed to parse and tokenize a PHP DocBlock for a class method. This is useful because it enables you to add custom annotations to your methods for various uses.

Personally, I've used it to help create rails-style helper classes in my frameworks. I use smarty as my template rendering engine, and use helper classes to create template functions, modifiers and blocks. By using a custom annotation (@helperType) in my DocBlocks, I can properly register the class method of a helper as a function, modifier or block.

Usage

Usage is pretty simple, you just need to do a bit of reflecting. Say you had a class that looks like:

class Foo
{
	/**
	 * Does Something
	 *
	 * @someAnnotation FooBar
	 * @return void
	 */
	public function bar ()
	{
		// do stuff
	}
}

You could get the tags, and annotation as a result, by doing the following (assuming you've included the DocumentingReflectionMethod class):

$rc 		= new ReflectionClass('Foo');
$instance 	= $rc->getInstance();
$docs		= new DocumentingReflectionMethod($instance, 'bar');
$tags		= $docs->getTags();

if (isset($tags['someAnnotation']))
{
	// do whatever you want
}

Other Info

The class itself is pretty well-documented, so you shouldn't have much trouble figuring things out. If you want some brownie points, you could always create /edit wiki pages for various pieces of functionality, and if you need help / found a bug, file a ticket in the issues

About

Parser / Tokenizer for DocBlocks in PHP Class Methods

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages