1: <?php
2:
3: /*
4: * Copyright (C) 2016 Luca
5: *
6: * This program is free software: you can redistribute it and/or modify
7: * it under the terms of the GNU Affero General Public License as published by
8: * the Free Software Foundation, either version 3 of the License, or
9: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Affero General Public License for more details.
15: *
16: * You should have received a copy of the GNU Affero General Public License
17: * along with this program. If not, see <http://www.gnu.org/licenses/agpl-3.0.html>.
18: */
19:
20: /**
21: * hzSystem SPL autoloader.
22: *
23: * @author Luca Liscio <hzkight@h0model.org>
24: * @version v 1.0 2016/09/09 17:03:20
25: * @copyright Copyright 2016 Luca Liscio
26: * @license http://www.gnu.org/licenses/agpl-3.0.html GNU/AGPL3
27: *
28: * @package hzSystem
29: * @filesource
30: */
31:
32: session_start();
33:
34: $_SESSION["hzSystem_path"] = dirname(__DIR__).DIRECTORY_SEPARATOR;
35: putenv("HZSVER=v0.1.0-Alfa");
36:
37: //First step set internazionalizzation
38:
39: //default language
40: $language = "it_IT";
41:
42: //check current language
43: if(getenv("LANG")!=null){
44: $language = getenv("LANG");
45: } else {
46: putenv("LANG=".$language);
47: }
48:
49: setlocale(LC_ALL, $language);
50:
51: $lang_path = $_SESSION["hzSystem_path"]."hzsystem".DIRECTORY_SEPARATOR."lang";
52: bindtextdomain("hzSystem", $lang_path);
53:
54: //Second step define SPL autoloader
55:
56: /**
57: * hzSystem SPL autoloader.
58: * @param string $classname The name of the class to load
59: */
60: function hzSystemAutoload($classname)
61: {
62: $pathtoclass = str_replace('\\', DIRECTORY_SEPARATOR, $classname);
63: $filename = $_SESSION["hzSystem_path"].strtolower($pathtoclass).'.class.php';
64: if (is_readable($filename)) {
65: require $filename;
66: }
67: }
68:
69: if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
70: //SPL autoloading was introduced in PHP 5.1.2
71: if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
72: spl_autoload_register('hzSystemAutoload', true, true);
73: } else {
74: spl_autoload_register('hzSystemAutoload');
75: }
76: } else {
77: /**
78: * Fall back to traditional autoload for old PHP versions
79: * @param string $classname The name of the class to load
80: */
81: function __autoload($classname)
82: {
83: hzSystemAutoload($classname);
84: }
85: }
86: