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

Sonata Composer Laravel Package

sonata-project/sonata-composer

Utilities to help manage Composer dependencies in Sonata projects, providing tooling and helpers around Composer configuration and package integration for the Sonata ecosystem. Suitable for automating dependency handling and simplifying setup across Sonata bundles.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Check Deprecation Notice Since this package is archived and deprecated, verify if it’s still needed in your project. If alternatives like composer-plugin-api or modern Composer scripts (post-install-cmd, scripts) suffice, skip installation.

  2. Legacy Project Compatibility If your project explicitly depends on sonata-project/sonata-composer (e.g., for SonataAdmin’s legacy Composer hooks), install via:

    composer require sonata-project/sonata-composer --dev
    

    Note: This may conflict with newer Composer versions (>2.x).

  3. First Use Case

    • SonataAdmin Bundle: If using SonataAdmin’s SonataAdminBundle, this package historically handled:
      • Post-install/update Composer scripts (e.g., asset compilation, DB migrations).
      • Dynamic autoload-dev for debug tools.
    • Workaround: Replace with composer.json scripts:
      "scripts": {
        "post-install-cmd": [
          "php artisan sonata:install --no-interaction"
        ],
        "post-update-cmd": [
          "php artisan sonata:install --no-interaction"
        ]
      }
      

Implementation Patterns

Workflows

  1. Legacy SonataAdmin Integration

    • Pre-Composer 2.x: The package hooked into post-install-cmd to run Sonata’s CLI commands (e.g., sonata:install).
    • Modern Alternative: Use Composer scripts (as above) or Laravel’s post-install hooks in composer.json.
  2. Dynamic Autoloading

    • Historically, the package added sonata/* to autoload-dev for debug classes.
    • Replacement: Manually add to composer.json:
      "autoload-dev": {
        "psr-4": {
          "Sonata\\": "vendor/sonata-project/*"
        }
      }
      
  3. Plugin-Based Extensions

    • The package allowed custom Composer plugins via Sonata’s SonataComposerPlugin.
    • Modern Approach: Use Composer plugins directly or Laravel’s ServiceProvider bootstrapping.

Integration Tips

  • For New Projects: Avoid this package entirely. Use:
    • Laravel’s bootstrap/app.php for service binding.
    • Composer scripts for one-off tasks.
  • For Legacy Projects:
    • Override sonata:install commands in config/packages/sonata_admin.yaml to use native Laravel commands.
    • Replace sonata/composer hooks with composer.json scripts.

Gotchas and Tips

Pitfalls

  1. Composer 2.x Incompatibility

    • The package may fail with errors like:
      Your Composer version (2.x) does not support SonataComposerPlugin.
      
    • Fix: Downgrade Composer to 1.x (not recommended) or migrate to native scripts.
  2. Deprecated Methods

    • Methods like SonataComposerPlugin::getInstaller() are obsolete.
    • Workaround: Use Laravel’s Artisan::call() in composer.json scripts.
  3. Circular Dependencies

    • If the package is pulled in transitively (e.g., via sonata-project/admin-bundle), it may cause conflicts.
    • Solution: Explicitly require the package in composer.json and use replace to avoid duplicates:
      "replace": {
        "sonata-project/sonata-composer": "*"
      }
      

Debugging

  • Script Failures: If Composer scripts fail silently, run them manually:
    php artisan sonata:install --no-interaction --verbose
    
  • Autoload Issues: Clear caches after changes:
    composer dump-autoload
    php artisan cache:clear
    

Extension Points

  • Custom Composer Plugins: If you need plugin-like behavior, create a custom Composer plugin or use Laravel’s Console/Kernel to hook into Composer events.
  • Post-Install Logic: Move logic from sonata/composer to:
    • Laravel’s registerCommands() in AppServiceProvider.
    • Composer scripts with php artisan calls.

Config Quirks

  • SonataAdmin Config: Ensure sonata_admin is properly configured in config/packages/sonata_admin.yaml to avoid missing command errors.
  • Environment Checks: The package may assume a specific Laravel/Symfony version. Validate compatibility in composer.json:
    "conflict": {
      "composer/composer": "2.0.0"
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky