Skip to content
Merged
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ $games = $client->getGames();

foreach ($games as $game) {
// like most other methods, this method returns a wrapper
// you can use the getData() method to get the game data
echo $game->getData()->getName() . PHP_EOL;
// wrappers extend the generated models, so all getters can be used directly
echo $game->getName() . PHP_EOL;
}

$games = $games->getNextPage();

foreach ($games as $game) {
echo $game->getData()->getName() . PHP_EOL;
echo $game->getName() . PHP_EOL;
}
```
You can also call `getGame` with the ID of a game to get a specific game. For example, 432 is the ID for Minecraft.
```php
$game = $client->getGame(432);
echo $game->getData()->getSlug() . PHP_EOL;
echo $game->getSlug() . PHP_EOL;
```

### Game Versions
Expand Down Expand Up @@ -146,7 +146,7 @@ $files = $mod->getFiles();
```
It optionally takes a ModFilesOptions object as a parameter:
```php
$options = new ModFilesOptions($mod->getData()->getId());
$options = new ModFilesOptions($mod->getId());
$options->setGameVersion("1.19.2");

use \Aternos\CurseForgeApi\Client\Options\ModSearch\ModLoaderType;
Expand All @@ -173,7 +173,7 @@ Note that the bulk endpoint doesn't require a mod id.
#### File Download URLs
You can get the download URL for a file like this:
```php
$url = $file->getData()->getDownloadUrl();
$url = $file->getDownloadUrl();
// or if you don't already have the file object
$url = $client->getModFileDownloadUrl(420561, 3787455);
```
Expand Down
23 changes: 8 additions & 15 deletions src/Client/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
use Aternos\CurseForgeApi\Client\Options\ModSearchOptions;
use Aternos\CurseForgeApi\Model\Category as CategoryModel;

class Category
class Category extends CategoryModel
{
public function __construct(
protected CurseForgeAPIClient $client,
protected CategoryModel $category,
CategoryModel $data
)
{
}

/**
* @return CategoryModel
*/
public function getData(): CategoryModel
{
return $this->category;
parent::__construct($data->container);
}

/**
Expand All @@ -33,13 +26,13 @@ public function getData(): CategoryModel
public function getMods(?ModSearchOptions $options = null): PaginatedModList
{
if ($options === null) {
$options = new ModSearchOptions($this->category->getGameId());
$options = new ModSearchOptions($this->getGameId());
}

if ($this->category->getIsClass()) {
$options->setClassId($this->category->getId());
if ($this->getIsClass()) {
$options->setClassId($this->getId());
} else {
$options->setCategoryIds([$this->category->getId()]);
$options->setCategoryIds([$this->getId()]);
}

return $this->client->searchMods($options);
Expand All @@ -52,6 +45,6 @@ public function getMods(?ModSearchOptions $options = null): PaginatedModList
*/
public function getGame(): Game
{
return $this->client->getGame($this->category->getGameId());
return $this->client->getGame($this->getGameId());
}
}
2 changes: 1 addition & 1 deletion src/Client/CurseForgeAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function getCategories(int $gameId, ?int $classId = null, ?bool $classesO
public function getCategory(int $gameId, int $categoryId): ?Category
{
foreach ($this->getCategories($gameId) as $category) {
if ($category->getData()->getId() === $categoryId) {
if ($category->getId() === $categoryId) {
return $category;
}
}
Expand Down
21 changes: 7 additions & 14 deletions src/Client/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
use Aternos\CurseForgeApi\ApiException;
use Aternos\CurseForgeApi\Model\File as FileModel;

class File
class File extends FileModel
{
public function __construct(
protected CurseForgeAPIClient $client,
protected FileModel $file,
FileModel $data
)
{
}

/**
* @return FileModel
*/
public function getData(): FileModel
{
return $this->file;
parent::__construct($data->container);
}

/**
Expand All @@ -29,11 +22,11 @@ public function getData(): FileModel
*/
public function getServerPack(): ?File
{
if (!$this->file->getServerPackFileId()) {
if (!$this->getServerPackFileId()) {
return null;
}

return $this->client->getModFile($this->file->getModId(), $this->file->getServerPackFileId());
return $this->client->getModFile($this->getModId(), $this->getServerPackFileId());
}

/**
Expand All @@ -46,7 +39,7 @@ public function getServerPack(): ?File
*/
public function getChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $markup = null): string
{
return $this->client->getModFileChangelog($this->file->getModId(), $this->file->getId(), $raw, $stripped, $markup);
return $this->client->getModFileChangelog($this->getModId(), $this->getId(), $raw, $stripped, $markup);
}

/**
Expand All @@ -56,6 +49,6 @@ public function getChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $m
*/
public function getMod(): Mod
{
return $this->client->getMod($this->file->getModId());
return $this->client->getMod($this->getModId());
}
}
27 changes: 10 additions & 17 deletions src/Client/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,19 @@
use Aternos\CurseForgeApi\Model\Game as GameModel;
use Aternos\CurseForgeApi\Model\GameVersionsByTypeV2;

class Game
class Game extends GameModel
{

/**
* @param CurseForgeAPIClient $client
* @param GameModel $game
* @param GameModel $data
*/
public function __construct(
protected CurseForgeAPIClient $client,
protected GameModel $game
GameModel $data
)
{
}

/**
* @return GameModel
*/
public function getData(): GameModel
{
return $this->game;
parent::__construct($data->container);
}

/**
Expand All @@ -37,7 +30,7 @@ public function getData(): GameModel
*/
public function getVersionTypes(): array
{
return $this->client->getGameVersionTypes($this->game->getId());
return $this->client->getGameVersionTypes($this->getId());
}

/**
Expand All @@ -47,7 +40,7 @@ public function getVersionTypes(): array
*/
public function getVersions(): array
{
return $this->client->getGameVersions($this->game->getId());
return $this->client->getGameVersions($this->getId());
}

/**
Expand All @@ -58,7 +51,7 @@ public function getVersions(): array
*/
public function getGameVersionsByType(int $versionTypeId): array
{
return $this->client->getGameVersionsByType($this->game->getId(), $versionTypeId);
return $this->client->getGameVersionsByType($this->getId(), $versionTypeId);
}

/**
Expand All @@ -69,7 +62,7 @@ public function getGameVersionsByType(int $versionTypeId): array
*/
public function getCategories(?int $classId = null, ?bool $classesOnly = null): array
{
return $this->client->getCategories($this->game->getId(), $classId, $classesOnly);
return $this->client->getCategories($this->getId(), $classId, $classesOnly);
}

/**
Expand All @@ -80,7 +73,7 @@ public function getCategories(?int $classId = null, ?bool $classesOnly = null):
*/
public function searchMods(?ModSearchOptions $options = null): PaginatedModList
{
return $this->client->searchMods($options ?? new ModSearchOptions($this->game->getId()));
return $this->client->searchMods($options ?? new ModSearchOptions($this->getId()));
}

/**
Expand All @@ -93,6 +86,6 @@ public function searchMods(?ModSearchOptions $options = null): PaginatedModList
*/
public function getFeaturedMods(array $excludedModIds = [], ?int $gameVersionTypeId = null, ?bool $clientCompatible = null): FeaturedMods
{
return $this->client->getFeaturedMods($this->game->getId(), $excludedModIds, $gameVersionTypeId, $clientCompatible);
return $this->client->getFeaturedMods($this->getId(), $excludedModIds, $gameVersionTypeId, $clientCompatible);
}
}
17 changes: 5 additions & 12 deletions src/Client/GameVersionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
use Aternos\CurseForgeApi\Model\GameVersionsByTypeV2;
use Aternos\CurseForgeApi\Model\GameVersionType as GameVersionTypeModel;

class GameVersionType
class GameVersionType extends GameVersionTypeModel
{
public function __construct(
protected CurseForgeAPIClient $client,
protected GameVersionTypeModel $gameVersion,
GameVersionTypeModel $data
)
{
}

/**
* @return GameVersionTypeModel
*/
public function getData(): GameVersionTypeModel
{
return $this->gameVersion;
parent::__construct($data->container);
}

/**
Expand All @@ -30,7 +23,7 @@ public function getData(): GameVersionTypeModel
*/
public function getVersions(): array
{
return $this->client->getGameVersionsByType($this->gameVersion->getGameId(), $this->gameVersion->getId());
return $this->client->getGameVersionsByType($this->getGameId(), $this->getId());
}

/**
Expand All @@ -40,6 +33,6 @@ public function getVersions(): array
*/
public function getGame(): Game
{
return $this->client->getGame($this->gameVersion->getGameId());
return $this->client->getGame($this->getGameId());
}
}
29 changes: 11 additions & 18 deletions src/Client/Mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Aternos\CurseForgeApi\Client\Options\ModFilesOptions;
use Aternos\CurseForgeApi\Model\Mod as ModModel;

class Mod
class Mod extends ModModel
{
public function __construct(
protected CurseForgeAPIClient $client,
protected ModModel $mod,
ModModel $data
)
{
parent::__construct($data->container);
}

/**
Expand All @@ -26,14 +27,6 @@ public static function fromModels(CurseForgeAPIClient $client, array $models): a
return array_map(fn($mod) => new Mod($client, $mod), $models);
}

/**
* @return ModModel
*/
public function getData(): ModModel
{
return $this->mod;
}

/**
* Fetch the description of this mod as html
* @param string|null $lang
Expand All @@ -42,7 +35,7 @@ public function getData(): ModModel
*/
public function getDescription(?string $lang = null): ?string
{
return $this->client->getModDescription($this->mod->getId(), $lang);
return $this->client->getModDescription($this->getId(), $lang);
}

/**
Expand All @@ -53,7 +46,7 @@ public function getDescription(?string $lang = null): ?string
*/
public function getFiles(?ModFilesOptions $options = null): PaginatedFilesList
{
return $this->client->getModFiles($options ?? new ModFilesOptions($this->mod->getId()));
return $this->client->getModFiles($options ?? new ModFilesOptions($this->getId()));
}

/**
Expand All @@ -63,7 +56,7 @@ public function getFiles(?ModFilesOptions $options = null): PaginatedFilesList
*/
public function getGame(): Game
{
return $this->client->getGame($this->mod->getGameId());
return $this->client->getGame($this->getGameId());
}

/**
Expand All @@ -72,8 +65,8 @@ public function getGame(): Game
*/
public function getPrimaryCategory(): ?Category
{
foreach ($this->mod->getCategories() as $category) {
if ($category->getId() === $this->mod->getPrimaryCategoryId()) {
foreach ($this->getCategories() as $category) {
if ($category->getId() === $this->getPrimaryCategoryId()) {
return new Category($this->client, $category);
}
}
Expand All @@ -87,7 +80,7 @@ public function getPrimaryCategory(): ?Category
*/
public function getCategoryClass(): Category
{
return $this->client->getCategory($this->mod->getGameId(), $this->mod->getClassId());
return $this->client->getCategory($this->getGameId(), $this->getClassId());
}

/**
Expand All @@ -97,7 +90,7 @@ public function getCategoryClass(): Category
*/
public function getMainFile(): File
{
return $this->getFile($this->mod->getMainFileId());
return $this->getFile($this->getMainFileId());
}

/**
Expand All @@ -107,6 +100,6 @@ public function getMainFile(): File
*/
public function getFile(int $fileId): File
{
return $this->client->getModFile($this->mod->getId(), $fileId);
return $this->client->getModFile($this->getId(), $fileId);
}
}
Loading
Loading