1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
function _d( $string ) { |
4
|
|
|
die($string); |
|
|
|
|
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
if (!extension_loaded('phalcon')) { |
8
|
|
|
_d('Phalcon extension isn\'t installed. Please follow these instructions to install it: http://docs.phalconphp.com/en/latest/reference/install.html'); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
function _if( $path, $name ) { |
12
|
|
|
$filePath = $path.'/'.(ENVIROMENT == '' ? '' : ENVIROMENT.'/').$name; |
13
|
|
|
if ( !is_file($filePath) ) |
14
|
|
|
$filePath = $path.'/'.$name; |
15
|
|
|
return $filePath; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
|-------------------------------------------------------------------------- |
20
|
|
|
| Define Paths |
21
|
|
|
|-------------------------------------------------------------------------- |
22
|
|
|
| |
23
|
|
|
| I defined some path which can be called anywhere. Root, Solution, |
24
|
|
|
| Public, | Vendor, Apps and Application path is defined here. |
25
|
|
|
| |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
define("ROOT_PATH", realpath( __DIR__."/../") ); |
29
|
|
|
|
30
|
|
|
$pathConfigs = new \Phalcon\Config( |
31
|
|
|
include_once __DIR__."/paths.php" |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
define("SOLUTION_PATH", $pathConfigs->solution_path ); |
35
|
|
|
define("STORAGE_PATH", $pathConfigs->storage_path ); |
36
|
|
|
define("PUBLIC_PATH", $pathConfigs->public_path ); |
37
|
|
|
define("VENDOR_PATH", $pathConfigs->vendor_path ); |
38
|
|
|
define("GLOBAL_CONFIG_PATH", $pathConfigs->global_config_path ); |
39
|
|
|
|
40
|
|
|
/* |
41
|
|
|
|-------------------------------------------------------------------------- |
42
|
|
|
| Define Application |
43
|
|
|
|-------------------------------------------------------------------------- |
44
|
|
|
| |
45
|
|
|
| I define which application is running by using server/console parameters. |
46
|
|
|
| |
47
|
|
|
*/ |
48
|
|
|
|
49
|
|
|
$solutionRouting = new \Phalcon\Config( |
50
|
|
|
include_once GLOBAL_CONFIG_PATH."routing.php" |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$configurationName = null; |
54
|
|
|
if (PHP_SAPI === 'cli') { |
55
|
|
|
if ( isset( $_SERVER['argv'][1] ) AND strpos($argv[1], "@") !== FALSE ) { |
56
|
|
|
$arguments = explode("@", $argv[1]); |
57
|
|
|
$configurationName = $arguments[0]; |
58
|
|
|
} |
59
|
|
|
} else { |
60
|
|
|
if ( isset( $_SERVER['SERVER_NAME'] ) ) { |
61
|
|
|
$configurationName = $_SERVER['SERVER_NAME']; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ( !isset($solutionRouting->routing->$configurationName->name) ) { |
66
|
|
|
if ( isset( $solutionRouting->routing->default->name ) ) { |
67
|
|
|
$applicationName = $solutionRouting->routing->default->name; |
68
|
|
|
$enviromentName = ""; |
69
|
|
|
if ( isset($solutionRouting->routing->default->enviroment) ) { |
70
|
|
|
$enviromentName = $solutionRouting->routing->default->enviroment; |
71
|
|
|
} |
72
|
|
|
} else { |
73
|
|
|
_d("Solution routing configuration is failed. Please check your application route configurations"); |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
|
|
$applicationName = $solutionRouting->routing->$configurationName->name; |
77
|
|
|
$enviromentName = ""; |
78
|
|
|
if ( isset($solutionRouting->routing->$configurationName->enviroment) ) { |
79
|
|
|
$enviromentName = $solutionRouting->routing->$configurationName->enviroment; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
define("ENVIROMENT", $enviromentName); |
84
|
|
|
define("APPLICATION_NAME", $applicationName); |
85
|
|
|
define("APPLICATION_PATH", $pathConfigs->solution_path.APPLICATION_NAME."/" ); |
86
|
|
|
|
87
|
|
|
if ( !is_dir( APPLICATION_PATH ) ) |
88
|
|
|
_d("There is no application called \"".APPLICATION_NAME."\" in your apps folder."); |
89
|
|
|
|
90
|
|
|
/* |
91
|
|
|
|-------------------------------------------------------------------------- |
92
|
|
|
| Register The Composer Auto Loader |
93
|
|
|
|-------------------------------------------------------------------------- |
94
|
|
|
| |
95
|
|
|
| Composer provides a convenient, automatically generated class loader |
96
|
|
|
| for our application. We just need to utilize it! We'll require it |
97
|
|
|
| into the script here so that we do not have to worry about the |
98
|
|
|
| loading of any our classes "manually". Feels great to relax. |
99
|
|
|
*/ |
100
|
|
|
|
101
|
|
|
if ( !is_file( VENDOR_PATH.'autoload.php' ) ) { |
102
|
|
|
_d("There is no autoload.php in your \"".VENDOR_PATH."\". Please update your vendor folder."); |
103
|
|
|
} else { |
104
|
|
|
require VENDOR_PATH.'autoload.php'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/* |
108
|
|
|
|-------------------------------------------------------------------------- |
109
|
|
|
| Di Services |
110
|
|
|
|-------------------------------------------------------------------------- |
111
|
|
|
| Phalcon\Di is a component that implements Dependency Injection/Service |
112
|
|
|
| Location of services and it”s itself a container for them. |
113
|
|
|
*/ |
114
|
|
|
|
115
|
|
|
include_once __DIR__."/services.php"; |
116
|
|
|
include_once APPLICATION_PATH."/application.php"; |
117
|
|
|
|
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.