Skip to content

Commit

Permalink
Update low level api docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dirx committed Jan 21, 2023
1 parent f8f6750 commit f1d1d09
Show file tree
Hide file tree
Showing 30 changed files with 2,335 additions and 1,125 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ It supports the same interfaces as the [PHP RdKafka extension](https://github.co
## Runtime Requirements

* PHP ^7.4 or ^8.0 with extensions FFI enabled
* librdkafka ^1.0.0
* librdkafka ^1.0.0 or ^2.0.0
* Conflicts: RdKafka extension
* Suggested:
* zend opcache extension for preloading
* pcntl extension for faster shutdown in request/response context

Note: Support for macOS and Windows is currently experimental.
Note: Support for macOS and Windows is experimental.

## Installation

Expand Down
37 changes: 19 additions & 18 deletions resources/ffigen/LibrdkafkaDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LibrdkafkaDocumentation
protected array $documentedElements;
private string $url;

public function __construct(string $url = 'https://docs.confluent.io/3.2.1/clients/librdkafka/rdkafka_8h.html')
public function __construct(string $url = 'https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html')
{
$this->url = $url;
}
Expand All @@ -23,19 +23,20 @@ public function extract(): void
{
echo 'Download and prepare librdkafka documentation ...';

$page = new Crawler(file_get_contents($this->url));
$elements = $page->filter('a[class=anchor]')->each(
$html = file_get_contents($this->url);
$page = new Crawler($html);
$elements = $page->filter('div[class=contents] a[id]')->each(
function (Crawler $node, $i) {
// extract defines & methods
if ($node->nextAll()->count()
&& $node->nextAll()->first()->filter('td[class=memname]')->count()
&& $node->nextAll()->first()->filter('div[class=memdoc]')->count()
&& $node->nextAll()->eq(1)->filter('td[class=memname]')->count()
&& $node->nextAll()->eq(1)->filter('div[class=memdoc]')->count()
) {
// extract enumerators
if ($node->nextAll()->first()->filter('td[class=fieldname]')->count()
&& $node->nextAll()->first()->filter('td[class=fielddoc]')->count()
if ($node->nextAll()->eq(1)->filter('td[class=fieldname]')->count()
&& $node->nextAll()->eq(1)->filter('td[class=fielddoc]')->count()
) {
$enums = $node->nextAll()->first()->filter('td[class=fieldname]')->each(
$enums = $node->nextAll()->eq(1)->filter('td[class=fieldname]')->each(
function (Crawler $node, $i) {
return [
'name' => $this->filterHtml($node->text()),
Expand All @@ -46,26 +47,26 @@ function (Crawler $node, $i) {
}

// extract params - and remove them (from description)
if ($node->nextAll()->first()->filter('td[class=paramname]')->count()) {
$params = $node->nextAll()->first()->filter('td[class=paramname]')->each(
if ($node->nextAll()->eq(1)->filter('td[class=paramname]')->count()) {
$params = $node->nextAll()->eq(1)->filter('td[class=paramname]')->each(
function (Crawler $node, $i) {
return [
'name' => $this->filterHtml($node->text()),
'description' => $this->filterHtml($node->nextAll()->first()->html('')),
];
}
);
$node->nextAll()->first()->filter('dl[class=params]')->each(
$node->nextAll()->eq(1)->filter('dl[class=params]')->each(
function (Crawler $node, $i): void {
$node->getNode(0)->parentNode->removeChild($node->getNode(0));
}
);
}

// extract return - and remove them (from description)
if ($node->nextAll()->first()->filter('dl[class*=return] dd')->count()) {
$return = $this->filterHtml($node->nextAll()->first()->filter('dl[class*=return] dd')->first()->html(''));
$node->nextAll()->first()->filter('dl[class*=return]')->each(
if ($node->nextAll()->eq(1)->filter('dl[class*=return] dd')->count()) {
$return = $this->filterHtml($node->nextAll()->eq(1)->filter('dl[class*=return] dd')->first()->html(''));
$node->nextAll()->eq(1)->filter('dl[class*=return]')->each(
function (Crawler $node, $i): void {
$node->getNode(0)->parentNode->removeChild($node->getNode(0));
}
Expand All @@ -74,11 +75,11 @@ function (Crawler $node, $i): void {

return [
'id' => $node->attr('id'),
'name' => $node->nextAll()->first()->filter('td[class=memname]')->count()
? $this->filterHtml($node->nextAll()->first()->filter('td[class=memname]')->first()->html(''))
'name' => $node->nextAll()->eq(1)->filter('td[class=memname]')->count()
? $this->filterHtml($node->nextAll()->eq(1)->filter('td[class=memname]')->first()->html(''))
: '',
'description' => $node->nextAll()->first()->filter('div[class=memdoc]')->count()
? $this->filterHtml($node->nextAll()->first()->filter('div[class=memdoc]')->first()->html(''))
'description' => $node->nextAll()->eq(1)->filter('div[class=memdoc]')->count()
? $this->filterHtml($node->nextAll()->eq(1)->filter('div[class=memdoc]')->first()->html(''))
: '',
'params' => $params ?? [],
'return' => $return ?? null,
Expand Down
4 changes: 2 additions & 2 deletions resources/ffigen/LibrdkafkaHeaderFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function prepareVersion(string $version): void
$content = @file_get_contents($this->config->getOutputPath() . '/' . $version . '-' . $fileName);
} else {
$url = $baseUrl . '/' . $fileName;
echo " Download ${url}" . PHP_EOL;
echo " Download {$url}" . PHP_EOL;

$content = @file_get_contents($url);
if ($content === false) {
Expand All @@ -57,7 +57,7 @@ public function prepareVersion(string $version): void
$content = $this->prepareFileContent($file, $content, $version);
$this->filesystem->dumpFile($file, $content);

echo " Save as ${file}" . PHP_EOL;
echo " Save as {$file}" . PHP_EOL;
}
}

Expand Down
Loading

0 comments on commit f1d1d09

Please sign in to comment.