# Reflection Batch Operations

The Reflection Batch Operations provide methods for performing reflection operations on multiple classes or methods in batch, which can be more efficient than performing individual operations.

## Basic Usage

```php
use App\Framework\Reflection\BatchOperations\ReflectionBatchProcessor;
use App\Framework\Reflection\CachedReflectionProvider;

// Create a batch processor
$provider = new CachedReflectionProvider();
$batchProcessor = new ReflectionBatchProcessor($provider);

// Get attributes for multiple classes
$attributes = $batchProcessor->getAttributesForClasses([
    MyClass1::class,
    MyClass2::class,
    MyClass3::class
], RouteAttribute::class);

// Get methods with a specific attribute
$methods = $batchProcessor->getMethodsWithAttribute([
    Controller1::class,
    Controller2::class,
    Controller3::class
], RouteAttribute::class);

// Check instantiability of multiple classes
$instantiable = $batchProcessor->checkInstantiability([
    Service1::class,
    Service2::class,
    AbstractService::class
]);

// Check interface implementation
$implementsInterface = $batchProcessor->checkInterfaceImplementation([
    Repository1::class,
    Repository2::class,
    Repository3::class
], RepositoryInterface::class);
```

## Advanced Usage

### Working with Properties and Methods

```php
// Get properties for multiple classes
$properties = $batchProcessor->getPropertiesForClasses([
    Entity1::class,
    Entity2::class
]);

// Get methods for multiple classes (with optional filter)
$publicMethods = $batchProcessor->getMethodsForClasses([
    Service1::class,
    Service2::class
], \ReflectionMethod::IS_PUBLIC);

// Get parameters for multiple methods
$parameters = $batchProcessor->getMethodParametersForMethods([
    Controller1::class => ['index', 'show', 'update'],
    Controller2::class => 'index', // Single method as string
    Controller3::class => ['store', 'destroy']
]);

// Get attributes for multiple methods
$methodAttributes = $batchProcessor->getMethodAttributesForMethods([
    Controller1::class => ['index', 'show'],
    Controller2::class => ['index', 'store']
], RouteAttribute::class);
```

### Creating Instances

```php
// Create instances of multiple classes
$instances = $batchProcessor->createInstances([
    Service1::class => [],  // No constructor arguments
    Service2::class => ['arg1', 'arg2'],  // With constructor arguments
    Service3::class => [new Dependency()]  // With object dependencies
]);

// Process the instances
foreach ($instances as $className => $instance) {
    if ($instance !== null) {
        // Use the instance
        $instance->doSomething();
    } else {
        // Handle instantiation failure
        echo "Failed to instantiate {$className}";
    }
}
```

### Filtering Classes

```php
// Filter classes by attribute
$controllersWithRoute = $batchProcessor->filterClassesByAttribute([
    Controller1::class,
    Controller2::class,
    Service1::class,
    Service2::class
], RouteAttribute::class);

// Filter classes by interface
$repositories = $batchProcessor->filterClassesByInterface([
    Repository1::class,
    Service1::class,
    Repository2::class
], RepositoryInterface::class);

// Filter classes that don't implement an interface
$nonRepositories = $batchProcessor->filterClassesByInterface([
    Repository1::class,
    Service1::class,
    Repository2::class
], RepositoryInterface::class, false);
```

### Working with Enums (PHP 8.1+)

```php
// Get enum cases for multiple enum classes
$enumCases = $batchProcessor->getEnumCasesForClasses([
    StatusEnum::class,
    ColorEnum::class,
    NonEnumClass::class  // Will be skipped
]);

// Filter enum classes
$enums = $batchProcessor->filterEnumClasses([
    StatusEnum::class,
    Service1::class,
    ColorEnum::class
]);

// Filter non-enum classes
$nonEnums = $batchProcessor->filterEnumClasses([
    StatusEnum::class,
    Service1::class,
    ColorEnum::class
], false);
```

## Benefits

- **Performance**: Batch operations can be more efficient than performing individual operations, especially when working with many classes or methods.
- **Convenience**: The batch processor provides a simple API for common batch operations.
- **Flexibility**: Methods accept various input formats and handle edge cases gracefully.
- **PHP 8.x Support**: Full support for PHP 8.0 attributes and PHP 8.1 enums.

## Implementation Details

The batch processor delegates to the underlying `ReflectionProvider` for the actual reflection operations, but it handles the iteration and result collection for you. This makes it easier to work with collections of classes or methods.

Most methods return associative arrays where the keys are class names or method names, making it easy to access the results for specific classes or methods.
