Skip to content

Commit

Permalink
Merge pull request #545 from Neriderc/both-versions
Browse files Browse the repository at this point in the history
Support 2.1 and 2.2
  • Loading branch information
Neriderc authored Dec 3, 2024
2 parents 9a6bb4a + fe9edbe commit 75752fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/ApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function __construct(ServerRequestInterface $request, GVExport $module, T
* @return mixed
*/
public function getResponse() {
$stream = Registry::container()->get(StreamFactoryInterface::class)->createStream(json_encode($this->response_data));
$response_factory = Registry::container()->get(ResponseFactoryInterface::class);
$stream = GVExport::getClass(StreamFactoryInterface::class)->createStream(json_encode($this->response_data));
$response_factory = GVExport::getClass(ResponseFactoryInterface::class);
return $response_factory->createResponse()
->withBody($stream)
->withHeader('Content-Type', "application/json");
Expand Down
8 changes: 4 additions & 4 deletions app/Favourite.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ private function addUserFavourite(Tree $tree, string $url, string $title): bool
$note = "";
$user = Auth::user();
$favorite = function ($tree, $user, $url, $title, $note) {
return Registry::container()->get(UserFavoritesModule::class)->addUrlFavorite($tree, $user, $url, $title, $note);
return GVExport::getClass(UserFavoritesModule::class)->addUrlFavorite($tree, $user, $url, $title, $note);
};
$favorite->call(Registry::container()->get(UserFavoritesModule::class), $tree, $user, $url, $title, $note);
$favorite->call(GVExport::getClass(UserFavoritesModule::class), $tree, $user, $url, $title, $note);
return true;
}

Expand All @@ -77,9 +77,9 @@ private function addTreeFavourite(Tree $tree, string $url, string $title): bool
{
$note = "";
$favorite = function ($tree, $url, $title, $note) {
return Registry::container()->get(FamilyTreeFavoritesModule::class)->addUrlFavorite($tree, $url, $title, $note);
return GVExport::getClass(FamilyTreeFavoritesModule::class)->addUrlFavorite($tree, $url, $title, $note);
};
$favorite->call(Registry::container()->get(FamilyTreeFavoritesModule::class), $tree, $url, $title, $note);
$favorite->call(GVExport::getClass(FamilyTreeFavoritesModule::class), $tree, $url, $title, $note);
return true;
}
}
4 changes: 2 additions & 2 deletions app/OutputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function __construct($temp_dir, $file_type, $module) {
function downloadFile()
{
$stream = $this->getFileStream();
$response_factory = Registry::container()->get(ResponseFactoryInterface::class);
$response_factory = GVExport::getClass(ResponseFactoryInterface::class);
return $response_factory->createResponse()
->withBody($stream)
->withHeader('Content-Type', $this->settings['graphviz_config']['output'][$this->fileType]['cont_type'])
Expand All @@ -59,7 +59,7 @@ private function getFileStream() {
}
}

return Registry::container()->get(StreamFactoryInterface::class)->createStreamFromFile($filename);
return GVExport::getClass(StreamFactoryInterface::class)->createStreamFromFile($filename);
}

}
17 changes: 16 additions & 1 deletion module.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,22 @@ private function strip_param_from_url($url, $param): string
}
return $url;
}

/**
* A breaking change in webtrees 2.2.0 changes how the classes are retrieved.
* This function allows support for both 2.1.X and 2.2.X versions
* @param $class
* @return mixed
*/
static function getClass($class)
{
if (version_compare(Webtrees::VERSION, '2.2.0', '>=')) {
return Registry::container()->get($class);

Check warning on line 444 in module.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Registry'
} else {
return app($class);

Check warning on line 446 in module.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'app'
}
}
}

$moduleService = Registry::container()->get(ModuleService::class);
$moduleService = GVExport::getClass(ModuleService::class);

Check warning on line 451 in module.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'ModuleService'
return new GVExport($moduleService);

0 comments on commit 75752fb

Please sign in to comment.