Skip to content

Commit 37216d3

Browse files
committed
updates
1 parent 5136023 commit 37216d3

File tree

12 files changed

+119
-35
lines changed

12 files changed

+119
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
vendor/*
2+
config/*.php
3+
!config/base.php
24
storage/cache/smarty/*
35
storage/cache/stash/*
46
storage/languages/*

bootstrap.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,43 @@
2323
/**
2424
* Load BASE config first
2525
*/
26-
include __DIR__ . '/config/base.php';
26+
require_once __DIR__ . '/config/base.php';
2727

2828
/**
2929
* Load AutoLoaders
3030
*/
31-
include __DIR__ . '/system/functions.php';
32-
include __DIR__ . '/system/autoload.php';
33-
include __DIR__ . '/vendor/autoload.php';
31+
require_once __DIR__ . '/system/functions.php';
32+
require_once __DIR__ . '/system/autoload.php';
33+
require_once __DIR__ . '/vendor/autoload.php';
3434

3535
/**
3636
* Load Dependency Injector Container (PHP-DI)
3737
*/
3838
$container = DI\ContainerBuilder::buildDevContainer();
3939

4040
/**
41-
* Load System Configs
41+
* Load System Config
4242
*/
43-
include __DIR__ . '/config/system.php';
44-
include __DIR__ . '/config/cache.php';
45-
include __DIR__ . '/config/database.php';
4643
$config = $container->get('System\Config');
4744

45+
/**
46+
* Load System Logger
47+
*/
48+
$logger = $container->get('System\Logger');
49+
4850
/**
4951
* Load Cache Library (Stash)
5052
*/
5153
$cachedriver = new Stash\Driver\FileSystem(['path'=>$config->cache['stash']['cachedir']]);
5254
$cache = new Stash\Pool($cachedriver);
5355

56+
5457
/**
5558
* Load Database
5659
* Create a new PDO connection to MySQL
5760
* Create a new static DB class object
5861
*/
59-
System\DB::$c = (new System\Database($config))->connect();
62+
System\DB::$c = (new System\Database($container))->connect();
6063

6164
/**
6265
* Load System Language
@@ -99,7 +102,7 @@
99102
/**
100103
* Cache Routes
101104
*/
102-
if ($config->system['cache_routes']) {
105+
if ($config->system['cache_routes']) {
103106
$item = $cache->getItem('routes');
104107
$routesData = $item->get();
105108
if ($item->isMiss()) {
@@ -121,15 +124,16 @@
121124
/**
122125
* Load Middlewares
123126
*/
124-
//Create a relay dispatcher and add some middlewares:
125127
use Psr7Middlewares\Middleware;
126128
$relay = new Relay\RelayBuilder();
127129

130+
//Create a relay dispatcher and add some middlewares
128131
$relaydispatcher = $relay->newInstance([
129132
Middleware::basePath(BASE_PATH),
130133
Middleware::trailingSlash(),
131134
Middleware::responseTime(),
132135
new System\Middlewares\LanguageDetect($language),
133136
new System\Middlewares\Phroute($dispatcher)
134137
]);
138+
135139
$response = $relaydispatcher($request, $response);

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/base.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/* BASE SETTINGS */
33
define('BASE_PATH',"/phreak"); // leave empty if not in subdir or "/phreak" for example subdir
4-
//define('BASE_URL',"http://localhost:8080".BASE_PATH);
54
define('BASE_URL',"http://".$_SERVER['HTTP_HOST'].BASE_PATH);
65
define('ROOT_DIR', dirname(__DIR__));

config/system.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
return [
66
'site_key'=>'put_your_encryption_key_here',
7-
'max_upload_size'=>'52428800', //filesize in bytes also depends on server settings inside php.ini (1MB=1048576bytes)
8-
'session_expire'=>'30', // session TTL (time to live) in minutes
7+
//filesize in bytes also depends on server settings inside php.ini (1MB=1048576bytes)
8+
'max_upload_size'=>'52428800',
9+
// session TTL (time to live) in minutes
10+
'session_expire'=>'30',
911
'websocket_server'=>'ws://127.0.0.1:12345',
1012
'cache_routes'=>true
1113
];

config/system.php.sample

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
2-
define('SITE_KEY','put_your_encryption_key_here');
3-
4-
/* BASE SETTINGS */
5-
define('BASE_PATH',"/phreak"); // leave empty if not in subdir or "/phreak" for example subdir
6-
//define('BASE_URL',"http://localhost:8080".BASE_PATH);
7-
define('BASE_URL',"http://".$_SERVER['HTTP_HOST'].BASE_PATH);
8-
define('ROOT_DIR', dirname(__DIR__));
9-
10-
/* OTHERS */
11-
// filesize in bytes also depends on server settings inside php.ini (1MB=1048576bytes)
12-
define('MAX_UPLOAD_SIZE','52428800');
13-
define('SESSION_EXPIRE','30'); // session TTL (time to live) in minutes
14-
define('WEBSOCKET_SERVER','ws://127.0.0.1:12345');
2+
/**
3+
* SYSTEM CONFIG
4+
*/
5+
return [
6+
'site_key'=>'put_your_encryption_key_here',
7+
//filesize in bytes also depends on server settings inside php.ini (1MB=1048576bytes)
8+
'max_upload_size'=>'52428800',
9+
// session TTL (time to live) in minutes
10+
'session_expire'=>'30',
11+
'websocket_server'=>'ws://127.0.0.1:12345',
12+
'cache_routes'=>true
13+
];

installer

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ echo "Copying sample configs...\n";
1818
copyFiles([
1919
"config/system.php.sample"=>"config/system.php",
2020
"config/cache.php.sample"=>"config/cache.php",
21-
"config/database.php.sample"=>"config/database.php",
2221
"config/modules.php.sample"=>"config/modules.php"
2322
]);
2423
echo "\nPhreak! has been successfuly installed!\n";

routes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/**
3+
* DEFAULT ROUTES
4+
*/
25

36
// Add default homepage route
47
$router->get('/', ['App\HomeController','showIndex']);
@@ -12,4 +15,4 @@
1215
]);
1316
$template->display('layout.tpl');
1417
});
15-
*/
18+
*/

system/Config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function __get($name) {
2626
}
2727

2828
public function build ($conf) {
29-
// echo "Building conf...<br/>";
3029
foreach ($this->configfiles as $cfgkey => $cfgfile) {
3130
if (is_readable($cfgfile)) {
3231
$conf[$cfgkey]=include($cfgfile);

system/Database.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22
namespace System;
3+
use DI\Container;
34

45
class Database {
5-
public function __construct (Config $conf) {
6-
$this->conf = $conf;
6+
public function __construct (Container $container) {
7+
$this->conf = $container->get('System\Config');
8+
$this->log = $container->get('System\Logger');
79
}
810

911
public function connect () {
12+
if ($this->conf->database) {
1013
/** Create a new PDO connection to MySQL **/
1114
try {
1215
$pdo = new \PDO(
@@ -24,9 +27,10 @@ public function connect () {
2427
$pdo->exec("SET CHARACTER_SET_CONNECTION=".$this->conf->database['mysql']['charset']);
2528
$pdo->exec("SET SQL_MODE = ''");
2629
} catch (\PDOException $err) {
27-
die('Unable to connect to database: ' . $err->getMessage());
30+
$this->log->write('system','error','Unable to connect to database: ' . $err->getMessage());
2831
}
2932

3033
return $pdo;
3134
}
35+
}
3236
}

0 commit comments

Comments
 (0)