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

Utils Bundle Laravel Package

dontdrinkandroot/utils-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dontdrinkandroot/utils-bundle
    

    Add to config/bundles.php (Symfony) or config/app.php (Laravel via Symfony bridge):

    DontDrinkAndRoot\UtilsBundle\DontDrinkAndRootUtilsBundle::class => ['all' => true],
    
  2. First Use Case: Check the Utils service for quick utilities like:

    $this->get('utils')->slugify('Hello World'); // Returns 'hello-world'
    

    Verify via TWIG (if enabled):

    {{ app('utils').slugify('Test String') }}
    
  3. Key Classes:

    • Utils (core utilities)
    • ArrayUtils (array manipulations)
    • StringUtils (string helpers)

Implementation Patterns

Common Workflows

  1. String Manipulation:

    // Slugify, truncate, or format strings
    $slug = $this->get('utils')->slugify($title);
    $shortText = $this->get('utils')->truncate($longText, 50);
    
  2. Array Operations:

    // Merge, diff, or flatten arrays
    $merged = $this->get('array_utils')->mergeRecursive($array1, $array2);
    $diff = $this->get('array_utils')->arrayDiffAssoc($array1, $array2);
    
  3. Dependency Injection:

    // Inject services in controllers/services
    public function __construct(Utils $utils) {
        $this->utils = $utils;
    }
    
  4. Twig Integration:

    {# Filter strings in templates #}
    {{ 'Hello World'|slugify }}
    

Integration Tips

  • Laravel-Specific: Use app('utils') or bind the service in AppServiceProvider:
    public function register() {
        $this->app->bind('utils', function() {
            return new \DontDrinkAndRoot\UtilsBundle\Utils();
        });
    }
    
  • Validation: Extend Laravel’s FormRequest with custom rules:
    use DontDrinkAndRoot\UtilsBundle\Utils;
    
    public function rules() {
        return [
            'title' => ['required', function($attribute, $value, $fail) {
                if (strlen($this->utils->slugify($value)) > 50) {
                    $fail('Slug too long.');
                }
            }]
        ];
    }
    

Gotchas and Tips

Pitfalls

  1. Outdated Codebase:

    • Last release in 2016; test thoroughly for edge cases (e.g., Unicode slugs).
    • Example: slugify() may not handle non-ASCII characters well.
  2. No Laravel Native Support:

    • Requires manual binding or Symfony bridge. Avoid assuming Laravel service container compatibility.
  3. Undocumented Methods:

    • Some methods (e.g., StringUtils::camelCase()) lack examples. Check source for usage:
      $this->get('string_utils')->camelCase('hello_world'); // 'helloWorld'
      

Debugging

  • Service Not Found: Ensure the bundle is registered in config/bundles.php and dependencies are loaded.

    php bin/console debug:container utils
    
  • Performance: Avoid heavy operations (e.g., recursive array merges) in loops. Cache results if needed:

    $cachedSlug = Cache::remember("slug_{$title}", 3600, function() use ($title) {
        return $this->utils->slugify($title);
    });
    

Extension Points

  1. Custom Utilities: Extend the Utils class or create a decorator:

    class CustomUtils extends \DontDrinkAndRoot\UtilsBundle\Utils {
        public function customMethod($input) { ... }
    }
    

    Register the new service in services.yaml (Symfony) or AppServiceProvider.

  2. Override Defaults: Replace the bundle’s services in config/services.yaml:

    services:
        utils: '@app.custom_utils_service'
    
  3. Testing: Mock the Utils service in PHPUnit:

    $this->mock(Utils::class)->shouldReceive('slugify')->andReturn('test-slug');
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui