Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] [Feature] Docker support + Upgrade to 8.3 + regional Lodestone support + heavy refacto #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.sh]
indent_style = tab

[*.xml{,.dist}]
indent_style = space
indent_size = 4

[*.{yaml,yml}]
trim_trailing_whitespace = false

[.github/workflows/*.yml]
indent_size = 2

[.gitmodules]
indent_style = tab

[.php_cs{,.dist}]
indent_style = space
indent_size = 4

[composer.json]
indent_size = 4

[{,docker-}compose{,.*}.{yaml,yml}]
indent_style = space
indent_size = 2

[{,*.*}Dockerfile]
indent_style = tab

[{,*.*}Caddyfile]
indent_style = tab
4 changes: 1 addition & 3 deletions .github/workflows/php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ permissions:

jobs:
tests:

runs-on: ubuntu-latest
strategy:
matrix:
php:
- '7.2'
- '7.4'
- '8.3'
composer_preference:
- 'lowest'
- 'highest'
Expand Down
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
.idea
vendor
.phpunit.cache/

composer.lock

export/achievements/*
export/banners/*
export/character/*
export/characterfull/*
export/cwlinkshell/*
export/freecompany/*
export/leaderboards/*
export/linkshell/*
export/pvpteam/*

!**.gitkeep

test\.json
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM php:8.3-alpine AS php_base

WORKDIR /app

VOLUME /app/var/

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN apk add --no-cache \
acl \
file \
gettext \
git \
;

RUN set -eux; \
install-php-extensions \
@composer \
apcu \
intl \
opcache \
;

ENV COMPOSER_ALLOW_SUPERUSER=1

# Dev FrankenPHP image
FROM php_base AS php_dev

ENV XDEBUG_MODE=debug

VOLUME /app/var/

RUN apk add --no-cache \
curl \
;

RUN set -eux; \
install-php-extensions \
xdebug \
;

FROM php_base AS php_prod

COPY --link docker/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY --link composer.* ./
RUN set -eux; \
composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress

# copy sources
COPY --link . ./
RUN rm -Rf docker/

RUN set -eux; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer dump-env prod; \
composer run-script --no-dev post-install-cmd;
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@ Parse lodestone for those juicy details
- Run `php cli <func> <arguments>` for debugging
- Run `php tests` to validate tests

|CLI Command|Arguments|Description|
|-|-|-|
|`character`|`<id>`|Prints a character parse.
|`freecompany`|`<id>`|Prints a freecompanies parse.|
|`pvpteam`|`<id>`|Prints a pvpteam parse.|
|`linkshell`|`<id>`|Prints a linkshell parse.|
|`achievements`|`<id>`|Prints a characters achievement parse.|
|`banners`|none|Prints the currently displayed banners on the lodestone homepage.|
|`leaderboards`|`feast`,`potd`,`hoh`|Prints the current leaderboard parse for The Feast, Palace of The Dead, or Heaven on High.|
| CLI Command |Arguments|Description|
|-----------------|-|-|
| `character` |`<id>`|Prints a character parse.
| `characterfull` |`<id>`|Prints a character parse with its complete class jobs list.
| `freecompany` |`<id>`|Prints a freecompanies parse.|
| `pvpteam` |`<id>`|Prints a pvpteam parse.|
| `linkshell` |`<id>`|Prints a linkshell parse.|
| `achievements` |`<id>`|Prints a characters achievement parse.|
| `banners` |none|Prints the currently displayed banners on the lodestone homepage.|
| `leaderboards` |`feast`,`potd`,`hoh`|Prints the current leaderboard parse for The Feast, Palace of The Dead, or Heaven on High.|

All commands accept a flag to print the returned blob to a json file.
Example
All commands accept a flag to print the returned blob to a json file (with `-f filename` after the `<func>`).

The json file is saved in the `export` directory under the directory with the command name.

## Languages supported
- `en`: English (default)
- `fr`: French
- `de`: German
- `ja`: Japanese

## Commands with language support
- `character`
- `characterfull`
- `freecompany`
- `achievements`

## Examples
```
// prints returned object to file myCharacter.json
php cli character <lodestoneid> -file myCharacter
```
php cli character <lodestoneid> -f myCharacter
```
```
// prints returned object to file myCharacter.json from the French Lodestone
php cli character <lodestoneid> -f myCharacter -l fr
```
107 changes: 60 additions & 47 deletions cli
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
*/

// composer auto loader
use Lodestone\Enum\LocaleEnum;

require __DIR__ . '/vendor/autoload.php';

$api = new \Lodestone\Api();
$exporter = new \LodestoneUtils\Exporter();

print_r($argv);
//print_r($argv);

if ($argc < 2) {
print("No arguments provided.\n");
Expand All @@ -22,18 +25,46 @@ if ($argc < 2) {
array_shift($argv);
$cliCommandType = $argv[0];

$locale = LocaleEnum::EN->value;

foreach ($argv as $key => $arg) {
if ($arg === "-l") {
if (
!isset($argv[$key + 1])
|| !LocaleEnum::isValid(strtolower($argv[$key + 1]))
) {
print_r("INVALID ARGUMENT: Expected country identifier or wrong country identifier\n");
exit(1);
}
$locale = strtolower($argv[$key + 1]);
break;
}
}

switch ($cliCommandType) {
case "character":
if (!isset($argv[1])) {
print_r("INVALID ARGUMENT: Expected Character ID\n");
break;
}
print_r("Parsing character of {$argv[1]}...\n");
$results = $api->character()->get($argv[1]);
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->character()->get($argv[1], $locale);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
break;

case "characterfull":
if (!isset($argv[1])) {
print_r("INVALID ARGUMENT: Expected Character ID\n");
break;
}
print_r("Parsing character of {$argv[1]}...\n");
$results = $api->character()->getFull($argv[1], $locale, true);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand All @@ -45,11 +76,9 @@ switch ($cliCommandType) {
break;
}
print_r("Parsing freecompany of {$argv[1]}...\n");
$results = $api->freecompany()->get($argv[1]);
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->freecompany()->get($argv[1], $locale);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand All @@ -61,11 +90,9 @@ switch ($cliCommandType) {
break;
}
print_r("Parsing pvp team of {$argv[1]}...\n");
$results = $api->pvpteam()->get($argv[1]);
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->pvpteam()->get($argv[1], $locale);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand All @@ -77,11 +104,9 @@ switch ($cliCommandType) {
break;
}
print_r("Parsing linkshell of {$argv[1]}...\n");
$results = $api->linkshell()->get($argv[1])->Results;
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->linkshell()->get(id: $argv[1], locale: $locale)->Results;
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand All @@ -93,11 +118,9 @@ switch ($cliCommandType) {
break;
}
print_r("Parsing linkshell of {$argv[1]}...\n");
$results = $api->linkshell()->getCrossWorld($argv[1])->Results;
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->linkshell()->getCrossWorld(id: $argv[1], locale: $locale)->Results;
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand All @@ -109,22 +132,18 @@ switch ($cliCommandType) {
break;
}
print_r("Parsing achievements of {$argv[1]}...\n");
$results = $api->character()->achievements($argv[1]);
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
$results = $api->character()->achievements(id: $argv[1], locale: $locale);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
break;

case "banners":
$results = $api->lodestone()->banners();
if (isset($argv[1]) == "-file") {
$file = fopen("{$argv[2]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
if (isset($argv[1]) == "-f") {
$exporter->exportToFile($argv[0], $argv[2], $results);
break;
}
print_r($results);
Expand All @@ -135,32 +154,26 @@ switch ($cliCommandType) {
switch ($argv[1]) {
case "feast":
$results = $api->leaderboards()->feast();
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
break;

case "potd":
$results = $api->leaderboards()->ddPalaceOfTheDead();
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
break;

case "hoh":
$results = $api->leaderboards()->ddHeavenOnHigh();
if (isset($argv[2]) == "-file") {
$file = fopen("{$argv[3]}.json", 'w');
fwrite($file, json_encode($results));
fclose($file);
if (isset($argv[2]) == "-f") {
$exporter->exportToFile($argv[0], $argv[3], $results);
break;
}
print_r($results);
Expand Down
Loading