-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.php
129 lines (111 loc) · 2.63 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Bootstrap the project
*
* PHP version 5.5
*
* @author Pieter Hordijk <[email protected]>
* @copyright Copyright (c) 2013 Pieter Hordijk <https://github.com/PeeHaa>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 1.0.0
*/
use Feedr\Storage\Session;
use Feedr\Security\Generator\Factory;
use Feedr\Security\CsrfToken;
use Feedr\Storage\Database\Auth;
use Feedr\Auth\User;
use Feedr\Storage\ImmutableArray;
use Feedr\Network\Http\Request;
use Feedr\Router\Factory as RouterFactory;
use Feedr\Presentation\Html;
use Feedr\Presentation\Xml;
use Feedr\Router\NotFoundException;
use OAuth\ServiceFactory;
use OAuth\Common\Http\Uri\UriFactory;
use OAuth\Common\Storage\Session as OauthSession;
use OAuth\Common\Consumer\Credentials;
/**
* Autoload composer dependencies
*/
require __DIR__ . '/vendor/autoload.php';
/**
* Bootstrap the library
*/
require_once __DIR__ . '/src/Feedr/bootstrap.php';
/**
* Setup the environment
*/
require_once __DIR__ . '/init.deployment.php';
/**
* Start the session
*/
session_start();
/**
* Setup CSRF token
*/
$sessionStorage = new Session();
$csrfToken = new CsrfToken($sessionStorage, new Factory());
/**
* Setup the GitHub service
*/
$serviceFactory = new ServiceFactory();
$storage = new OauthSession();
/**
* Return when on CLI
*/
if (php_sapi_name() === 'cli') {
return;
}
/**
* Request access token
*/
$uriFactory = new UriFactory();
$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
$currentUri->setQuery('');
$credentials = new Credentials(
$githubCredentials['key'],
$githubCredentials['secret'],
$currentUri->getAbsoluteUri()
);
$github = $serviceFactory->createService('GitHub', $credentials, $storage, array());
/**
* Setup the authentication object
*/
$user = new User($sessionStorage, new Auth($dbConnection));
/**
* Setup the HTML template renderer
*/
$htmlTemplate = new Html(__DIR__ . '/templates', 'page.phtml');
/**
* Setup the XML template renderer
*/
$xmlTemplate = new Xml(__DIR__ . '/templates');
/**
* Setup the request object
*/
$request = new Request(
new ImmutableArray([]),
new ImmutableArray($_GET),
new ImmutableArray($_POST),
new ImmutableArray($_SERVER),
new ImmutableArray($_FILES),
new ImmutableArray($_COOKIE)
);
/**
* Setup the router
*/
$router = (new RouterFactory())->build();
/**
* Load the routes
*/
require_once __DIR__ . '/routes.php';
/**
* Dispatch the request
*/
try {
$route = $router->getRoute($request);
$callback = $route->getCallback();
echo $callback($route);
} catch(NotFoundException $e) {
echo '404';
}