PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   PHP Code Gleaner and Analyzer Tool   readme.txt   Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: readme
Class: PHP Code Gleaner and Analyzer Tool
Scan PHP scripts to extract data about the code
Author: By
Last change: correct some typos
Date: 6 years ago
Size: 9,482 bytes
 

Contents

Class file image Download
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 contents. 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 leizmo@gmail.com. ------------------------------------------------------------------------------------------ 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'); by require_once(./grabber/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 //or $d->justKeepOne($y);//just act on the file and remove duplicate content; only useful for automatic review //or $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.