protected function processHookFile($filepath) {
    $contents = file_get_contents("$filepath");

    // Prepare a replacement set of the import statements, so we can replace
    // short class names will fully-qualified ones, so the sample code can
    // actually run.
    $imports_pattern = "@^use (.+);@m";
    $matches = [];
    preg_match_all($imports_pattern, $contents, $matches);
    $imports = $matches[1];

    $import_replacements = [];
    foreach ($imports as $import) {
      $pieces = explode('\\', $import);
      $short_class_name = array_pop($pieces);

      $import_replacements['@\b' . $short_class_name . '\b@'] = '\\' . $import;
    }

    // The pattern for extracting function data: capture first line of doc,
    // function declaration, and hook name.
    $pattern = '[
             / \* \* \n     # start phpdoc
            \  \* \  ( .* ) \n  # first line of phpdoc: capture the text for the description
      ( (?: \  \* .* \n )* )  # lines of phpdoc: capture the documentation
            \  \* /  \n     # end phpdoc
           ( function \ ( ( hook | callback ) \w+ ) .* ) \ { # function declaration: capture...
      #    ^ entire definition and name
      #                 ^ function name
      #                   ^ whether this is a hook or a callback
       ( (?: .* \n )*? )    # function body: capture example code
           ^ }
    ]mx';

    $matches = [];
    preg_match_all($pattern, $contents, $matches);

    // We don't care about the full matches.
    //array_shift($matches);

    $data = array(
      'descriptions'  => $matches[1],
      'documentation' => $matches[2],
      'definitions'   => $matches[3],
      'names'         => $matches[4],
      'type'          => $matches[5],
      'bodies'        => $matches[6],
    );

    // Replace all the short class names in body code with fully-qualified ones.
    foreach ($data['bodies'] as &$hook_body) {
      $hook_body = preg_replace(array_keys($import_replacements), array_values($import_replacements), $hook_body);
    }

    return $data;
  }