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

Silly Laravel Package

mnapoli/silly

Silly is a lightweight library for building CLI apps in PHP. It wraps Symfony Console with a simple, callback-based API, optional dependency injection support, and helpers for defining commands and arguments quickly—ideal for small tools and prototypes.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mnapoli/silly
    

    No additional configuration is needed—just require the Silly\Silly class.

  2. First Command: Create a basic command class in app/Console/Commands/Hello.php:

    <?php
    namespace App\Console\Commands;
    
    use Silly\Silly;
    
    class Hello extends Silly
    {
        public function handle()
        {
            $this->line('Hello, Silly!');
        }
    }
    
  3. Run It:

    php artisan silly:run App\Console\Commands\Hello
    

    (Note: If using Laravel, register the SillyServiceProvider in config/app.php.)

Where to Look First

  • Documentation: GitHub README (minimal but clear).
  • Core Class: Silly\Silly (extends Symfony\Component\Console\Command).
  • Built-in Helpers: $this->line(), $this->ask(), $this->choice(), etc.

Implementation Patterns

1. Command Structure

  • Basic Command:
    class MyCommand extends Silly
    {
        protected $name = 'app:my-command'; // Optional: auto-detected via class name.
    
        public function handle()
        {
            $this->line('Running...');
        }
    }
    
  • Arguments/Options:
    class Deploy extends Silly
    {
        protected $signature = 'deploy {--dry-run} {--env=production}';
        protected $description = 'Deploy the app';
    
        public function handle()
        {
            if ($this->option('dry-run')) {
                $this->line('Dry run mode');
            }
        }
    }
    

2. Integration with Laravel

  • Service Provider:
    // app/Providers/SillyServiceProvider.php
    namespace App\Providers;
    
    use Silly\Silly;
    use Illuminate\Support\ServiceProvider;
    
    class SillyServiceProvider extends ServiceProvider
    {
        public function register()
        {
            $this->app->singleton(Silly::class);
        }
    }
    
  • Artisan Command Registration:
    // app/Console/Kernel.php
    protected $commands = [
        \App\Console\Commands\Hello::class,
    ];
    

3. Reusable Components

  • Custom Helpers:
    trait LoggingTrait
    {
        protected function log($message)
        {
            $this->line('[LOG] ' . $message);
        }
    }
    
    class MyCommand extends Silly
    {
        use LoggingTrait;
    
        public function handle()
        {
            $this->log('Command started');
        }
    }
    

4. Workflow: CLI Task Automation

  • Example: Database backup with user confirmation.
    class Backup extends Silly
    {
        protected $signature = 'db:backup {--path=backups}';
    
        public function handle()
        {
            $path = $this->option('path');
            if (!$this->confirm("Backup to {$path}? [y/N]")) {
                return;
            }
            // Backup logic here...
            $this->success('Backup complete!');
        }
    }
    

Gotchas and Tips

Pitfalls

  1. No Built-in Artisan Integration:

    • Silly is a standalone CLI framework. For Laravel, manually register commands in app/Console/Kernel.php or use a service provider.
    • Fix: Use SillyServiceProvider to bind Silly commands to Laravel’s container.
  2. Signature Conflicts:

    • If two commands share the same name/signature, the last registered one wins.
    • Fix: Use unique names (e.g., app:deploy vs. deploy:app).
  3. Output Formatting:

    • Silly uses Symfony’s Output class. Overriding $output can break formatting.
    • Tip: Use $this->line() instead of echo for consistent styling.
  4. Dependency Injection:

    • Silly doesn’t natively support Laravel’s IoC container. Manually resolve dependencies:
      $this->line($this->app->make(MyService::class)->doSomething());
      

Debugging Tips

  • Enable Verbose Output:
    php artisan silly:run MyCommand --verbose
    
  • Check Symfony’s Console Events: Use Silly\Events\CommandEvent for pre/post hooks:
    Silly::listen(function ($event) {
        $event->getCommand()->line('Event triggered!');
    });
    

Extension Points

  1. Custom Commands Directory: Override the default command discovery:

    Silly::setCommandsDirectory(app_path('Console/ExtendedCommands'));
    
  2. Global Options: Add reusable options via a trait:

    trait GlobalOptionsTrait
    {
        protected function getGlobalOptions()
        {
            return ['--env' => Input::getOption('env')];
        }
    }
    
  3. Interactive Prompts: Chain methods for complex UX:

    $name = $this->ask('Your name');
    $age = $this->ask('Your age', 30);
    $this->choice('Select option', ['A', 'B', 'C'], 'A');
    

Config Quirks

  • No Default Config File: Silly is lightweight—configure via code (e.g., Silly::setColorized(true)).
  • Color Customization:
    Silly::setColorized(true);
    Silly::setColors(['error' => '<fg=red>']);
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport