Skip to content

Instantly share code, notes, and snippets.

@lkwdwrd
Created January 4, 2016 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkwdwrd/4965896623e662bbcc6f to your computer and use it in GitHub Desktop.
Save lkwdwrd/4965896623e662bbcc6f to your computer and use it in GitHub Desktop.
Docblock Factory Play
<?php
namespace WP_Parser\Reflection;
use WP_Parser\Reflection\Doc_Block;
use phpDocumentor\Reflection\Location;
use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use phpDocumentor\Reflection\Types\Context;
final class Doc_Block_Factory implements DocBlockFactoryInterface {
/**
* Factory method for easy instantiation.
*
* @param string[] $additionalTags
*
* @return DocBlockFactory
*/
public static function createInstance( array $additionalTags = [] ){
return new self( $additionalTags );
}
private $_docblock_factory;
public function __construct( array $additionalTags ) {
$this->_docblock_factory = DocBlockFactory::createInstance( $additionalTags );
}
/**
* @param string $docblock
* @param Types\Context $context
* @param Location $location
*
* @return DocBlock
*/
public function create( $docblock, Context $context = null, Location $location = null){
// Try to unwrap objects if needed.
if ( is_object( $docblock ) ) {
$docblock = ( method_exists( $docblock, 'getDocComment' ) ) ? $docblock->getDocComment() : '';
}
return new Doc_Block( $this->_docblock_factory->create( $docblock, $context, $location ), $docblock );
}
}
<?php
namespace WP_Parser\Reflection;
use WP_Parser\Reflection\Reflector_Meta;
use phpDocumentor\Reflection\DocBlock;
final class Doc_Block {
use Reflector_Meta;
private $_docblock;
private $_raw_text;
public function __construct( DocBlock $dockblock, $raw_text ) {
$this->_docblock = $dockblock;
$this->_raw_text = $raw_text;
}
public function getRawText() {
return $this->_raw_text;
}
public function __call( $method, $args ) {
if ( method_exists( $this->_docblock, $method ) ) {
return call_user_func_array( array( $this->_docblock, $method ), $args );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment