PHP code example of uzbek / classtools

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

    

uzbek / classtools example snippets


$finder = new Symfony\Component\Finder\Finder;
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));

// Print the file names of classes, interfaces and traits in 'src'
foreach ($iter->getClassMap() as $classname => $splFileInfo) {
    echo $classname.': '.$splFileInfo->getRealPath();
}

$finder = new Symfony\Component\Finder\Finder;
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));

print_r($iter->getErrors());

$finder = new Symfony\Component\Finder\Finder();
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));

// Enable reflection by autoloading found classes
$iter->enableAutoloading();

// Print all classes, interfaces and traits in 'src'
foreach ($iter as $class) {
    echo $class->getName();
}

$finder = new Symfony\Component\Finder\Finder();
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));
$iter->enableAutoloading();

// Print all Filter types (including the interface itself)
foreach ($iter->type('uzbek\ClassTools\Iterator\Filter') as $class) {
    echo $class->getName();
}

// Print definitions in the Iterator namespace whose name contains 'Class'
foreach ($iter->inNamespace('uzbek\ClassTools\Iterator\Filter')->name('/type/i') as $class) {
    echo $class->getName();
}

// Print implementations of the Filter interface
foreach ($iter->type('uzbek\ClassTools\Iterator\Filter')->where('isInstantiable') as $class) {
    echo $class->getName();
}

$finder = new Symfony\Component\Finder\Finder();
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));
$iter->enableAutoloading();

// Print all classes, interfaces and traits NOT instantiable
foreach ($iter->not($iter->where('isInstantiable')) as $class) {
    echo $class->getName();
}

$finder = new Symfony\Component\Finder\Finder();
$iter = new Uzbek\ClassTools\Iterator\ClassIterator($finder->in('src'));
$iter->enableAutoloading();

// Print all found definitions in one snippet
echo $iter->minimize();

// The same can be done using
echo $iter->transform(new Uzbek\ClassTools\Transformer\MinimizingWriter);

$reader = new Reader(" class Bar {}");
$writer = new Writer;
$writer->apply(new Action\NamespaceWrapper('Foo'));

// Outputs class Bar wrapped in namespace Foo
echo $writer->write($reader->read('Bar'));