vm5 / php-parser
This package can parse easily PHP Files. There is a visitor which removes all the PHP comments (NOT the DocBlocks) - including @author and @copyright tags from docblocks.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:package
Requires
This package is auto-updated.
Last update: 2024-11-27 01:03:35 UTC
README
Sample usage:
<?php use PhpParser\NodeTraverser; use PhpParser\PrettyPrinter; use VM5\PhpCommentsRemover\Saver\SameFileSaver; use VM5\PhpCommentsRemover\Visitor; require 'vendor/autoload.php'; $parserFactory = new \PhpParser\ParserFactory(); $docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); $serializer = new \phpDocumentor\Reflection\DocBlock\Serializer(); $docBlockVisitors = [ new \VM5\PhpParser\DocBlockVisitor\CommentsRemoverDocBlockVisitor(), ]; $visitor = new \VM5\PhpParser\NodeVisitor\DocBlockVisitor($docBlockFactory, $serializer, $docBlockVisitors); $nodeTraverser = new NodeTraverser(); $nodeTraverser->addVisitor($visitor); $removeComments = new \VM5\PhpCommentsRemover\CommentsRemover( $parserFactory->create(\PhpParser\ParserFactory::PREFER_PHP5), $traverser, new PrettyPrinter\Standard, new SameFileSaver() ); $removeComments->parseDirectory(__DIR__); $removeComments->parseFile('file.php');