Task/Collect/ServicesCollector.php
protected function getServiceInterface($service_class) {
    $reflection = new \ReflectionClass($service_class);
    // This can get us more than one interface, if the declared interface has
    // parents. We only want one, so we need to go hacking in the code itself.
    $file = $reflection->getFileName();

    // If there's no file, as apparently some services have as their class
    // ArrayObject (WTF?!).
    if (empty($file)) {
      return '';
    }

    $start_line = $reflection->getStartLine();
    $spl = new \SplFileObject($file);
    $spl->seek($start_line - 1);
    $service_declaration_line = $spl->current();

    // Extract the interface from the declaration. We expect a service class
    // to only name one interface in its declaration!
    $matches = [];
    preg_match("@implements (\w+)@", $service_declaration_line, $matches);

    if (!isset($matches[1])) {
      return '';
    }

    $interface_short_name = $matches[1];

    // Find the fully-qualified interface name in the array of interfaces
    // obtained from the reflection.
    $interfaces = $reflection->getInterfaces();
    foreach (array_keys($interfaces) as $interface) {
      if (substr($interface, -(strlen($interface_short_name) + 1)) == '\\' . $interface_short_name) {
        // The reflection doesn't give the initial '\'.
        $full_interface_name = '\\' . $interface;

        return $full_interface_name;
      }
    }

    return '';
  }
protected function getServiceInterface($service_class) {
    $reflection = new \ReflectionClass($service_class);
    // This can get us more than one interface, if the declared interface has
    // parents. We only want one, so we need to go hacking in the code itself.
    $file = $reflection->getFileName();

    // If there's no file, as apparently some services have as their class
    // ArrayObject (WTF?!).
    if (empty($file)) {
      return '';
    }

    $start_line = $reflection->getStartLine();
    $spl = new \SplFileObject($file);
    $spl->seek($start_line - 1);
    $service_declaration_line = $spl->current();

    // Extract the interface from the declaration. We expect a service class
    // to only name one interface in its declaration!
    $matches = [];
    preg_match("@implements (\w+)@", $service_declaration_line, $matches);

    if (!isset($matches[1])) {
      return '';
    }

    $interface_short_name = $matches[1];

    // Find the fully-qualified interface name in the array of interfaces
    // obtained from the reflection.
    $interfaces = $reflection->getInterfaces();
    foreach (array_keys($interfaces) as $interface) {
      if (substr($interface, -(strlen($interface_short_name) + 1)) == '\\' . $interface_short_name) {
        // The reflection doesn't give the initial '\'.
        $full_interface_name = '\\' . $interface;

        return $full_interface_name;
      }
    }

    return '';
  }
protected function getServiceInterface ( $ service_class ) { $ reflection = new \ ReflectionClass ( $ service_class ) ; // This can get us more than one interface, if the declared interface has // parents. We only want one, so we need to go hacking in the code itself. $ file = $ reflection -> getFileName ( ) ; // If there's no file, as apparently some services have as their class // ArrayObject (WTF?!). if ( empty ( $ file ) ) { return '' ; } $ start_line = $ reflection -> getStartLine ( ) ; $ spl = new \ SplFileObject ( $ file ) ; $ spl -> seek ( $ start_line - 1 ) ; $ service_declaration_line = $ spl -> current ( ) ; // Extract the interface from the declaration. We expect a service class // to only name one interface in its declaration! $ matches = [ ] ; preg_match ( "@implements (\w+)@" , $ service_declaration_line , $ matches ) ; if ( ! isset ( $ matches [ 1 ] ) ) { return '' ; } $ interface_short_name = $ matches [ 1 ] ; // Find the fully-qualified interface name in the array of interfaces // obtained from the reflection. $ interfaces = $ reflection -> getInterfaces ( ) ; foreach ( array_keys ( $ interfaces ) as $ interface ) { if ( substr ( $ interface , - ( strlen ( $ interface_short_name ) + 1 ) ) == '\\' . $ interface_short_name ) { // The reflection doesn't give the initial '\'. $ full_interface_name = '\\' . $ interface ; return $ full_interface_name ; } } return '' ; }
Extracts the interface from the service class using reflection.

This expects a service to only implement a single interface.

@param string $service_class
The fully-qualified class name of the service.

@return string
The fully-qualified name of the interface with the initial '\', or an
empty string if no interface was found.
Extracts the interface from the service class using reflection .