PHP Classes

PHP Code Gleaner and Analyzer Tool: Scan PHP scripts to extract data about the code

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 272 All time: 7,648 This week: 192Up
Version License PHP version Categories
code-gleaner 1.2.1Custom (specified...5PHP 5, Language, Code Generation, Par...
Description Author

This package can scan PHP scripts to extract data about the code.

It can scan and parse given PHP code files to collect details about any classes, functions, constants of a given project.

The package can build maps of classes, constants and functions in order to generate autoloader code with support to namespaces.

Innovation Award
PHP Programming Innovation award winner
March 2018
One way for developers to become more productive is to use code generation tools that produce code based on relevant information provide by files created by the developers.

This package can scan the files code of an existing project to extract relevant information and so be able to generate useful code files like maps for autoloading or any other purposes.

Manuel Lemos
Picture of zinsou A.A.E.Mo´se
  Performance   Level  
Name: zinsou A.A.E.Mo´se is available for providing paid consulting. Contact zinsou A.A.E.Mo´se .
Classes: 50 packages by
Country: Benin Benin
Age: 32
All time rank: 7051 in Benin Benin
Week rank: 170 Up1 in Benin Benin Equal
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

PHP Code Gleaner is an useful package that helps to collect Classes,Functions,Constants of a given PHP Project
and build classes map,constants map and functions map.
The package can collect all the project's functions in a file or in a specific directory.
In case of directory,each file will be renamed with the same name as the function it contains 
and namespaces are also supported and can be preserved or no.
It can also collect all the project's classes in a file or in a specific directory.
In case of directory,each file will be renamed with the same name as the class it contains 
and  namespaces are also supported and can be preserved or no.
The package allows also to build easily and efficiently  autoloader that will always include the right file,
however the name you call it, for the right class or the right function.The possibilities of failure for this kind of 
autoloader are less than 1/100,Provided that the  class or function really exists while building the autoloader or were
added later manually.

The package contains six classes which are:

-Tokens_grabber: useful for extract all the PHP tokens in a file and retrieve namespaces

-Function_grabber which is a grabber that extends the Tokens_grabber for retrieving 
all kinds of functions and their contents in a file

-Classes_grabber which is a grabber that extends the Tokens_grabber for retrieving all kinds of classes and
 their contents in a file
-Constants_grabber which is a grabber that extends the Tokens_grabber for retrieving all
 kinds of constants and their values in a file
-Project_info_collector is a main class that make usage of the four others classes to retrieve all 
functions,classes,and constants from a specified project's path,and build maps and autoloaders...But
be careful when you use the methods Grab{Functions/Classes}ToFile or GrabFunctionsToStatic.Indeed the generated file can contain
duplicate data so you will need to check this manually(delete or rename it) 
or use the  DuplicateHelper class to achieve the duplicate deletion .
In the case of classes, the parent classes ,interfaces and trait are always copied before the classes which extend,implement or 
use them...

-DuplicateHelper is a helper class which helps in duplicate functions or classes finding  after use of 
Grab{Functions/Classes}ToFile or GrabFunctionsToStatic.It can parse the generated functions or classes file to find duplicate
contents and return the results as array of duplicate elements containing for each element ,its content,
its start line ,its end line ,its start offset and its end offset.This will help to easily even manually
review the code to delete duplicates or rename them.It also get a method which automatically parse the file,
find the duplicate contents and delete or rename each time n-1 occurrences to avoid fatal errors when using the code.
Renaming instead of deleting can be useful especially when functions/classes do have the same name but different 

Suppose one moment you want to start a new project but you don't want to manually copy and paste your 
functions,classes codes then you can use this package that will automatically parse your project files and find all functions ,classes.

suppose also that you are new on an old project which is maintained by someone else since a moment,
You will have a lot of difficulties even with a good documentation to know where to find each class,
function and last but not least constants which are very important in every projects as they are part
of the core then this package can map in just a laps all you need to know and then make you earn 
lot of time...   

Any common autoloader need a specific strategy based on  classes files names or specific  files hierarchy
Even Composer need json file to build automatically efficient classes map but also its autoloader.
With this package no need of specific file system hierarchy or class naming strategy.The package can also help
to make conversion between different autoloader specifications.

As the package find itself the classes and functions in each file and build a precise map,It can build
autoloader even when the file name strategy is not defined.Some may say this is  anarchic but i say 
every developers didn't yet have the same level of competences and this must not prevent them to work together.
So we won't need to rename each file we download before use it in a project.

Suppose you have lot of project and you want to make a test project outer in a specific directory but you need
some of the classes from each project to work without copy them in your new directory,then you can use
this package to build a map and  an anarchic autoloader and all is done

By extending this package you can even built more advanced feature...So enjoy it and let me know
what you are using it for in the forums...or contact me at 
                                  How to use it
First download a fresh copy from PHPCLASSES 
Then unzip the file in your chosen directory 
Run the install.php file only once 

From there you can use the file testAutoloader.php from anywhere you want.
For example you can run from its current location in the browser to build classes maps,functions maps etc...
of your chosen project 

but all this will be saved automatically in the same folder as the testAutoloader.php file .
Once your maps and autoloaders are built or anything else you do with the package you can use the autoloader file from anywhere.

Suppose that you unzip the package in the folder grabber which is itself in the root directory of your server(it can be
anywhere else)

so you got
-root-----grabber--------- testAutoloader.php
			     --------- another package file...
			     --------- install.php
		         --------- etc......

once you run the install file, the package is well configured to start working properly.
If you want for example your autoloader file and your classes map for your project(s)
stay in the root file:
copy the testAutoloader.php file to the root directory
then open this copy and change this line :

require_once(__DIR__ .DIRECTORY_SEPARATOR .'Autoloader_pjc_1517055626.php');

from there anything you will do with this file will be saved in the root directory.

To build your first classes map:

Open the testAutoloader.php file and 
uncomment the line // $x=$Dir->BuildClassesMap();
in the file there is an uncommented line that you can comment to disable it :
$x=$Dir->GrabInfos();//built classes,functions,constants map and their autoloader once...

Run now the file in the browser and wait until it loads the results.
In your root directory you will now see two files 
an autoloader  file that looks like Autoloader_pjc_1517055626.php
and another file (the class map)that looks like this projectsClasses1517253095.pjc .
Never alter them manually. 

You can now include The generated autoloader anywhere you want exactly as you use the composer autoloader.

PS: You can proceed like that for any other directory if you don't want your classes map and other stay in root directory.
									how to use DuplicateHelper class

This class is useful when you don't have time to review the gleaned code before use it in your 
project.Indeed sometimes different projects on your server or even single project sometimes can contain
same data .Of course the kind of data which interested us here are classes and functions .PHP
didn't allow to define many times same classes or functions in the same file.So if 
you do it, this will lead to fatal errors.When then you use the Grab{functions/classes}ToFile methods or
GrabFunctionsToStatic on a big project or on many projects together.The generated file can contain 
duplicate data.This class allows to quickly review the code manually or automatically keep only one instance 
of each duplicate function or class .

Its usage is really simple.

After you build the project file as shown in the testAutoloader.php file 

//be sure to use this on page where the package built in autoloader is included just as in the testAutoloader.php file

$d=new DuplicateHelper();// instantiate the helper
$y=new Functions_grabber('projectsFunctions1517157121.php');//parse the PHP code with the specific grabber :
//Function_grabber for functions and Classes_grabber for classes

print_r($d->getDuplicateContent($y));//get the duplicate contents informations as indicated above 
//only useful for manual review 

$d->justKeepOne($y);//just act on the file and remove duplicate content;	only useful for automatic review	

$d->justRenameDuplicate($y);//just act on the file to rename duplicate content; only useful for automatic review	

Keep in mind that this class is just a helper.

Note also that  good restrictions from start while using the project info collector via the exclude and include parameters	
can help significantly avoid the duplicate content.				
  Files folder image Files  
File Role Description
Accessible without login Plain text file Autoloader_pjc_1517055626.php Aux. autoloader script
Plain text file Classes_grabber.php Class Classes grabber
Plain text file Constants_grabber.php Class Constants grabber
Plain text file DuplicateHelper.php Class Duplicate content Helper
Plain text file Functions_grabber.php Class Functions grabber
Accessible without login Plain text file install.php Conf. installation script
Accessible without login Plain text file license.txt Lic. license file
Plain text file ProjectInfoCollector.php Class Project Info Collector
Accessible without login Plain text file projectsClasses1517253095.pjc Data Code Gleaner's classes map
Accessible without login Plain text file projectsFunctions1517253095.pjc Data Code Gleaner's functions map
Accessible without login Plain text file readme.txt Doc. readme
Accessible without login Plain text file testAutoloader.php Example example script
Accessible without login Plain text file testGfunc.php Example example script
Plain text file Tokens_grabber.php Class tokenizer

 Version Control Reuses Unique User Downloads Download Rankings  
This week:0
All time:7,648
This week:192Up
For more information send a message to info at phpclasses dot org.