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

Support 2.1 and 2.2 #545

Merged
merged 1 commit into from
Dec 3, 2024
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
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 @@
}
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);
} 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);
return new GVExport($moduleService);
Loading