Passed
Push — main ( cdfe2b...915a08 )
by Sammy
01:35
created

common.inc.php (6 issues)

1
<?php
2
3
namespace HexMakina\kadro
4
{
5
	use \HexMakina\LocalFS\FileSystem;
0 ignored issues
show
The type HexMakina\LocalFS\FileSystem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
	define('KADRO_BASE', APP_BASE.'/lib/kadro/'); // this is project dependant, should be in settings
0 ignored issues
show
The constant HexMakina\kadro\APP_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
8
	// define('QIVIVE_BASE', APP_BASE.'/lib/qivive/'); // this is project dependant, should be in settings
9
10
	set_include_path(implode(PATH_SEPARATOR, [get_include_path(), APP_BASE, APP_BASE.'/lib/', APP_BASE.'/vendor/', KADRO_BASE]));
11
12
	//---------------------------------------------------------------     autoloader
13
  require APP_BASE.'vendor/autoload.php';
14
15
	require 'PSR4Autoloader.class.php';
16
	$loader=new PSR4Autoloader;
17
	$loader->register(); //Register loader with SPL autoloader stack.
18
19
	$loader->addNamespace('HexMakina', APP_BASE.'/lib/');
20
21
	// $loader->addNamespace('HexMakina\Crudites', APP_BASE.'/lib/Crudites/');
22
	// $loader->addNamespace('HexMakina\ORM', APP_BASE.'/lib/ORM/');
23
	// $loader->addNamespace('HexMakina\Lezer', APP_BASE.'/lib/Lezer/');
24
	// $loader->addNamespace('HexMakina\Format', APP_BASE.'/lib/Format');
25
26
	// $loader->addNamespace('HexMakina\kadro', KADRO_BASE);
27
	// $loader->addNamespace('HexMakina\qivive', QIVIVE_BASE);
28
	// $loader->addNamespace('HexMakina\LocalFS', __DIR__.'/Format/File');
29
	$loader->addNamespaceTree(KADRO_BASE);
30
31
	//---------------------------------------------------------------     erara raportado
32
	error_reporting(E_ALL);
33
34
	set_error_handler('\HexMakina\kadro\Logger\LogLaddy::error_handler');
35
	set_exception_handler('\HexMakina\kadro\Logger\LogLaddy::exception_handler');
36
37
	\HexMakina\Debugger\Debugger::init();
0 ignored issues
show
The type HexMakina\Debugger\Debugger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
39
	//---------------------------------------------------------------     parametroj
40
	require_once APP_BASE.'configs/settings.php';
41
	$box=new Container\LeMarchand($settings);
42
43
  foreach($box->get('settings.app.namespaces') as $namespace => $path)
44
  {
45
  	$loader->addNamespace($namespace, $path);
46
  }
47
48
	define('PRODUCTION', $_SERVER['HTTP_HOST'] === $box->get('settings.app.production_host'));
49
	ini_set('display_errors', PRODUCTION ? 0 : 1);
50
51
	//---------------------------------------------------------------       logger
52
	$box->register('LoggerInterface', new Logger\LogLaddy());
53
54
	//---------------------------------------------------------------       router
55
	$box->register('RouterInterface', new Router\hopper($box->get('settings.RouterInterface')));
56
57
	//---------------------------------------------------------------        kuketoj
58
	setcookie('cookie_test', 'test_value', time()+(365 * 24 * 60 * 60), "/", "");
59
	$cookies_enabled=isset($_COOKIE['cookie_test']); // houston, do we have cookies ?
60
61
	if($cookies_enabled === false)
62
	{
63
		ini_set('session.use_cookies', 0);
64
		ini_set('session.use_only_cookies', 0);
65
		ini_set('session.use_trans_sid', 1);
66
		ini_set('session.cache_limiter', 'nocache');
67
	}
68
69
//---------------------------------------------------------------        Session Management
70
	$StateAgent=new StateAgent($box->get('settings.app.session_start_options') ?? []);
71
	$StateAgent->add_runtime_filters((array)$box->get('settings.filter'));
72
	$StateAgent->add_runtime_filters((array)($_SESSION['filter'] ?? []));
73
	$StateAgent->add_runtime_filters((array)($_REQUEST['filter'] ?? []));
74
75
	$box->register('StateAgent', $StateAgent);
76
77
78
	//---------------------------------------------------------------     parametroj:signo
79
80
	ini_set('default_charset', $box->get('settings.default.charset'));
81
	header('Content-type: text/html; charset='.strtolower($box->get('settings.default.charset')));
82
83
	//---------------------------------------------------------------     parametroj:linguo
84
	putenv('LANG='.$box->get('settings.default.language'));
85
	setlocale(LC_ALL, $box->get('settings.default.language'));
86
87
	//---------------------------------------------------------------     parametroj:datoj
88
	date_default_timezone_set($box->get('settings.default.timezone'));
89
90
91
	//---------------------------------------------------------------     ŝablonoj
92
	require_once 'smarty/smarty/libs/Smarty.class.php';
93
	// Load smarty template parser
94
	if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path')))
95
			throw new \Exception("SMARTY CONFIG ERROR: missing parameters");
96
97
	$smarty=new \Smarty();
0 ignored issues
show
The type Smarty was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
	$box->register('template_engine', $smarty);
99
100
	$smarty->setTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path').'app');
101
	$smarty->addTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path'));
102
	$smarty->addTemplateDir(KADRO_BASE . 'Views/');
103
104
	$smarty->setCompileDir(APP_BASE . $box->get('settings.smarty.compiled_path'));
105
	$smarty->setDebugging($box->get('settings.smarty.debug'));
106
107
	$smarty->registerClass('Lezer', 			'\HexMakina\Lezer\Lezer');
108
	$smarty->registerClass('Marker', 			'\HexMakina\Format\HTML\Marker');
109
	$smarty->registerClass('Form', 				'\HexMakina\Format\HTML\Form');
110
	$smarty->registerClass('TableToForm',	'\HexMakina\kadro\TableToForm');
111
	$smarty->registerClass('Dato', 				'\HexMakina\Format\Tempo\Dato');
112
113
	$smarty->assign('APP_NAME', $box->get('settings.app.name'));
114
115
	//---------------------------------------------------------------     lingva
116
117
	$languages=\HexMakina\Lezer\Lezer::languages_by_file(APP_BASE.'locale/');
0 ignored issues
show
The type HexMakina\Lezer\Lezer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
118
119
  $smarty->assign('languages', $languages);
120
121
	$language=null;
122
123
	// changing / setting the language
124
	if(isset($_GET['lang']))
125
	{
126
		if(isset($languages[$_GET['lang']]))
127
		{
128
			$language=$_GET['lang'];
129
			if($cookies_enabled === true)
130
				setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", "");
131
			else
132
				trigger_error('KADRO_SYSTEM_ERR_COOKIES_ARE_DISABLED_LANGUAGE_CANNOT_BE_STORED', E_USER_WARNING);
133
		}
134
		else
135
			throw new \Exception('KADRO_SYSTEM_ERR_INVALID_PARAMETER');
136
	}
137
	else if($cookies_enabled === true && array_key_exists('lang', $_COOKIE) && array_key_exists($_COOKIE['lang'], $languages))
138
		$language=$_COOKIE['lang'];
139
140
	if(is_null($language) && !empty($languages))
141
	{
142
		if(count($languages) === 1)
143
			$language=key($languages);
144
		elseif(array_key_exists($box->get('settings.default.language'), $languages))
145
			$language=$box->get('settings.default.language');
146
		else
147
			throw new \Exception('FALLBACK_TO_DEFAULT_LANGUAGE_FAILED');
148
		$i18n = new \HexMakina\Lezer\Lezer(APP_BASE.'locale/'.$language.'/user_interface.json', APP_BASE.'locale/cache/', $language);
149
		$i18n->init();
150
		$smarty->assign('language', $language);
151
	}
152
}
153
154
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
155