-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
165 lines (144 loc) · 5.78 KB
/
index.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
session_start();
require __DIR__ . '/vendor/autoload.php';
use Rosie\Config\DatabaseConnection;
use Rosie\Controllers\Breadcrumbs;
use Rosie\Controllers\Head;
use Rosie\Controllers\Footer;
use Rosie\Controllers\NavigationItemsForDifferentScreenSizes;
use Rosie\Controllers\PageNotFoundContent;
use Rosie\Controllers\PayPalTransactionErrorContent;
use Rosie\Services\Basket\AddingProductBasket;
use Rosie\Services\Basket\BasketDatabase;
use Rosie\Services\Basket\BasketDatabaseDataPreparation;
use Rosie\Services\Basket\BasketFullContent;
use Rosie\Services\Basket\RemovingProductBasket;
use Rosie\Services\Basket\UpdatingProductQtyViaDropDownInBasket;
use Rosie\Services\Contact\ContactFormDatabase;
use Rosie\Services\Contact\ContactFormDatabaseDataPreparation;
use Rosie\Services\Contact\ContactFormErrors;
use Rosie\Services\Contact\ContactFormFields;
use Rosie\Services\Contact\ContactFormSubmission;
use Rosie\Services\Contact\ContactFormValidation;
use Rosie\Services\ContentDatabaseQuery\ContentDatabaseQuery;
use Rosie\Services\PurchaseCompleted\PurchaseCompleted;
use Rosie\Utils\RetailPrices;
use Rosie\Utils\ContentSecurityPolicy;
use Rosie\Utils\EnvironmentVariables;
use Rosie\Utils\FormValidation;
use Rosie\Utils\Logging;
use Rosie\Utils\NameOfClass;
use Rosie\Utils\NewLogger;
use Rosie\Utils\RequestMethod;
use Rosie\Utils\Token;
use Rosie\Utils\TokenValidation;
use Rosie\Utils\UserId;
if (PageNotFoundContent::showPageNotFoundInfo()) {
return;
}
if (PayPalTransactionErrorContent::showPayPalTransactionErrorInfo()) {
return;
}
EnvironmentVariables::getEnvVars();
$newLogger = new NewLogger();
$userId = new UserId();
$token = new Token(
new Logging($newLogger->injectNewLogger('Token'), $userId)
);
$databaseConnection = new DatabaseConnection(
new Logging($newLogger->injectNewLogger('DatabaseConnection'), $userId)
);
$databaseConnection = $databaseConnection->connectToDb();
$contentSecurityPolicy = new ContentSecurityPolicy($token);
$contentSecurityPolicy->setContentSecurityPolicyHeader();
$formValidation = new FormValidation(
new Logging($newLogger->injectNewLogger('FormValidation'), $userId),
new RequestMethod(),
new TokenValidation()
);
// Contact Form
$contactFormFields = new ContactFormFields();
$contactFormErrors = new ContactFormErrors($contactFormFields);
$contactFormValidation = new ContactFormValidation(
new Logging($newLogger->injectNewLogger('ContactFormValidation'), $userId),
$formValidation,
$contactFormErrors,
$contactFormFields
);
$contactFormSubmission = new ContactFormSubmission(
new Logging($newLogger->injectNewLogger('ContactFormSubmission'), $userId),
$contactFormFields
);
$contactFormDatabase = new ContactFormDatabase(
$databaseConnection,
new Logging($newLogger->injectNewLogger('ContactFormDatabase'), $userId),
new ContactFormDatabaseDataPreparation($contactFormFields),
$userId
);
// Basket
$clientId = EnvironmentVariables::$payPalClientId;
$_SESSION['productsRetailPrices'] = RetailPrices::getRetailPrices();
$addingProductBasket = new AddingProductBasket(
new Logging($newLogger->injectNewLogger('AddingProductBasket'), $userId),
$formValidation
);
$removingProductBasket = new RemovingProductBasket(
new Logging($newLogger->injectNewLogger('RemovingProductBasket'), $userId)
);
$updatingProductQtyViaDropDownInBasket = new UpdatingProductQtyViaDropDownInBasket(
new Logging($newLogger->injectNewLogger('UpdatingProductQtyViaDropDownInBasket'), $userId),
$formValidation
);
$basketDatabase = new BasketDatabase(
$databaseConnection,
new BasketDatabaseDataPreparation(),
new Logging($newLogger->injectNewLogger('BasketDatabase'), $userId),
$userId
);
// Services injected into controllers via dependencies containers.
// Below logic needs to run before parts of a page are inserted.
$containerDependencies = [
'ArtworkDepCont' => [new ContentDatabaseQuery($databaseConnection)],
'AboutDepCont' => [new ContentDatabaseQuery($databaseConnection)],
'ContactDepCont' => [
new ContentDatabaseQuery($databaseConnection),
$token,
$contactFormValidation,
$contactFormSubmission,
$contactFormDatabase
],
'ShopDepCont' => [
new ContentDatabaseQuery($databaseConnection),
$token
],
'BasketDepCont' => [
$addingProductBasket,
$removingProductBasket,
$updatingProductQtyViaDropDownInBasket,
$basketDatabase,
new BasketFullContent($token)
],
'PurchaseCompletedDepCont' => [new PurchaseCompleted()],
'CaptureTransactionErrorDepCont' => []
];
$dependenciesContainerClassName = NameOfClass::getClassName($instance = null);
$dependenciesContainer = "Rosie\\DependenciesContainers\\$dependenciesContainerClassName";
$dependenciesContainerInstance = new $dependenciesContainer(...$containerDependencies[$dependenciesContainerClassName]);
$dependenciesContainerInstance->runDependencies();
Head::getHead();
$navigationItemsForDifferentScreenSizes = new NavigationItemsForDifferentScreenSizes($databaseConnection);
$navigationItemsForDifferentScreenSizes->getNavigationItemsForDifferentScreenSizes();
Breadcrumbs::getBreadcrumbs();
$contentControllerDependencies = [
'Artwork' => [$dependenciesContainerInstance],
'About' => [$dependenciesContainerInstance],
'Contact' => [$dependenciesContainerInstance],
'Shop' => [$dependenciesContainerInstance],
'Basket' => [$dependenciesContainerInstance],
'PurchaseCompleted' => [$dependenciesContainerInstance]
];
$contentControllerClassName = NameOfClass::getClassName($instance = 'controller');
$contentController = "Rosie\\Controllers\\$contentControllerClassName";
$contentControllerInstance = new $contentController(...$contentControllerDependencies[$contentControllerClassName]);
$contentControllerInstance->runPage();
Footer::getFooter();