-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support to parse for interface and trait definitions and partly enums (enum support is not finished) - Adapted code to never PHP version - Updated readme - Added some examples
- Loading branch information
Showing
20 changed files
with
1,239 additions
and
848 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
/vendor | ||
/composer.lock |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "purc/autoloader-class-map", | ||
"type": "library", | ||
"description": "Autoloader class map generator", | ||
"keywords": [ | ||
"php", | ||
"autoload", | ||
"autoloader", | ||
"classmap", | ||
"generator" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Murat Purç", | ||
"email": "[email protected]", | ||
"homepage": "https://www.purc.de" | ||
} | ||
], | ||
"license": ["GPL-2.0-or-later"], | ||
"autoload": { | ||
"psr-4": { | ||
"Purc\\AutoloaderClassMap\\": "src/" | ||
} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,81 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Example usage for autoloader class map file generator. | ||
* | ||
* Parses full PEAR directory and creates a class map file! | ||
* | ||
* Usage: | ||
* ------ | ||
* 1. Modifiy settings to youre requriements | ||
* 2. call this cript from command line as follows: | ||
* 1. Modify settings to your requirements | ||
* 2. Call this script from command line as follows: | ||
* $ php example.php | ||
* 3. Check created class map file | ||
* | ||
* @category Development | ||
* @package mpAutoloaderClassMap | ||
* @author Murat Purc <[email protected]> | ||
* @copyright Copyright (c) 2009-2011 Murat Purc (http://www.purc.de) | ||
* @license http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2 | ||
* @version $Id$ | ||
* @category Development | ||
* @package AutoloaderClassMap | ||
* @author Murat Purç <[email protected]> | ||
* @copyright Murat Purç (http://www.purc.de) | ||
* @license http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2 | ||
*/ | ||
|
||
|
||
################################################################################ | ||
##### Initialization/Settings | ||
|
||
// create a page context class, better than spamming global scope | ||
$context = new stdClass(); | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
$classMapPath = __DIR__ . '/classmap.configuration.php'; | ||
|
||
// current path | ||
$context->currentPath = str_replace('\\', '/', realpath(dirname(__FILE__) . '/')) . '/'; | ||
// Set the environment variable, PURC_AUTOLOADER_CLASS_MAP_FILE, you can set the global variable alternatively, e.g. | ||
// $GLOBALS['PURC_AUTOLOADER_CLASS_MAP_FILE'] = $classMapPath; | ||
putenv('PURC_AUTOLOADER_CLASS_MAP_FILE="' . $classMapPath . '"'); | ||
|
||
// the destination file where the class map configuration should be written in | ||
$context->destinationFile = $context->currentPath . '/classmap.configuration.php'; | ||
$destinationFile = $classMapPath; | ||
|
||
// list of paths from where all class/interface names should be found | ||
// NOTE: Path depends on used environment and should be adapted | ||
$context->pathsToParse = array( | ||
'/path/to/my/project' | ||
); | ||
$pathsToParse = [ | ||
__DIR__ .'/_data/class-map-generator-fixtures' | ||
]; | ||
|
||
// list to collect class maps | ||
$context->classMapList = array(); | ||
$classMapList = []; | ||
|
||
// class file finder options | ||
$context->options = array( | ||
$options = [ | ||
// exclude following folder names | ||
'excludeDirs' => array('temp', 'session', 'docs', 'tests'), | ||
'excludeDirs' => ['temp', 'session', 'docs', 'tests'], | ||
// no specific file exclusion | ||
'excludeFiles' => array(), | ||
'excludeFiles' => [], | ||
// parse all files with '.php' extension | ||
'extensionsToParse' => '.php', | ||
// disbale debugging | ||
'extensionsToParse' => ['.php'], | ||
// disable debugging | ||
'enableDebug' => false, | ||
); | ||
]; | ||
|
||
|
||
################################################################################ | ||
##### Process | ||
|
||
// include required classes | ||
include_once($context->currentPath . 'lib/mpClassTypeFinder.php'); | ||
include_once($context->currentPath . 'lib/mpClassMapFileCreator.php'); | ||
|
||
// collect all found class/interface names with their paths | ||
$context->classTypeFinder = new mpClassTypeFinder($context->options); | ||
foreach ($context->pathsToParse as $pos => $dir) { | ||
$classMap = $context->classTypeFinder->findInDir(new SplFileInfo($dir), true); | ||
// Collect all found class/interface names with their paths | ||
$classTypeFinder = new \Purc\AutoloaderClassMap\ClassTypeFinder($options); | ||
foreach ($pathsToParse as $pos => $dir) { | ||
$classMap = $classTypeFinder->findInDir(new SplFileInfo($dir), true); | ||
if ($classMap) { | ||
$context->classMapList = array_merge($context->classMapList, $classMap); | ||
$classMapList = array_merge($classMapList, $classMap); | ||
} | ||
} | ||
ksort($classMapList); | ||
|
||
// uncomment following line to get some debug messages | ||
#echo $context->classTypeFinder->getFormattedDebugMessages(); | ||
|
||
// Uncomment following line to get some debug messages | ||
#echo $classTypeFinder->getFormattedDebugMessages(); | ||
|
||
// write the class map configuration | ||
$context->classMapCreator = new mpClassMapFileCreator(); | ||
$context->classMapCreator->create($context->classMapList, $context->destinationFile); | ||
|
||
// Write the class map configuration | ||
$classMapCreator = new \Purc\AutoloaderClassMap\FileCreator(); | ||
$classMapCreator->create($classMapList, $destinationFile); | ||
|
||
// cleanup | ||
unset($context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Example usage for autoloader class map file generator. | ||
* | ||
* Parses defined directory/directories and creates a class map file! | ||
* | ||
* Usage: | ||
* ------ | ||
* 1. Modify settings to your requirements | ||
* 2. Call this script from command line as follows: | ||
* $ php class_map_generation.php | ||
* 3. Check created class map file | ||
* | ||
* @category Development | ||
* @package AutoloaderClassMap | ||
* @author Murat Purç <[email protected]> | ||
* @copyright Murat Purç (http://www.purc.de) | ||
* @license http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2 | ||
*/ | ||
|
||
|
||
// ##### Initialization/Settings | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// Path and name of class map file to store the class map definitions. | ||
// Note: PHP needs write-permissions for the folder! | ||
$classMapPath = __DIR__ . '/classmap.configuration.php'; | ||
|
||
// Set the environment variable, PURC_AUTOLOADER_CLASS_MAP_FILE, you can set the global variable alternatively, e.g. | ||
// $GLOBALS['PURC_AUTOLOADER_CLASS_MAP_FILE'] = $classMapPath; | ||
putenv('PURC_AUTOLOADER_CLASS_MAP_FILE="' . $classMapPath . '"'); | ||
|
||
// The destination file where the class map configuration should be written in | ||
$destinationFile = $classMapPath; | ||
|
||
// List of paths from where all class/interface names should be found | ||
// NOTE: Path depends on used environment and should be adapted | ||
$pathsToParse = [ | ||
__DIR__ . '/files' | ||
]; | ||
|
||
// List to collect class maps | ||
$classMapList = []; | ||
|
||
// Class file finder options | ||
$options = [ | ||
// exclude following folder names | ||
'excludeDirs' => ['temp', 'session', 'docs', 'tests'], | ||
// no specific file exclusion | ||
'excludeFiles' => [], | ||
// parse all files with '.php' extension | ||
'extensionsToParse' => ['.php'], | ||
// disable debugging | ||
'enableDebug' => false, | ||
]; | ||
|
||
|
||
// ##### Process | ||
|
||
// Collect all found class/interface names with their paths | ||
$classTypeFinder = new \Purc\AutoloaderClassMap\ClassTypeFinder($options); | ||
foreach ($pathsToParse as $pos => $dir) { | ||
$classMap = $classTypeFinder->findInDir(new SplFileInfo($dir)); | ||
if ($classMap) { | ||
$classMapList = array_merge($classMapList, $classMap); | ||
} | ||
} | ||
ksort($classMapList); | ||
|
||
// Uncomment following line to get some debug messages | ||
#echo $classTypeFinder->getFormattedDebugMessages(); | ||
|
||
// Write the class map configuration | ||
$classMapCreator = new \Purc\AutoloaderClassMap\FileCreator(); | ||
$classMapCreator->create($classMapList, $destinationFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Foo\Bar; | ||
|
||
use Exception; | ||
|
||
interface NsAndUseInterface | ||
{ | ||
} | ||
|
||
trait NsAndUseTrait | ||
{ | ||
} | ||
|
||
class NsAndUseClass | ||
{ | ||
public function __construct() | ||
{ | ||
throw new Exception('Instantiation not allowed!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace { | ||
|
||
interface RootNsInterface {} | ||
|
||
trait RootNsTrait {} | ||
|
||
class RootNsClass {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Foo \ Bar { | ||
|
||
interface WhitespaceNsInterface {} | ||
|
||
trait WhitespaceNsTrait {} | ||
|
||
class WhitespaceNsClass {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace | ||
/**/ | ||
Foo\Bar | ||
/**/ | ||
; | ||
|
||
interface NsInterface { | ||
} | ||
|
||
trait NsTrait { | ||
} | ||
|
||
class NsClass { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
interface NoNsInterface {} | ||
|
||
trait NoNsTrait {} | ||
|
||
class NoNsClass { | ||
|
||
public function getAnonInstance() | ||
{ | ||
return new class implements NoNsInterface { | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Example for finding tokens in a single file. | ||
* | ||
* Usage: | ||
* ------ | ||
* 1. Modify path to file (see `$file`) to your requirements | ||
* 2. Call this script from command line as follows: | ||
* $ php find_in_file.php | ||
* 3. See output | ||
* | ||
* @category Development | ||
* @package AutoloaderClassMap | ||
* @author Murat Purç <[email protected]> | ||
* @copyright Murat Purç (http://www.purc.de) | ||
* @license http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2 | ||
*/ | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$file = __DIR__ . '/files/namespace.php'; | ||
|
||
$classTypeFinder = new \Purc\AutoloaderClassMap\ClassTypeFinder(); | ||
$result = $classTypeFinder->findInFile( | ||
new SplFileInfo($file) | ||
); | ||
print_r($result); |
Oops, something went wrong.