vendredi 4 octobre 2019

PHP - how to get the "use (...)" section using reflection

I have a Closure like this:

Closure($event, $payload)^ {#1433
  class: "Illuminate\Events\Dispatcher"
  this: App\Overrides\Events\Dispatcher {#28 …}
  use: {
    $listener: "App\SomeListener"
    $wildcard: false
  }
}

I'm trying to investigate it with $function = new ReflectionFunction($myClosure). I get something like this:

ReflectionFunction {#4537
  +name: "Illuminate\Events\{closure}"
  class: "Illuminate\Events\Dispatcher"
  this: App\Overrides\Events\Dispatcher {#28 …}
  parameters: {
    $event: ReflectionParameter {#4579
      +name: "event"
      position: 0
    }
    $payload: ReflectionParameter {#4571
      +name: "payload"
      position: 1
    }
  }
  use: {
    $listener: "App\SomeListener"
    $wildcard: false
  }
  extra: {
    file: "./vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php"
    line: "360 to 368"
    isUserDefined: true
  }
}

How do I extract the value of $listener (App\SomeListener) out of it? There doesn't seem to be a method on ReflectionFunction that would return it.





Aucun commentaire:

Enregistrer un commentaire