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

Cube Common Bundle Laravel Package

cubetools/cube-common-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run composer require cubetools/cube-common-bundle in your Laravel project (or Symfony if legacy AppKernel.php is used). For Laravel 8+, replace AppKernel.php registration with a config/bundles.php entry:

    return [
        // ...
        CubeTools\CubeCommonBundle\CubeToolsCubeCommonBundle::class => ['all' => true],
    ];
    
  2. Publish Assets (if needed) Check for publishable resources (e.g., configs, views) with:

    php artisan vendor:publish --provider="CubeTools\CubeCommonBundle\CubeToolsCubeCommonBundle"
    
  3. First Use Case: User Settings If using FOSUserBundle, the bundle auto-configures a user_settings service. Test it via Twig:

    {{ dump(app('cube_common.user_settings').getUserSettings()) }}
    

Implementation Patterns

Core Workflows

  1. Service Integration

    • Dependency Injection: Inject CubeCommonBundle's services (e.g., user_settings, logger) into controllers/services:
      public function __construct(
          private CubeTools\CubeCommonBundle\Services\UserSettings $userSettings
      ) {}
      
    • Configuration: Override default settings via config/packages/cube_common.yaml (publish config first).
  2. Routing

    • Extend routes by copying/modifying @CubeToolsCubeCommonBundle/Resources/config/routing/all.yml to your project’s config/routes/cube_common.yml.
  3. Event Listeners

    • Subscribe to bundle events (e.g., cube_common.user_updated) via Symfony’s event dispatcher:
      $dispatcher->addListener('cube_common.user_updated', function ($event) {
          // Handle user update logic
      });
      
  4. Twig Extensions

    • Use provided Twig functions/filters (e.g., cube_common_format_date) in Blade templates:
      @php echo cube_common_format_date($date, 'Y-m-d') @endphp
      

Laravel-Specific Adaptations

  • Service Providers: Register bundle services in AppServiceProvider:
    public function register()
    {
        $this->app->bind(
            'cube_common.user_settings',
            CubeTools\CubeCommonBundle\Services\UserSettings::class
        );
    }
    
  • Route Prefix: Prefix routes in routes/web.php:
    Route::prefix('cube')->group(function () {
        // Include cube_common routes here
    });
    

Gotchas and Tips

Pitfalls

  1. Kernel Compatibility

    • Laravel 8+: The bundle assumes Symfony’s Kernel class. Use a bridge like symfony/bridge or wrap services in Laravel’s container.
    • Error: Class 'Kernel' not found → Add to composer.json:
      "require": {
          "symfony/http-kernel": "^5.4"
      }
      
  2. FOSUserBundle Dependency

    • Issue: Bundle expects FOSUserBundle for user management. If not used, mock the User class or disable related services via config:
      cube_common:
          user_class: App\Models\User  # Must implement required interfaces
          fos_user_enabled: false
      
  3. Route Conflicts

    • Problem: Overlapping routes with Laravel’s default routes. Use Route::namespace() or middleware to isolate:
      Route::middleware(['web', 'cube'])->group(function () {
          // Cube routes here
      });
      

Debugging

  • Service Not Found: Verify the service is registered in config/services.php (Laravel) or bundles.php (Symfony).
  • Twig Errors: Clear compiled views:
    php artisan view:clear
    
  • Event Dispatcher: Check if the event listener is bound to the correct dispatcher instance (Laravel’s vs. Symfony’s).

Extension Points

  1. Custom User Settings Extend the UserSettings class:

    namespace App\Services;
    use CubeTools\CubeCommonBundle\Services\UserSettings as BaseUserSettings;
    
    class UserSettings extends BaseUserSettings
    {
        public function getCustomSetting()
        {
            return $this->getUser()->customAttribute;
        }
    }
    

    Bind it in AppServiceProvider.

  2. Logger Integration Override the logger service to use Laravel’s Log facade:

    # config/packages/cube_common.yaml
    cube_common:
        logger: monolog.logger.app  # Laravel's default logger
    
  3. Database Migrations If the bundle includes migrations (e.g., user_settings table), publish and adapt them:

    php artisan vendor:publish --tag=cube-common-migrations
    
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