1
|
|
|
<?php
|
|
|
|
|
2
|
|
|
/**
|
3
|
|
|
* @author Alexey Tatarinov <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2016 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
*/
|
8
|
|
|
/**
|
9
|
|
|
* Class GlobalConfig
|
10
|
|
|
*
|
11
|
|
|
* @property string $rootPath
|
12
|
|
|
* @property string $frameworkPath
|
13
|
|
|
* @property string $backendPath
|
14
|
|
|
* @property string $frontendPath
|
15
|
|
|
* @property string $frontendConfigPath
|
16
|
|
|
* @property string $backendConfigPath
|
17
|
|
|
* @property string $frameworkVersion
|
18
|
|
|
*/
|
19
|
|
|
class GlobalConfig
|
20
|
|
|
{
|
21
|
|
|
protected $rootPath;
|
22
|
|
|
|
23
|
|
|
protected $frameworkPath;
|
24
|
|
|
|
25
|
|
|
protected $frontendPath;
|
26
|
|
|
|
27
|
|
|
protected $frontendConfigPath;
|
28
|
|
|
|
29
|
|
|
protected $backendPath;
|
30
|
|
|
|
31
|
|
|
protected $backendConfigPath;
|
32
|
|
|
|
33
|
|
|
/**
|
34
|
|
|
* @var GlobalConfig $instance
|
35
|
|
|
*/
|
36
|
|
|
protected static $instance;
|
37
|
|
|
|
38
|
|
|
/**
|
39
|
|
|
* @var string $frameworkVersion требуемая версия фреймворка
|
40
|
|
|
*/
|
41
|
|
|
protected $frameworkVersion;
|
42
|
|
|
|
43
|
|
|
public function __construct()
|
44
|
|
|
{
|
45
|
|
|
$this->rootPath = realpath(__DIR__.'/../../');
|
46
|
|
|
$this->frontendPath = $this->rootPath.'/protected';
|
47
|
|
|
$this->frontendConfigPath = $this->rootPath.'/protected/config';
|
48
|
|
|
$frameworkConfig = require_once $this->frontendConfigPath.'/framework.php';
|
49
|
|
|
|
50
|
|
|
if( !($this->frameworkPath = realpath($this->rootPath.$frameworkConfig['frameworkPath'])) )
|
51
|
|
|
{
|
52
|
|
|
throw new Exception('Framework path "'.$frameworkConfig['frameworkPath'].'" wasn\'t found');
|
53
|
|
|
}
|
54
|
|
|
|
55
|
|
|
$this->frameworkVersion = $frameworkConfig['version'];
|
56
|
|
|
$this->backendPath = $this->rootPath.'/backend/protected';
|
57
|
|
|
$this->backendConfigPath = $this->rootPath.'/backend/protected/config';
|
58
|
|
|
}
|
59
|
|
|
|
60
|
33 |
|
public function __get($name)
|
61
|
|
|
{
|
62
|
33 |
|
$getter = 'get'.$name;
|
63
|
|
|
|
64
|
33 |
|
if( method_exists($this, $getter) )
|
65
|
33 |
|
{
|
66
|
|
|
return $this->$getter();
|
67
|
|
|
}
|
68
|
33 |
|
else if( property_exists($this, $name) )
|
69
|
33 |
|
{
|
70
|
33 |
|
return $this->$name;
|
71
|
|
|
}
|
72
|
|
|
|
73
|
|
|
throw new Exception('Property "'.get_class($this).'.'.$name.'" is not defined.');
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* @return GlobalConfig
|
78
|
|
|
*/
|
79
|
33 |
|
public static function instance()
|
80
|
|
|
{
|
81
|
33 |
|
if( isset(self::$instance) )
|
82
|
33 |
|
return self::$instance;
|
83
|
|
|
|
84
|
|
|
return self::$instance = new self;
|
85
|
|
|
}
|
86
|
|
|
}
|
87
|
|
|
|
88
|
|
|
mb_internal_encoding("UTF-8");
|
89
|
|
|
mb_http_output("UTF-8" );
|
90
|
|
|
$globalConfig = GlobalConfig::instance(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.