Closed belisoful closed 1 year ago
To be honest I'm not sure of the reason why TThemeManager is a member of TPageService instead of TApplication. There's no real dependency between the two classes; TThemeManager only depends on the request object (available in all modules, used to create the urls) and TTheme only on TCache. So, go for it. Maybe TTemplateManager could be another candidate to be taken outside TPageService, too.
maybe TPage as PDF/eBook format
I normally use a subclass of THttpResponseAdapter to achieve this result:
class YMPDFHttpResponseAdapter extends THttpResponseAdapter
{
...
public function flushContent()
{
$buffer = ob_get_clean();
$m = new mPDF('c');
$m->fontdata = [
"dejavusanscondensed" => [
'R' => "DejaVuSansCondensed.ttf",
'B' => "DejaVuSansCondensed-Bold.ttf",
'I' => "DejaVuSansCondensed-Oblique.ttf",
'BI' => "DejaVuSansCondensed-BoldOblique.ttf",
],
];
$m->WriteHTML($buffer);
$m->Output();
}
TTemplateManage is having the same issues of tied to TPageService when trying to use it in the coming TEmailerModule. So, I'm glad you pointed that out. It makes a LOT of sense to move these two modules to the TApplication, given what TEmail is doing.
Issue: I am working on a TEmail based upon TPage (and TTemplates!) and the TEmailerModule (a pseudo-service) needs to access the TThemeManager from the TPageService to render Emails properly. However, TPageService is not guaranteed to be the Service when using the TEmailerModule. TEmailerModule can generate and send TEmail even when the service is (eg.) JSON, Soap, or RPC. The TEmail needs the TThemeManager without a TPageService. The TDbEmailerModule can activate its own 'email' service for viewing (logged) emails by UUID if the user is having difficulty viewing the email in their browser. (a common feature of websites and their emails today). The TDbEmailService would also use TThemeManager but it would also block TDbEmailerModule from accessing TPageService::getThemeManager.
Problem: TThemeManager is specifically tied (in code) to TPageService and cannot be used by external modules outside of TPageService (as the running service).
Solution: TThemeManager needs to be unlinked from TPageService and incorporated into TApplication, similarly to how TAssetManager is tied into TApplication (as a private variable with associated get/set)
I don't know if there is a third way of using a TPage besides TEmail (maybe TPage as PDF/eBook format?). No doubt someone creative can figure out a new way of using a TPage requiring TThemeManager (outside of TPageService and TEmailerModule)