Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Process Bundle Laravel Package

cleverage/process-bundle

View on GitHub
Deep Wiki
Context7
## Getting Started
Install via Composer:
```bash
composer require package-name

For PHP 8.5+ projects, ensure your composer.json requires ^5.0 and PHP 8.5. The package now drops PHP 8.1/Symfony 7.3 support, so verify your environment matches:

"require": {
    "php": "^8.5",
    "symfony/*": "^8.0"
}

Start with the documentation for core transformers like array_map_transformer or multi_replace_transformer. Example first use case:

use PackageName\Transformers\ArrayMapTransformer;

$transformer = new ArrayMapTransformer(fn($item) => strtoupper($item));
$result = $transformer->transform(['foo', 'bar']); // ['FOO', 'BAR']

Implementation Patterns

Core Workflows

  1. Data Sanitization/Transformation: Use multi_replace_transformer for bulk string replacements:

    $replacer = new MultiReplaceTransformer(['old' => 'new']);
    $cleaned = $replacer->transform($dirtyData);
    
  2. Collection Processing: Chain transformers with Laravel Collections:

    $collection->map(fn($item) => (new SlugifyTransformer())->transform($item));
    
  3. Dynamic Transformations: Leverage sprintf_transformer for template-based formatting:

    $formatter = new SprintfTransformer('User %d: %s');
    $formatted = $formatter->transform([1, 'John']); // "User 1: John"
    

Integration Tips

  • Service Providers: Register transformers as singletons for reuse:
    $this->app->singleton(SlugifyTransformer::class, fn() => new SlugifyTransformer());
    
  • Form Requests: Use implode_transformer to flatten arrays:
    $request->merge(['tags' => (new ImplodeTransformer(', '))->transform($request->tags)]);
    
  • API Responses: Apply transformers in AppServiceProvider@boot for global responses:
    Response::macro('transform', fn($response, $transformer) =>
        $response->setContent($transformer->transform($response->content()))
    );
    

Gotchas and Tips

Breaking Changes (v5.0)

  • PHP/Symfony Version Drop: Ensure your composer.json and server meet the new minimum (^8.5/^8.0). Test thoroughly if using legacy Symfony components.
  • Deprecated Features: Remove any direct usage of Symfony 7.3-specific features (e.g., Symfony\Component\HttpFoundation\File\UploadedFile v7 methods).

Pitfalls

  1. Transformer Order Matters: Chaining transformers may produce unexpected results if order isn’t considered. Example:

    // ❌ Fails: Slugify after truncate loses characters
    $data->map(fn($s) => (new TruncateTransformer(10))->transform(
        (new SlugifyTransformer())->transform($s)
    ));
    

    Fix: Reverse the order or use a custom transformer.

  2. Performance with Large Data: array_map_transformer processes items sequentially. For huge arrays, consider batching:

    $batchSize = 1000;
    array_map([$transformer, 'transform'], array_chunk($data, $batchSize));
    
  3. SlugifyTransformer Quirks:

    • Preserves original string if slug is empty after transformation (e.g., --- becomes ---).
    • Use ->slugify($string, ['separator' => '-']) for custom separators.

Debugging Tips

  • Transformer Validation: Add a validate() method to your custom transformers:
    public function validate($data) {
        if (!is_array($data)) throw new \InvalidArgumentException('Expected array');
    }
    
  • Logging: Wrap transformers in a decorator for debugging:
    class LoggingTransformer implements TransformerInterface {
        public function transform($data) {
            \Log::debug('Transformer input', ['data' => $data]);
            return $this->transformer->transform($data);
        }
    }
    
  • Symfony Dependency Injection: If using Symfony DI, tag transformers for autowiring:
    # config/services.yaml
    services:
        App\Transformers\CustomTransformer:
            tags: ['package_name.transformer']
    

Extension Points

  1. Custom Transformers: Extend BaseTransformer for reusable logic:
    class TitleCaseTransformer extends BaseTransformer {
        public function transform($string) {
            return ucwords(strtolower($string));
        }
    }
    
  2. Pipeline Support: Integrate with Laravel Pipelines for complex workflows:
    $result = app(\Illuminate\Pipeline\Pipeline::class)
        ->send($data)
        ->through([
            new SlugifyTransformer(),
            new TruncateTransformer(50),
        ])
        ->thenReturn();
    
  3. Event-Based Transformations: Listen for package_name.transforming events to intercept/modify data:
    event(new Transforming($data, $transformer));
    

NO_UPDATE_NEEDED would **not** apply here due to the breaking changes and new features.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware