PHP code example of yj-php-utils / class-finder

1. Go to this page and download the library: Download yj-php-utils/class-finder 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/ */

    

yj-php-utils / class-finder example snippets


// Your basePath project. 
$basePath = defined('BASE_PATH') ? BASEPATH : '/var/www/html/your_project_base_path';

// List all classes in App\Http\Controllers namespace
$classes = \ClassFinder\Finder::findClassesInNamespace($basePath, 'App\Http\Controllers')->get();

// List all classes in '.' directory
$classes = \ClassFinder\Finder::findClassesInPath($basePath, __DIR__)->get();

// With filters
$classes = 
    \ClassFinder\Finder::findClassesInNamespace($basePath, 'App\Http\Controllers')
    ->extends('\App\Http\Controllers\Controller')
    ->implements('\App\Http\Controllers\ApiInterface')
    ->where(function(string $namespace){ // get all classes that has index() method
        return method_exists($namespace, 'index');
    })
    ->get();