PHP code example of danog / class-finder

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

    

danog / class-finder example snippets




ll default to ClassFinder::ALLOW_CLASSES
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo');
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::ALLOW_CLASSES);
$interfaces = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::ALLOW_INTERFACES);
$traits = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::ALLOW_TRAITS);
$funcs = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::ALLOW_FUNCTIONS);

// You can combine any of the flags
$interfacesTraits = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::ALLOW_TRAITS | ClassFinder::ALLOW_INTERFACES);

/**
 * array(
 *   'TestApp1\Foo\Bar',
 *   'TestApp1\Foo\Baz',
 *   'TestApp1\Foo\Foo'
 * )
 */
var_dump($classes);
/**
 * array(
 *   'TestApp1\Foo\BarInterface',
 *   'TestApp1\Foo\FooInterface'
 * )
 */
var_dump($interfaces);
/**
 * array(
 *   'TestApp1\Foo\BazTrait',
 * )
 */
var_dump($traits);
/**
 * array(
 *   'TestApp1\Foo\myFunc',
 * )
 */
var_dump($funcs);
/**
 * array(
 *   'TestApp1\Foo\BarInterface',
 *   'TestApp1\Foo\FooInterface',
 *   'TestApp1\Foo\BazTrait',
 * )
 */
var_dump($interfacesTraits);



 before, will default to ClassFinder::ALLOW_CLASSES
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE);
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_CLASSES);
$interfaces = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_INTERFACES);
$traits = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_TRAITS);
$funcs = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_FUNCTIONS);


// You can combine any of the flags
$classesTraits = ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_CLASSS | ClassFinder::ALLOW_TRAITS);

/**
 * array(
 *   'TestApp1\Foo\Bar',
 *   'TestApp1\Foo\Baz',
 *   'TestApp1\Foo\Foo',
 *   'TestApp1\Foo\Box\Bar',
 *   'TestApp1\Foo\Box\Baz',
 *   'TestApp1\Foo\Box\Foo',
 *   'TestApp1\Foo\Box\Lon\Bar',
 *   'TestApp1\Foo\Box\Lon\Baz',
 *   'TestApp1\Foo\Box\Lon\Foo',
 * )
 */
var_dump($classes);

// You get the idea :)
var_dump($interfaces);
var_dump($traits);
var_dump($funcs);
var_dump($classesTraits);