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

Ide Helper Laravel Package

openswoole/ide-helper

Generates IDE helper stubs for OpenSwoole, improving autocompletion, type hints, and static analysis in PhpStorm and other editors. Useful for Swoole-style async/server apps to navigate APIs faster and reduce guesswork.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require openswoole/ide-helper
    

    Run the helper to generate stubs:

    vendor/bin/ide-helper generate
    
  2. IDE Configuration

    • For VSCode, ensure PHP Intelephense or PHP IntelliSense is installed.
    • Add this to your settings.json:
      "intelephense.environment.phpVersion": "8.1.0", // Match your PHP version
      "intelephense.environment.swoole": true
      
    • Restart VSCode and open a Laravel project using Swoole.
  3. First Use Case Test autocompletion in a Swoole-based Laravel controller:

    use Swoole\Http\Request;
    use Swoole\Http\Response;
    
    class SwooleController extends Controller
    {
        public function handle(Request $request, Response $response)
        {
            // Autocomplete should now work for $request and $response
            $response->end('Hello, Swoole!');
        }
    }
    

Implementation Patterns

Workflow Integration

  1. Swoole Server Initialization Use the helper to autocomplete Swoole server methods in bootstrap/app.php or a custom Swoole server file:

    $server = new Swoole\Http\Server('127.0.0.1', 9501);
    $server->on('request', function (Request $request, Response $response) {
        // Autocomplete works here
    });
    
  2. Middleware and Coroutines Leverage stubs for Swoole-specific middleware or coroutine functions:

    use Swoole\Coroutine;
    
    class SwooleMiddleware
    {
        public function handle(Request $request, Response $response, callable $next)
        {
            go(function () use ($request) {
                // Autocomplete for Coroutine functions
                $data = yield Coroutine\System::exec('ls -la');
            });
            $next($request, $response);
        }
    }
    
  3. Event-Driven Autocompletion Use stubs for Swoole events (e.g., onWorkerStart, onTask):

    $server->on('workerStart', function (Swoole\Server $server, int $workerId) {
        // Autocomplete for $server and $workerId
    });
    
  4. Laravel-Swoole Hybrid Combine Laravel’s dependency injection with Swoole’s server:

    $server = resolve(Swoole\Server::class);
    $server->on('request', function (Request $request, Response $response) {
        $user = auth()->user(); // Laravel autocompletion works too
    });
    

Gotchas and Tips

Pitfalls

  1. Stub Generation Overwrite

    • Running ide-helper generate overwrites existing stubs. Backup or use --force cautiously.
    • Fix: Use --force only when necessary or commit stubs to version control.
  2. IDE-Specific Quirks

    • VSCode: Ensure intelephense.environment.swoole is set to true; otherwise, Swoole classes won’t autocomplete.
    • PHPStorm: Enable "Store PHP language level" in project settings and set it to your PHP version.
  3. Namespace Conflicts

    • Swoole’s Request/Response may conflict with Laravel’s HTTP classes.
    • Fix: Use fully qualified namespaces (e.g., \Swoole\Http\Request) in ambiguous contexts.
  4. Dynamic Properties

    • Swoole’s dynamic properties (e.g., $server->stats) won’t autocomplete.
    • Workaround: Use @property annotations in custom stubs or rely on PHPDoc comments.

Debugging

  1. Stub Path Issues

    • If autocompletion fails, verify stubs are generated in vendor/openswoole/ide-helper/stubs.
    • Debug: Run vendor/bin/ide-helper generate --debug to check for errors.
  2. IDE Cache

    • Clear your IDE’s cache (e.g., VSCode: Ctrl+Shift+P > "PHP Intelephense: Restart Server").
  3. PHP Version Mismatch

    • Stubs are PHP version-specific. Ensure your ide-helper config matches your PHP version:
      # ide-helper.php
      return [
          'autoload' => [
              'namespaces' => [
                  'Swoole' => __DIR__ . '/vendor/openswoole/ide-helper/stubs',
              ],
          ],
          'swoole' => [
              'version' => '4.8.0', // Match your Swoole version
          ],
      ];
      

Extension Points

  1. Custom Stubs Extend stubs for unsupported Swoole classes or methods:

    // In a custom stub file (e.g., `stubs/Swoole/CustomClass.php`)
    <?php
    namespace Swoole;
    
    /**
     * @method static void customMethod()
     */
    class CustomClass {}
    
  2. Integration with Laravel Mix Automate stub generation in package.json:

    {
        "scripts": {
            "dev": "npm run development",
            "ide-helper": "php vendor/bin/ide-helper generate"
        }
    }
    

    Run with:

    npm run ide-helper
    
  3. CI/CD Pipeline Add stub generation to your CI pipeline (e.g., GitHub Actions):

    - name: Generate IDE Helpers
      run: vendor/bin/ide-helper generate
    
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