1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* YAWIK |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution <http://cross-solution.de> |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Core; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Dotenv\Dotenv; |
14
|
|
|
use Zend\Mvc\Application as ZendApplication; |
15
|
|
|
use Zend\Stdlib\ArrayUtils; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Utility class |
19
|
|
|
* |
20
|
|
|
* @package Core |
21
|
|
|
* @since 0.32 |
22
|
|
|
*/ |
23
|
|
|
class Yawik |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public static $VERSION; |
|
|
|
|
26
|
|
|
|
27
|
|
|
public static function init() |
28
|
|
|
{ |
29
|
|
|
$env = getcwd().'/.env'; |
30
|
|
|
if (!is_file($env)) { |
31
|
|
|
$env = getcwd().'/.env.dist'; |
32
|
|
|
} |
33
|
|
|
if (is_file($env)) { |
34
|
|
|
$dotenv = new Dotenv(); |
35
|
|
|
$dotenv->load($env); |
36
|
|
|
} |
37
|
|
|
$isVendor = strpos(__FILE__, 'modules')!==false || strpos(__FILE__, 'vendor') !== false; |
38
|
|
|
$version = getenv('TRAVIS') || $isVendor ? "undefined":exec('git describe'); |
39
|
|
|
$branch = getenv('TRAVIS') || $isVendor ? "undefined":exec('git rev-parse --abbrev-ref HEAD', $output, $retVal); |
40
|
|
|
static::$VERSION = $version.'['.$branch.']'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get required modules for Yawik |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public static function getRequiredModules() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
'Zend\ServiceManager\Di', |
52
|
|
|
'Zend\Session', |
53
|
|
|
'Zend\Router', |
54
|
|
|
'Zend\Navigation', |
55
|
|
|
'Zend\I18n', |
56
|
|
|
'Zend\Filter', |
57
|
|
|
'Zend\InputFilter', |
58
|
|
|
'Zend\Form', |
59
|
|
|
'Zend\Validator', |
60
|
|
|
'Zend\Log', |
61
|
|
|
'Zend\Mvc\Plugin\Prg', |
62
|
|
|
'Zend\Mvc\Plugin\Identity', |
63
|
|
|
'Zend\Mvc\Plugin\FlashMessenger', |
64
|
|
|
'Zend\Mvc\I18n', |
65
|
|
|
'Zend\Mvc\Console', |
66
|
|
|
'Zend\Hydrator', |
67
|
|
|
'Zend\Serializer', |
68
|
|
|
'DoctrineModule', |
69
|
|
|
'DoctrineMongoODMModule', |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Generate modules to be loaded for Yawik application |
75
|
|
|
* |
76
|
|
|
* @param array $loadModules |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public static function generateModuleConfiguration($loadModules=[]) |
80
|
|
|
{ |
81
|
|
|
return ArrayUtils::merge( |
82
|
|
|
static::getRequiredModules(), |
83
|
|
|
$loadModules |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Run application |
89
|
|
|
* @param mixed|array $appConfig |
90
|
|
|
* |
91
|
|
|
* @param bool $run |
|
|
|
|
92
|
|
|
* @return bool|ZendApplication |
|
|
|
|
93
|
|
|
*/ |
94
|
|
|
public static function initApplication($appConfig = null) |
95
|
|
|
{ |
96
|
|
|
static::init(); |
97
|
|
|
if (is_string($appConfig) && is_file($appConfig)) { |
98
|
|
|
$appConfig = include $appConfig; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if (empty($appConfig)) { |
102
|
|
|
// Retrieve configuration |
103
|
|
|
$file = null; |
|
|
|
|
104
|
|
|
if (is_file($test = getcwd().'/test/config/config.php')) { |
105
|
|
|
$file = $test; |
106
|
|
|
} elseif (is_file($test = getcwd(). '/config/config.php')) { |
107
|
|
|
$file = $test; |
108
|
|
|
} elseif (is_file($test = __DIR__.'/../config/config.php')) { |
109
|
|
|
$file = $test; |
110
|
|
|
} elseif (is_file($test = __DIR__.'/../../../../config/config.php')) { |
111
|
|
|
$file = $test; |
112
|
|
|
} else { |
113
|
|
|
fwrite( |
114
|
|
|
STDERR, |
115
|
|
|
'You must set up the project dependencies, run the following commands:'.PHP_EOL. |
116
|
|
|
'curl -s http://getcomposer.org/installer | php'.PHP_EOL. |
117
|
|
|
'php composer.phar install'.PHP_EOL |
118
|
|
|
); |
119
|
|
|
exit(1); |
120
|
|
|
} |
121
|
|
|
$appConfig = include $file; |
122
|
|
|
} |
123
|
|
|
return ZendApplication::init($appConfig); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public static function runApplication($appConfig=null) |
127
|
|
|
{ |
128
|
|
|
ini_set('display_errors', true); |
129
|
|
|
ini_set('error_reporting', E_ALL | E_STRICT); |
130
|
|
|
|
131
|
|
|
date_default_timezone_set('Europe/Berlin'); |
132
|
|
|
|
133
|
|
|
if (!version_compare(PHP_VERSION, '5.6.0', 'ge')) { |
134
|
|
|
echo sprintf('<p>Sorry, YAWIK requires at least PHP 5.6.0 to run, but this server currently provides PHP %s</p>', PHP_VERSION); |
135
|
|
|
echo '<p>Please ask your servers\' administrator to install the proper PHP version.</p>'; |
136
|
|
|
exit; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if (php_sapi_name() == 'cli-server') { |
140
|
|
|
$parseUrl = parse_url(substr($_SERVER["REQUEST_URI"], 1)); |
141
|
|
|
$route = isset($parseUrl['path']) ? $parseUrl['path']:null; |
142
|
|
|
if (is_file(__DIR__ . '/' . $route)) { |
143
|
|
|
if (substr($route, -4) == ".php") { |
144
|
|
|
require __DIR__ . '/' . $route; // Include requested script files |
145
|
|
|
exit; |
146
|
|
|
} |
147
|
|
|
return false; // Serve file as is |
148
|
|
|
} else { // Fallback to index.php |
149
|
|
|
$_GET["q"] = $route; // Try to emulate the behaviour of a .htaccess here. |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
return static::initApplication($appConfig)->run(); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
Yawik::init(); |
157
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.