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 CLI micro-framework built on Symfony Console. Define commands with simple signatures and PHP callables, get options/arguments parsing, helpers, and DI integration (PHP-DI or Pimple) while staying compatible with Symfony Console apps.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require mnapoli/silly
    

    For PHP-DI integration (recommended for Laravel projects):

    composer require mnapoli/silly-php-di
    
  2. Basic CLI Setup: Create a console.php file in your project root:

    <?php
    require __DIR__.'/vendor/autoload.php';
    
    $app = new \Silly\Application();
    $app->command('greet [name]', function ($name = 'World') {
        echo "Hello, $name!\n";
    });
    $app->run();
    
  3. First Use Case: Run your command:

    php console.php greet Laravel
    

    Output: Hello, Laravel!

Where to Look First


Implementation Patterns

Core Workflows

1. Command Organization

Laravel-style Artisan-like structure:

// app/Console/Commands/GreetCommand.php
namespace App\Console\Commands;

use Silly\Application;

class GreetCommand
{
    public function __invoke($name = 'World')
    {
        echo "Hello, $name!\n";
    }
}

// Register in bootstrap
$app = new Application();
$app->command('greet [name]', [new GreetCommand(), '__invoke']);

2. Dependency Injection with Laravel Services

// Using PHP-DI bridge
$app = new \Silly\Application\PhpDiApplication();
$app->bind(\App\Services\UserService::class)
    ->to(\App\Services\LivewireUserService::class);

$app->command('user:list', function (UserService $userService) {
    $users = $userService->all();
    // ...
});

3. SymfonyStyle Integration

use Symfony\Component\Console\Style\SymfonyStyle;

$app->command('deploy', function (SymfonyStyle $io) {
    $io->title('Starting deployment');
    $io->section('Checking dependencies');
    // ...
});

4. Command Groups

$app->command('user:create', /* ... */);
$app->command('user:list', /* ... */);
$app->add(new \Silly\Command\CommandGroup('user', 'User management'));

Integration Tips

Laravel Artisan Compatibility

// In bootstrap file
$app = new Application();
$app->setName('Laravel');
$app->setVersion('10.x');

// Add Laravel's default commands
$app->add(new \Illuminate\Foundation\Console\ArtisanCommand());

Configuration Management

// config/console.php
return [
    'commands' => [
        'greet' => [
            'callback' => [new \App\Console\Commands\GreetCommand(), '__invoke'],
            'description' => 'Greet someone',
        ],
    ],
];

// In bootstrap
$config = require __DIR__.'/../config/console.php';
foreach ($config['commands'] as $name => $config) {
    $app->command($name, $config['callback'])
        ->description($config['description']);
}

Event Listeners

$app->on('command.test', function ($event) {
    // Pre-command logic
});

$app->on('command.test.complete', function ($event) {
    // Post-command logic
});

Gotchas and Tips

Common Pitfalls

  1. Parameter Order Sensitivity:

    // ❌ Will fail - order matters for named parameters
    $app->command('test [name] [--age=]', function ($age, $name) {
        // $age will be null, $name will be the age
    });
    
    // ✅ Correct
    $app->command('test [name] [--age=]', function ($name, $age = 30) {
        // Works with default value
    });
    
  2. Hyphen Handling:

    // ❌ Will throw error
    $app->command('test [--dry-run]', function ($dryRun) {
        // ...
    });
    
    // ✅ Correct (hyphens converted to camelCase)
    $app->command('test [--dry-run]', function ($dryRun) {
        // ...
    });
    
  3. Container Binding Conflicts:

    // ❌ Will cause "Cannot resolve service" if both exist
    $container->set('logger', $logger);
    $app->command('test', function (\Psr\Log\LoggerInterface $logger) {
        // ...
    });
    

Debugging Techniques

  1. Command Introspection:

    $app->get('help')->setFormatter(new \Symfony\Component\Console\Formatter\OutputFormatter());
    $app->run(new \Symfony\Component\Console\Input\ArrayInput(['help']));
    
  2. Parameter Dumping:

    $app->command('debug:params', function ($input, $output, $args, $options) {
        $output->writeln('Arguments: ' . print_r($args, true));
        $output->writeln('Options: ' . print_r($options, true));
    });
    
  3. Container Inspection:

    $app->command('debug:container', function () {
        $container = $app->getContainer();
        foreach ($container->find() as $id => $entry) {
            echo "$id: " . get_class($entry) . "\n";
        }
    });
    

Configuration Quirks

  1. Default Command Behavior:

    // ❌ Won't work as expected
    $app->setDefaultCommand('greet');
    $app->command('greet', /* ... */);
    
    // ✅ Correct
    $app->command('greet', /* ... */);
    $app->setDefaultCommand('greet');
    
  2. Option Shortcuts:

    // ❌ Will conflict
    $app->command('test [-y|--yell]', /* ... */);
    
    // ✅ Correct (use consistent format)
    $app->command('test [--yell|y]', /* ... */);
    

Extension Points

  1. Custom Command Helpers:

    // app/Console/SillyHelper.php
    class SillyHelper
    {
        public static function confirm($question, $default = true)
        {
            $helper = new \Symfony\Component\Console\Helper\QuestionHelper();
            return $helper->ask($question, $default);
        }
    }
    
    // Usage
    $app->command('migrate', function () {
        if (!SillyHelper::confirm('Proceed with migration?')) {
            exit(1);
        }
        // ...
    });
    
  2. Middleware Pattern:

    $app->on('command.test', function ($event) {
        $start = microtime(true);
        $event->getCommand()->setCode(function () use ($start) {
            $duration = microtime(true) - $start;
            echo "Command took $duration seconds\n";
        });
    });
    
  3. Custom Input/Output:

    $app->setInput(new \Symfony\Component\Console\Input\ArgvInput());
    $app->setOutput(new \Symfony\Component\Console\Output\BufferedOutput());
    
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope