PHP code example of hackpack / hack-class-scanner
1. Go to this page and download the library: Download hackpack/hack-class-scanner library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hackpack / hack-class-scanner example snippets
use HackPack\Scanner\ClassScanner;
use HackPack\Scanner\NameType;
$scanner = new ClassScanner(
Set{‘directory/to/scan’, ‘other/directory’, ‘file/to/scan.txt’},
Set{‘other/directory/to/ignore’, ‘other/directory/file_to_ignore.txt’}
);
$classes = $scanner->getNameToFileMap(NameType::className);
$interfaces = $scanner->getNameToFileMap(NameType::interfaceName);
$traits = $scanner->getNameToFileMap(NameType::traitName);
$enums = $scanner->getNameToFileMap(NameType::enumName);
$types = $scanner->getNameToFileMap(NameType::typeName);
$newtypes = $scanner->getNameToFileMap(NameType::newtypeName);
$functions = $scanner->getNameToFileMap(NameType::functionName);
$constants = $scanner->getNameToFileMap(NameType::constantName);
use HackPack\Scanner\ClassScanner;
use HackPack\Scanner\NameType;
$des);
// Define the filter callbacks
$classFilter = $className ==> preg_match(‘/pattern/’, $className);
$fileFilter = $fileName ==> preg_match(‘/pattern/’, $fileName);
// Attach the filters
$scanner->addDefinitionNameFilter(NameType::className, $classFilter);
$scanner->addFileNameFilter($fileFilter);
// Retreive the class definitions
$classMap = $scanner->mapDefinitionToFile(NameType::className);
use HackPack\Scanner\ClassScanner;
use HackPack\Scanner\NameType;
$des);
// Define the filters
$classFilter = $className ==> substr($className, 0, 4) === 'xhp_';
$fileFilter = $fileName ==> substr($fileName, -4) === '.xhp';
// Attach the filters
$scanner->addNameFilter(NameType::className, $classFilter);
$scanner->addFileNameFilter($fileFilter);
// Retreive the class definitions
$xhpClasses = $scanner->mapClassToFile();