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

Console Bundle Laravel Package

ashtein/console-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require coresphere/console-bundle
    

    Ensure your composer.json does not override PHP version constraints (minimum PHP 7.1).

  2. Register Bundle: Add to AppKernel.php under dev/test environments:

    $bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
    
  3. Routing: Add to config/routing_dev.yml:

    coresphere_console:
        resource: .
        type: extra
    
  4. Assets:

    php bin/console assets:install web
    
  5. Access: Visit /console in your browser (dev environment only).

First Use Case

Run a simple command (e.g., cache:clear) directly in the browser UI. The bundle provides:

  • Colored output (like CLI).
  • Autocomplete for command names (e.g., type cache: → suggestions appear).
  • Local command history (persisted via localStorage).

Implementation Patterns

Workflows

  1. Development Workflow:

    • Use /console for one-off commands (e.g., doctrine:schema:update, cache:warmup).
    • Avoid CLI for debugging: Test commands interactively in the browser.
  2. Integration with Symfony Commands:

    • Extend existing commands (e.g., php bin/console my:custom-command) and test them via the web UI.
    • Example: Debug a custom command by running it in the browser and inspecting output/errors.
  3. Environment-Specific Usage:

    • Dev/Test: Enable the bundle (as shown above).
    • Prod: Disable it (not needed; CLI is preferred for production).
  4. Asset Management:

    • Bundle includes JS/CSS for the console UI. No manual asset compilation required (Symfony’s assets:install handles it).

Advanced Patterns

  • Custom Command Testing: Use the bundle to test commands that rely on Symfony’s HttpKernel (e.g., commands using services like Router or Twig). Example:

    // src/Command/MyCommand.php
    namespace App\Command;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\HttpFoundation\Request;
    
    class MyCommand extends Command {
        protected function execute(InputInterface $input, OutputInterface $output) {
            $request = Request::createFromGlobals();
            $output->writeln($request->getClientIp());
        }
    }
    

    Test in browser: /console → type my:command.

  • Debugging Services: Use the bundle to inspect services dynamically. Example:

    # In browser console:
    debug:container
    

    Then explore services via the interactive output.

  • Autocomplete for Custom Commands: The bundle auto-detects commands. For custom namespaces (e.g., app:), ensure your commands follow Symfony’s naming conventions (e.g., AppCommandapp:command-name).


Gotchas and Tips

Pitfalls

  1. Environment Restrictions:

    • The bundle only works in dev/test environments. Forgetting to register it in AppKernel will break the /console route.
    • Fix: Double-check AppKernel.php and routing_dev.yml.
  2. Asset Installation:

    • If JS/CSS fails to load, run:
      php bin/console assets:install web --symlink
      
    • Debug: Clear cache (cache:clear) and check web/bundles/coresphereconsole/ for files.
  3. PHP Version Mismatch:

    • The bundle requires PHP 7.1+. If Composer installs an older version, update config.platform.php or run:
      composer why-not symfony/console
      
  4. Command Autocomplete:

    • Autocomplete may not work for commands in sub-namespaces (e.g., doctrine:fixtures:load).
    • Fix: Ensure your command class follows Symfony’s naming rules (e.g., DoctrineFixturesCommanddoctrine:fixtures:*).
  5. LocalStorage Quirks:

    • Command history is stored in localStorage. If the browser blocks it (e.g., HTTPS issues), history won’t persist.
    • Fix: Test in Chrome/Firefox (supported browsers per README).
  6. Symfony 5+ Compatibility:

    • The bundle is listed as compatible with Symfony 4.0, but may need tweaks for Symfony 5+ (e.g., AppKernelKernel).
    • Workaround: Check the source for updates or fork it.

Debugging Tips

  1. Check Routes: Run php bin/console debug:router | grep console to verify the /console route exists.

  2. Enable Debug Mode: Ensure APP_DEBUG=true in .env (required for the bundle to function).

  3. Clear Cache: If the console UI is broken, clear all caches:

    php bin/console cache:clear
    
  4. Browser Console: Use your browser’s dev tools (F12) to debug JS errors (e.g., missing jQuery or Twig).

Extension Points

  1. Customize UI: Override the Twig template (CoreSphereConsoleBundle:Console:index.html.twig) by copying it to templates/bundles/coresphereconsole/Console/index.html.twig.

  2. Add Custom Commands: The bundle auto-discovers commands. For custom logic, extend the base command class or use Symfony’s event system (e.g., ConsoleEvents::COMMAND).

  3. Integrate with Other Bundles: Example: Use the bundle to trigger commands from a webhook or cron job by calling /console via curl:

    curl -X POST http://localhost/console -d "command=cache:clear"
    

    Note: This requires additional setup (e.g., a custom controller to parse the command parameter).

  4. Disable for Specific Users: Add a firewall rule in security.yaml to restrict access:

    access_control:
        - { path: ^/console, roles: ROLE_ADMIN }
    
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle