some work on dependency injection
git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1147 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,12 +37,14 @@
|
||||
|
||||
#include <map>
|
||||
#include "patterns.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class ChangePatterns
|
||||
class ChangePatterns : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,12 +40,15 @@
|
||||
#include <map>
|
||||
#include "ezc.h"
|
||||
#include "patterns.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class IndexPatterns
|
||||
class IndexPatterns : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,12 +39,14 @@
|
||||
#include <string>
|
||||
#include "space/spaceparser.h"
|
||||
#include "textstream/textstream.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class Locale
|
||||
class Locale : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,7 +33,7 @@
|
||||
*/
|
||||
|
||||
#include "localefilter.h"
|
||||
#include "../core/misc.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,12 +37,14 @@
|
||||
|
||||
#include "locale.h"
|
||||
#include "ezc.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class LocaleFilter
|
||||
class LocaleFilter : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,6 +32,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "patterncacher.h"
|
||||
#include "core/log.h"
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,6 +41,9 @@
|
||||
#include "core/item.h"
|
||||
#include "misc.h"
|
||||
#include "ezc.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
@@ -48,7 +51,7 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
class PatternCacher
|
||||
class PatternCacher : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2016, Tomasz Sowa
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,12 +39,14 @@
|
||||
#include "locale.h"
|
||||
#include "localefilter.h"
|
||||
#include "misc.h"
|
||||
#include "core/winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class Patterns
|
||||
class Patterns : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/version.h"
|
||||
#include "core/plugin.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
@@ -72,20 +72,20 @@ static size_t sys_plugin_index = 0;
|
||||
void sys_plugin_tab(Info & i)
|
||||
{
|
||||
sys_plugin_index = i.iter;
|
||||
i.res = sys_plugin_index < plugin.GetPlugins()->size();
|
||||
i.res = sys_plugin_index < plugin->GetPlugins()->size();
|
||||
}
|
||||
|
||||
void sys_plugin_tab_has_name(Info & i)
|
||||
{
|
||||
if( sys_plugin_index < plugin.GetPlugins()->size() )
|
||||
i.res = (*plugin.GetPlugins())[sys_plugin_index].plugin_name != 0;
|
||||
if( sys_plugin_index < plugin->GetPlugins()->size() )
|
||||
i.res = (*plugin->GetPlugins())[sys_plugin_index].plugin_name != 0;
|
||||
}
|
||||
|
||||
void sys_plugin_tab_name(Info & i)
|
||||
{
|
||||
if( sys_plugin_index < plugin.GetPlugins()->size() )
|
||||
if( sys_plugin_index < plugin->GetPlugins()->size() )
|
||||
{
|
||||
const wchar_t * name = (*plugin.GetPlugins())[sys_plugin_index].plugin_name;
|
||||
const wchar_t * name = (*plugin->GetPlugins())[sys_plugin_index].plugin_name;
|
||||
|
||||
if( name )
|
||||
i.out << name;
|
||||
|
||||
@@ -56,7 +56,8 @@ IndexPatterns index_patterns; // patterns for main index templates (those fr
|
||||
ChangePatterns change_patterns; // patterns for change_template mount option (storage is in 'patterns' too)
|
||||
PatternCacher pattern_cacher; // patterns for user items (files with an executable bit set)
|
||||
|
||||
Locale locale;
|
||||
Locale locale; // IMPROVE ME will be moved to a better place
|
||||
|
||||
EzcFun ezc_functions;
|
||||
Ezc::Blocks ezc_blocks;
|
||||
Ezc::Objects<HtmlTextStream> ezc_objects;
|
||||
@@ -73,12 +74,16 @@ const HtmlTextStream empty_stream;
|
||||
// en empty stack item for templates functions
|
||||
Ezc::Stack empty_stack;
|
||||
|
||||
Db * db;
|
||||
Cur * cur;
|
||||
Config * config;
|
||||
System * system;
|
||||
Functions * functions;
|
||||
SessionManager * session_manager;
|
||||
Db * db = nullptr;
|
||||
Cur * cur = nullptr;
|
||||
Config * config = nullptr;
|
||||
System * system = nullptr;
|
||||
Functions * functions = nullptr;
|
||||
SessionManager * session_manager = nullptr;
|
||||
|
||||
|
||||
Log log; // temporarily for ezc functions
|
||||
Plugin * plugin = nullptr; // temporarily for ezc functions
|
||||
|
||||
|
||||
// generator used by content() function
|
||||
@@ -778,7 +783,7 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("content", content);
|
||||
|
||||
|
||||
plugin.Call((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions, &ezc_objects);
|
||||
plugin->Call((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions, &ezc_objects);
|
||||
|
||||
|
||||
Ezc::Objects<HtmlTextStream>::Iterator i = ezc_objects.Begin();
|
||||
@@ -806,14 +811,12 @@ void Templates::CreateFunctions()
|
||||
|
||||
void Templates::ReadLocale()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
TemplatesFunctions::locale.SetLocaleFiles(config->locale_files);
|
||||
TemplatesFunctions::locale.SetLocaleMaxId(config->locale_max_id);
|
||||
TemplatesFunctions::locale.SetDefLang(config->locale_default_id);
|
||||
TemplatesFunctions::locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
locale.SetLocaleFiles(config->locale_files);
|
||||
locale.SetLocaleMaxId(config->locale_max_id);
|
||||
locale.SetDefLang(config->locale_default_id);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
log << log3 << "Templates: there are " << locale.Size() << " locales" << logend;
|
||||
log << log3 << "Templates: there are " << TemplatesFunctions::locale.Size() << " locales" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -891,15 +894,15 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( config->html_filter_orphans )
|
||||
{
|
||||
html_filter.OrphansMode(config->html_filter_orphans_mode);
|
||||
html_filter.OrphansMode(config->html_filter_orphans_mode_str);
|
||||
|
||||
for(size_t i=0 ; i<locale.Size() ; ++i)
|
||||
for(size_t i=0 ; i<TemplatesFunctions::locale.Size() ; ++i)
|
||||
{
|
||||
if( locale.IsKeyByIndex(L"html_lang_attr_value", i, false) &&
|
||||
locale.IsListByIndex(L"language_orphans", i, false) )
|
||||
if( TemplatesFunctions::locale.IsKeyByIndex(L"html_lang_attr_value", i, false) &&
|
||||
TemplatesFunctions::locale.IsListByIndex(L"language_orphans", i, false) )
|
||||
{
|
||||
html_filter.AssignOrphans(locale.GetByIndex(L"html_lang_attr_value", i, false),
|
||||
locale.GetListByIndex(L"language_orphans", i, false));
|
||||
html_filter.AssignOrphans(TemplatesFunctions::locale.GetByIndex(L"html_lang_attr_value", i, false),
|
||||
TemplatesFunctions::locale.GetListByIndex(L"language_orphans", i, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -969,7 +972,7 @@ using namespace TemplatesFunctions;
|
||||
ReadIndexTemplates();
|
||||
ReadChangeTemplates();
|
||||
|
||||
plugin.Call((Session*)0, WINIX_ADD_TEMPLATE);
|
||||
plugin->Call((Session*)0, WINIX_ADD_TEMPLATE);
|
||||
|
||||
patterns.RebuildCache();
|
||||
ezc_blocks.CacheObjects(ezc_objects);
|
||||
@@ -980,7 +983,7 @@ using namespace TemplatesFunctions;
|
||||
SetHtmlFilter();
|
||||
|
||||
log << log3 << "Templates: there are " << patterns.Size() << " patterns"
|
||||
<< " (" << (locale.Size() * patterns.Size()) << " for all locales)" << logend;
|
||||
<< " (" << (TemplatesFunctions::locale.Size() * patterns.Size()) << " for all locales)" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -1025,16 +1028,16 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( template_name == config->templates_index )
|
||||
{
|
||||
index = patterns.Get(pat_index, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
else
|
||||
if( template_name == config->templates_index_raw )
|
||||
{
|
||||
index = patterns.Get(pat_index_raw, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index_raw, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
else
|
||||
{
|
||||
index = index_patterns.Get(template_name, locale.GetCurLang());
|
||||
index = index_patterns.Get(template_name, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
|
||||
if( index )
|
||||
@@ -1070,7 +1073,7 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( !index )
|
||||
{
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetCurLang());
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, TemplatesFunctions::locale.GetCurLang());
|
||||
|
||||
if( index )
|
||||
log << log3 << "Templates: index template taken from change_patterns" << logend;
|
||||
@@ -1078,7 +1081,7 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( !index )
|
||||
{
|
||||
index = patterns.Get(pat_index, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index, TemplatesFunctions::locale.GetCurLang());
|
||||
|
||||
if( index )
|
||||
log << log3 << "Templates: index template taken from: " << config->templates_index << logend;
|
||||
@@ -1170,6 +1173,24 @@ void Templates::SetSessionManager(SessionManager * psession_manager)
|
||||
}
|
||||
|
||||
|
||||
void Templates::set_dependency(WinixRequest * winix_request)
|
||||
{
|
||||
WinixRequest::set_dependency(winix_request);
|
||||
TemplatesFunctions::locale.set_dependency(winix_request);
|
||||
TemplatesFunctions::change_patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::index_patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::pattern_cacher.set_dependency(winix_request);
|
||||
TemplatesFunctions::locale_filter.set_dependency(winix_request);
|
||||
TemplatesFunctions::html_filter.set_dependency(winix_request);
|
||||
|
||||
log.SetDependency(&this->log);
|
||||
log.Init(config->log_level, config->log_save_each_line, config->log_request);
|
||||
|
||||
plugin = winix_request->get_plugin();
|
||||
}
|
||||
|
||||
|
||||
Templates::Templates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
@@ -1178,7 +1199,7 @@ Templates::Templates()
|
||||
patterns.SetEzcFunctions(&ezc_functions);
|
||||
patterns.SetEzcBlocks(&ezc_blocks);
|
||||
|
||||
patterns.SetLocale(&locale);
|
||||
patterns.SetLocale(&TemplatesFunctions::locale);
|
||||
patterns.SetLocaleFilter(&locale_filter);
|
||||
|
||||
index_patterns.SetPatterns(&patterns);
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
#include "core/sessionmanager.h"
|
||||
#include "core/htmlfilter.h"
|
||||
#include "db/db.h"
|
||||
#include "core/winixrequest.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
@@ -80,12 +82,15 @@ namespace TemplatesFunctions
|
||||
extern Ezc::Stack empty_stack;
|
||||
|
||||
extern Db * db;
|
||||
extern Cur * cur;
|
||||
extern Config * config;
|
||||
extern System * system;
|
||||
extern Cur * cur; // will be removed when TemplateBase class will be implemented
|
||||
extern Config * config; // will be removed when TemplateBase class will be implemented
|
||||
extern System * system; // will be removed when TemplateBase class will be implemented
|
||||
extern Functions * functions;
|
||||
extern SessionManager * session_manager;
|
||||
|
||||
extern Log log; // will be removed when TemplateBase class will be implemented
|
||||
extern Plugin * plugin; // will be removed when TemplateBase class will be implemented
|
||||
|
||||
extern bool gen_trim_white;
|
||||
extern bool gen_skip_new_line;
|
||||
extern bool gen_use_special_chars;
|
||||
@@ -676,8 +681,9 @@ namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
class Templates
|
||||
// will be similar like Functions
|
||||
// concrete templates classes (based on TemplateBase) will be registered here
|
||||
class Templates : public WinixRequest
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -690,6 +696,8 @@ public:
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetSessionManager(SessionManager * psession_manager);
|
||||
|
||||
void set_dependency(WinixRequest * winix_request);
|
||||
|
||||
void Init();
|
||||
void ClearAfterRequest();
|
||||
void ReadTemplates();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <ctime>
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/plugin.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
@@ -134,7 +133,7 @@ size_t exist = 0;
|
||||
|
||||
for(size_t a=0 ; a<i.params.size() ; ++a)
|
||||
{
|
||||
if( plugin.HasPlugin(i.params[a].str) )
|
||||
if( plugin->HasPlugin(i.params[a].str) )
|
||||
++exist;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user