eaglewu/swoole-ide-helper
Laravel IDE helper for Swoole-based apps: adds accurate code completion and type hints for Swoole/Coroutine features, facades and helpers, improving PhpStorm and other IDE autocompletion when using swoole/laravel-swoole integrations.
Installation Add the package via Composer:
composer require eaglewu/swoole-ide-helper --dev
Run the publish command to generate IDE helper files:
php artisan swoole-ide-helper:generate
This creates bootstrap/cache/swoole-ide-helper.php (or your configured cache path).
First Use Case
Swoole\Server, Swoole\Coroutine).Swoole\ and press Ctrl+Space (or your IDE's autocomplete shortcut).start(), on(), or coroutine() appear with proper signatures.Where to Look First
config/swoole-ide-helper.php for customization (e.g., cache path, excluded classes).bootstrap/cache/swoole-ide-helper.php to inspect generated stubs.Autocomplete in Swoole Projects
phpstorm.meta.php or phpDocumentor for hybrid IDE support.Swoole\Server->on('request', ...) with parameter hints for $request, $response.CI/CD Pipeline
php artisan swoole-ide-helper:generate --force
.gitignore).Custom Swoole Extensions
// config/swoole-ide-helper.php
'classes' => [
'App\\Swoole\\CustomServer' => [
'methods' => [
'customMethod' => ['return' => 'void', 'params' => []],
],
],
];
php artisan swoole-ide-helper:generate
Laravel-Swoole Integration
beberlei/assert or spatie/laravel-swoole for type safety in async routes:
// Route with Swoole coroutine
Swoole\Coroutine::create(function () {
$user = User::find(1); // IDE hints for DB methods
});
Cache Invalidation
--force to regenerate:
php artisan swoole-ide-helper:generate --force
composer.json:
"scripts": {
"post-update-cmd": "php artisan swoole-ide-helper:generate --force"
}
IDE-Specific Quirks
Swoole\* classes in Settings > Languages & Frameworks > PHP > Include.bootstrap/cache/.Missing Methods
config/swoole-ide-helper.php or use PHPDoc comments:
/**
* @method static void customMethod(string $param)
*/
class_alias('Swoole\\Server', 'Swoole\\ServerWithCustomMethods');
Performance
'exclude' => [
'Swoole\\Process\\Pool',
'Swoole\\Http\\Server',
],
Verify Generation Check the generated file for errors:
grep -E "parse error|syntax error" bootstrap/cache/swoole-ide-helper.php
Log Missing Classes Enable debug mode in config:
'debug' => true,
Check logs for unresolved classes during generation.
Fallback to PHPDoc For unsupported methods, use inline PHPDoc:
/** @var \Swoole\Server $server */
$server->on('request', function ($request, $response) {
/** @var \Swoole\Http\Request $request */
$request->get['id']; // IDE hints work here
});
Custom Class Mappings Override default Swoole classes in config:
'classes' => [
'Swoole\\Server' => [
'file' => 'custom/Swoole/Server.php', // Path to your stub file
],
],
Dynamic Method Generation Use a service provider to inject runtime stubs:
// app/Providers/SwooleIdeHelperServiceProvider.php
public function boot()
{
$helper = new \Eaglewu\SwooleIdeHelper\Generator();
$helper->addClass('App\\Swoole\\Custom', [
'methods' => ['dynamicMethod' => ['return' => 'mixed']],
]);
$helper->generate();
}
Integration with Laravel Mix
Auto-generate helpers on npm run dev:
// webpack.mix.js
mix.scripts(['resources/js/app.js'], 'public/js')
.exec('php artisan swoole-ide-helper:generate');
How can I help you explore Laravel packages today?