Read parser from config and inject it to handlers
This commit is contained in:
@ -9,10 +9,13 @@
|
||||
#include "../database/queryoption.h"
|
||||
#include "../logger.h"
|
||||
#include "../cache/icache.h"
|
||||
#include "../iparser.h"
|
||||
|
||||
class Handler
|
||||
{
|
||||
protected:
|
||||
ICache *cache;
|
||||
IParser *parser;
|
||||
Template *templ;
|
||||
Database *database;
|
||||
Session *userSession;
|
||||
@ -25,7 +28,7 @@ class Handler
|
||||
|
||||
public:
|
||||
Handler(HandlerConfig &handlersConfig, Template &templ, Database &db, Session &userSession, UrlProvider &provider,
|
||||
ICache &cache)
|
||||
ICache &cache, IParser &parser)
|
||||
{
|
||||
this->handlersConfig = &handlersConfig;
|
||||
this->templ = &templ;
|
||||
@ -33,6 +36,7 @@ class Handler
|
||||
this->userSession = &userSession;
|
||||
this->urlProvider = &provider;
|
||||
this->cache = &cache;
|
||||
this->parser = &parser;
|
||||
}
|
||||
|
||||
virtual Response handle(const Request &r);
|
||||
|
@ -10,15 +10,16 @@ class HandlerFactory
|
||||
Database &db;
|
||||
UrlProvider &urlProvider;
|
||||
ICache &cache;
|
||||
IParser &parser;
|
||||
|
||||
template <class T> inline std::unique_ptr<T> produce(Session &userSession)
|
||||
{
|
||||
return std::make_unique<T>(handlerConfig, templ, db, userSession, urlProvider, cache);
|
||||
return std::make_unique<T>(handlerConfig, templ, db, userSession, urlProvider, cache, parser);
|
||||
}
|
||||
|
||||
public:
|
||||
HandlerFactory(HandlerConfig &handlerConfig, Template &templ, Database &db, UrlProvider &urlprovider, ICache &cache)
|
||||
: handlerConfig(handlerConfig), templ(templ), db(db), urlProvider(urlprovider), cache(cache)
|
||||
HandlerFactory(HandlerConfig &handlerConfig, Template &templ, Database &db, UrlProvider &urlprovider, ICache &cache, IParser &parser)
|
||||
: handlerConfig(handlerConfig), templ(templ), db(db), urlProvider(urlprovider), cache(cache), parser(parser)
|
||||
{
|
||||
}
|
||||
std::unique_ptr<Handler> createHandler(const std::string &action, Session &userSession);
|
||||
|
@ -130,7 +130,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
|
||||
TemplatePage &page = this->templ->getPage(templatepartname);
|
||||
|
||||
ParserLegacy parser;
|
||||
|
||||
Response result;
|
||||
result.setStatus(200);
|
||||
std::string indexcontent;
|
||||
@ -138,8 +138,8 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
|
||||
if(revisionid > 0)
|
||||
{
|
||||
indexcontent = createIndexContent(parser, revision->content);
|
||||
parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content);
|
||||
indexcontent = createIndexContent(*parser, revision->content);
|
||||
parsedcontent = parser->parse(pageDao, *this->urlProvider, revision->content);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -153,7 +153,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
}
|
||||
else
|
||||
{
|
||||
indexcontent = createIndexContent(parser, revision->content);
|
||||
indexcontent = createIndexContent(*parser, revision->content);
|
||||
this->cache->put(cachekeyindexcontent, indexcontent);
|
||||
}
|
||||
if(cachedparsedcontent)
|
||||
@ -162,7 +162,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
}
|
||||
else
|
||||
{
|
||||
parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content);
|
||||
parsedcontent = parser->parse(pageDao, *this->urlProvider, revision->content);
|
||||
this->cache->put(cachekeyparsedcontent, parsedcontent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user