Automatic Docker build, abstract classes implementation in stubs

This commit is contained in:
Sys 2021-07-30 00:25:07 +02:00
parent 5b38b081c3
commit 1905ce6f95
No known key found for this signature in database
GPG Key ID: 3CD2C29F8AB39BFD
5 changed files with 69 additions and 4 deletions

View File

@ -1,5 +1,6 @@
composer.phar composer.phar
/vendor/ /vendor/
.idea/ /.idea/
/.git/
LICENSE LICENSE
README.md README.md

22
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
name: Build package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker image
uses: docker/build-push-action@v1
with:
registry: ghcr.io
username: sysbot-org
password: ${{ secrets.PAT }}
repository: sysbot-org/tgscraper
tags: latest

17
.github/workflows/delete.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Delete
on:
push:
branches:
- master
pull_request:
jobs:
build:
name: Delete old packages
runs-on: ubuntu-latest
steps:
- name: Delete oldest package
uses: actions/delete-package-versions@v1
with:
package-name: tgscraper
num-old-versions-to-delete: 1

View File

@ -47,7 +47,7 @@ class SchemaExtractor
* @throws ChildNotFoundException * @throws ChildNotFoundException
*/ */
#[ArrayShape(['description' => "string", 'table' => "mixed", 'extended_by' => "array"])] #[ArrayShape(['description' => "string", 'table' => "mixed", 'extended_by' => "array"])]
private function parseNode(Dom\Node\AbstractNode $node): ?array private static function parseNode(Dom\Node\AbstractNode $node): ?array
{ {
$description = ''; $description = '';
$table = null; $table = null;

View File

@ -24,6 +24,14 @@ class StubCreator
* @var string * @var string
*/ */
private string $namespace; private string $namespace;
/**
* @var array
*/
private array $abstractClasses = [];
/**
* @var array
*/
private array $extendedClasses = [];
/** /**
* StubCreator constructor. * StubCreator constructor.
@ -43,6 +51,16 @@ class StubCreator
if (!is_array($this->schema['methods']) or !is_array($this->schema['types'])) { if (!is_array($this->schema['methods']) or !is_array($this->schema['types'])) {
throw new InvalidArgumentException('Schema invalid'); throw new InvalidArgumentException('Schema invalid');
} }
foreach ($this->schema['types'] as $type) {
if (!empty($type['extended_by'])) {
$this->abstractClasses[] = $type['name'];
foreach ($type['extended_by'] as $extendedType) {
$this->extendedClasses[$extendedType] = $type['name'];
}
}
}
print_r($this->extendedClasses);
print_r($this->abstractClasses);
$this->namespace = $namespace; $this->namespace = $namespace;
} }
@ -125,7 +143,7 @@ class StubCreator
): array { ): array {
$interfaceFile = new PhpFile; $interfaceFile = new PhpFile;
$interfaceNamespace = $interfaceFile->addNamespace($namespace); $interfaceNamespace = $interfaceFile->addNamespace($namespace);
$interface = $interfaceNamespace->addInterface('TypeInterface'); $interfaceNamespace->addInterface('TypeInterface');
$responseFile = new PhpFile; $responseFile = new PhpFile;
$responseNamespace = $responseFile->addNamespace($namespace); $responseNamespace = $responseFile->addNamespace($namespace);
$response = $responseNamespace->addClass('Response') $response = $responseNamespace->addClass('Response')
@ -167,7 +185,14 @@ class StubCreator
$phpNamespace = $file->addNamespace($namespace); $phpNamespace = $file->addNamespace($namespace);
$typeClass = $phpNamespace->addClass($type['name']) $typeClass = $phpNamespace->addClass($type['name'])
->setType('class'); ->setType('class');
if (in_array($type['name'], $this->abstractClasses)) {
$typeClass->setAbstract();
}
if (array_key_exists($type['name'], $this->extendedClasses)) {
$typeClass->addExtend($namespace . '\\' . $this->extendedClasses[$type['name']]);
} else {
$typeClass->addImplement($namespace . '\\TypeInterface'); $typeClass->addImplement($namespace . '\\TypeInterface');
}
foreach ($type['fields'] as $field) { foreach ($type['fields'] as $field) {
['types' => $fieldTypes, 'comments' => $fieldComments] = $this->parseFieldTypes( ['types' => $fieldTypes, 'comments' => $fieldComments] = $this->parseFieldTypes(
$field['types'], $field['types'],