2017 © Pedro Peláez
 

library class-finder

Class Finder by Darsyn for searching for end-user PHP classes.

image

darsyn/class-finder

Class Finder by Darsyn for searching for end-user PHP classes.

  • Friday, January 29, 2016
  • by zanderbaldwin
  • Repository
  • 2 Watchers
  • 3 Stars
  • 44 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Darsyn's Class Finder Build Status

A library for searching for classes in a specific root directory and namespace. Originally intended for searching for classes in all registered Symfony bundles (similar to finding bundle commands), it can find classes that stick to a standard without having to manually register each of those classes. Various filters can be specified, such as:, (*1)

  • In a sub-directory/namespace.
  • Have a specific file extension.
  • End with custom suffix.
  • Implement or extend a parent class or interface.

Usually an array containing fully-qualified class names (as strings) is returned, but passing true as the fourth parameter to the findClasses() method will return an array of ReflectionClass instances instead. Very useful in certain situations., (*2)

License

This project is licensed under MIT., (*3)

Dependencies

This project uses Symfony's Finder component to search for classes, and PHP's Reflection extension to process class definitions. It also assumes you are using Composer or a similar autoloader., (*4)

If you plan to use this library with the Symfony framework, it also utilises the HTTP Kernel component; this will already be a dependency of your project however., (*5)

Example

<?php

use Darsyn\ClassFinder\ClassFinder;

$finder = new ClassFinder;
$finder->setRootDirectory(__DIR__);

$subDir = 'Models';
$suffix = 'Entity';
$parent = 'Framework\\ActiveRecordEntity';

$classes = $finder->findClasses($subDir, $suffix, $parent);
foreach ($classes as $class) {
    echo $class . "\n";
}

/**
 * Example Output:
 *
 * Models\UserEntity
 * Models\GroupEntity
 * Models\CustomerEntity
 */

Symfony Integration

<?php

use Darsyn\ClassFinder\BundleClassFinder;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $kernel = $this->container->get('kernel');
        $finder = new BundleClassFinder($kernel);
        // Find all container-aware commands across all bundles:
        $containerAwareCommands = $finder->findClasses(
            'Command',
            'Command',
            'Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand'
        );
    }
}

You may also register this library as a service. To do so, add the following to app/config/services.yml (or in the bundle that uses this library in your preferred configuration format):, (*6)

services:

    darsyn.class_finder:
        class: Darsyn\ClassFinder\BundleClassFinder
        arguments: [ @kernel ]

Note: Remember that the kernel service is synthetic, and cannot be used until Symfony injects the correct kernel instance into the container., (*7)

Authors and Contributing

Current authors include:, (*8)

All contributions are welcome, don't forget to add your name here in the pull request!, (*9)

The Versions

29/01 2016

dev-develop

dev-develop

Class Finder by Darsyn for searching for end-user PHP classes.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/01 2016

dev-master

9999999-dev

Class Finder by Darsyn for searching for end-user PHP classes.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/01 2016

3.0.1

3.0.1.0

Class Finder by Darsyn for searching for end-user PHP classes.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/01 2016

3.0.0

3.0.0.0

Class Finder by Darsyn for searching for end-user PHP classes.

  Sources   Download

MIT

The Requires

 

The Development Requires