PHP code example of liquidrazor / class-locator

1. Go to this page and download the library: Download liquidrazor/class-locator 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/ */

    

liquidrazor / class-locator example snippets


$fileLocator = new FileLocator(...);

$classLocator = new ClassLocator($fileLocator, Mode::STRICT);

$result = $classLocator->locate();

new ClassLocator(FileLocator $fileLocator, Mode $mode = Mode::ENFORCING)

LocateResult locate()

Mode::ENFORCING
Mode::STRICT
Mode::LENIENT

array getClasses()
array getViolations()
bool hasViolations()

SymbolKind::CLASS_
SymbolKind::INTERFACE
SymbolKind::TRAIT
SymbolKind::ENUM

string getFqcn()
string getPath()
?SymbolKind getSymbolKind()
array getImplementedInterfaces()
?string getParentClass()
?bool isAbstract()
?bool isFinal()
bool hasResolvedMetadata()

string getMessage()
string getPath()

$fileLocator = new FileLocator(...);
$classLocator = new ClassLocator($fileLocator, Mode::STRICT);

$result = $classLocator->locate();

foreach ($result->getClasses() as $classInfo) {
    if (!$classInfo->hasResolvedMetadata()) {
        continue;
    }

    if ($classInfo->getSymbolKind() !== SymbolKind::CLASS_) {
        continue;
    }

    if (in_array('App\\Contract\\EventSubscriber', $classInfo->getImplementedInterfaces(), true)) {
        // Downstream code can classify this symbol without re-parsing the file.
    }
}