Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit b588d8f

Browse files
committed
refactor: upgrade to slim 4.X
BREAKING: support only php 8 and higher
1 parent 9d5e1d4 commit b588d8f

34 files changed

+2101
-1368
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
.idea/*
66
.idea/**
7-
composer.lock
8-
package-lock.json
7+
#composer.lock
8+
#package-lock.json
99
log/*
1010
log
1111

App/App.php

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Utils\ContainerBuilder;
66
use RKA\Middleware\IpAddress;
77

8-
class App extends \DI\Bridge\Slim\App
8+
class App
99
{
1010
/**
1111
* The absolute fs path of the root of the application
@@ -16,86 +16,6 @@ class App extends \DI\Bridge\Slim\App
1616

1717
public function __construct()
1818
{
19-
parent::__construct();
20-
21-
$this->add(new Middlewares\CorsMiddleware());
22-
23-
$this->get('/', [Controllers\PagesController::class, 'getHome']);
24-
$this->get('/ping', [Controllers\PagesController::class, 'getPing']);
25-
$this->map(['POST', 'OPTIONS'], '/newsletter/subscribe', [Controllers\NewsletterController::class, 'postSubscribe']);
26-
$this->get('/newsletter/event', [Controllers\NewsletterController::class, 'getEvent']);
27-
$this->post('/newsletter/event', [Controllers\NewsletterController::class, 'postEvent']);
28-
29-
$this->map(['POST', 'OPTIONS'], '/graphql', [Controllers\GraphQlController::class, 'newRequest'])
30-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
31-
32-
//Routes deprecated
33-
/*$this->get('/paysafecard/get_url', [Controllers\Payment\PaysafeCardController::class, 'getUrl']);
34-
$this->post('/paysafecard/capture_payment', [Controllers\Payment\PaysafeCardController::class, 'postCapturePayment']);
35-
$this->get('/paysafecard/success', [Controllers\Payment\PaysafeCardController::class, 'getSuccess']);
36-
$this->get('/paysafecard/failure', [Controllers\Payment\PaysafeCardController::class, 'getFailure']);*/
37-
38-
// STRIPE
39-
$this->map(['POST', 'OPTIONS'], '/stripe/create', [Controllers\Payment\StripeController::class, 'postCreateSession'])
40-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
41-
$this->map(['POST', 'OPTIONS'], '/stripe/execute', [Controllers\Payment\StripeController::class, 'postExecute']);
42-
43-
// PAYPAL
44-
$this->map(['POST', 'OPTIONS'], '/paypal/get-url', [Controllers\Payment\PaypalController::class, 'postGetUrl'])
45-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
46-
//$this->get('/paypal/execute', [Controllers\Payment\PaypalController::class, 'postExecute']);
47-
$this->map(['POST', 'OPTIONS'], '/paypal/execute', [Controllers\Payment\PaypalController::class, 'postExecute']);
48-
49-
$this->group('/account', function () {
50-
$this->get('/login', [Controllers\AccountController::class, 'getLogin']);
51-
$this->get('/register', [Controllers\AccountController::class, 'getLogin']);
52-
$this->get('/login-desktop', [Controllers\AccountController::class, 'getLoginDesktop']);
53-
$this->post('/login-desktop', [Controllers\AccountController::class, 'postLoginDesktop'])
54-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
55-
56-
$this->map(['GET', 'OPTIONS'], '/info', [Controllers\AccountController::class, 'getInfo'])
57-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
58-
59-
$this->map(['POST', 'OPTIONS'], '/execute', [Controllers\AccountController::class, 'execute'])
60-
->add(new IpAddress());
61-
});
62-
63-
$this->group('/dashboard', function () {
64-
$this->map(['GET', 'OPTIONS'], '[/]', [Controllers\DashboardController::class, 'getDashboard']);
65-
$this->map(['POST', 'OPTIONS'], '/upload', [Controllers\UploadController::class, 'postUpload']);
66-
$this->map(['GET', 'OPTIONS'], '/delete', [Controllers\DashboardController::class, 'getDelete']);
67-
})->add(new Middlewares\JWTMiddleware($this->getContainer()));
68-
69-
$this->group('/shop', function () {
70-
$this->get('/address', [Controllers\ShopController::class, 'getQueryAddress'])
71-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
72-
$this->get('/storage-prices', [Controllers\ShopController::class, 'getStoragePrices']);
73-
$this->get('/shipping-prices', [Controllers\ShopController::class, 'getShippingPrices']);
74-
$this->get('/{locale}/categories', [Controllers\ShopController::class, 'getCategories']);
75-
$this->get('/{locale}/item/{slug}', [Controllers\ShopController::class, 'getItem']);
76-
});
77-
78-
$this->post('/console/verify', [Controllers\ConsoleController::class, 'verifyConsole']);
79-
80-
$this->get('/downloads', [Controllers\DownloadController::class, 'getDownloads']);
81-
82-
$this->group('/docs', function () {
83-
$this->get('/{locale}/{slug}', [Controllers\DocsController::class, 'getPage']);
84-
});
85-
86-
$this->get('/cache/shop/generate', [Controllers\PagesController::class, 'generateShopCache'])
87-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
88-
$this->get('/websocket/connexions', [Controllers\PagesController::class, 'getWebSocketConnexions'])
89-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
90-
$this->get('/test-send-email-event', [Controllers\PagesController::class, 'testSendEmailEvent'])
91-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
92-
93-
$this->get('/countries/{locale}', [Controllers\CountriesController::class, 'getCountries']);
94-
95-
$this->get('/health', [Controllers\HealthController::class, 'getHealth']);
96-
$this->get('/dangerously-truncate-table', [Controllers\IntegrationTestController::class, 'getDangerouslyTruncateTables']);
97-
$this->get('/jwt', [Controllers\IntegrationTestController::class, 'getUserToken'])
98-
->add(new Middlewares\JWTMiddleware($this->getContainer()));
9919
}
10020

10121
protected function configureContainer(\DI\ContainerBuilder $builder)

App/Auth/Session.php

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -9,111 +9,111 @@
99
class Session
1010
{
1111

12-
/**
13-
* Raw JSON Web token sent by the client
14-
*
15-
* @var string
16-
*/
17-
private string $token;
12+
/**
13+
* Raw JSON Web token sent by the client
14+
*
15+
* @var string
16+
*/
17+
private string $token;
1818

19-
/**
20-
* Data decoded contained inside the JWT
21-
*
22-
* @var array
23-
*/
24-
private array $data;
19+
/**
20+
* Data decoded contained inside the JWT
21+
*
22+
* @var array
23+
*/
24+
private array $data;
2525

26-
/**
27-
* @var ContainerInterface
28-
*/
29-
private ContainerInterface $container;
26+
/**
27+
* @var ContainerInterface
28+
*/
29+
private ContainerInterface $container;
3030

31-
public function __construct(ContainerInterface $container)
32-
{
33-
$this->container = $container;
34-
}
31+
public function __construct(ContainerInterface $container)
32+
{
33+
$this->container = $container;
34+
}
3535

36-
/**
37-
* Create the session and return the JWT
38-
*
39-
* @param $user
40-
* @return string
41-
*/
42-
public function create($user) : string
43-
{
44-
return JWT::encode([
45-
'iss' => $this->container->get('app_name') . '._.' . $this->container->get('env_name'),
46-
'iat' => Carbon::now()->timestamp,
47-
'user' => $user
48-
], $this->container->get('jwt')['key']);
49-
}
36+
/**
37+
* Create the session and return the JWT
38+
*
39+
* @param $user
40+
* @return string
41+
*/
42+
public function create($user): string
43+
{
44+
return JWT::encode([
45+
'iss' => $this->container->get('app_name') . '._.' . $this->container->get('env_name'),
46+
'iat' => Carbon::now()->timestamp,
47+
'user' => $user
48+
], $this->container->get('jwt')['key']);
49+
}
5050

51-
/**
52-
* Return array about actual user logged in
53-
*
54-
* @return array
55-
*/
56-
public function getUser(): array
57-
{
58-
return $this->data['user'];
59-
}
51+
/**
52+
* Return array about actual user logged in
53+
*
54+
* @return array
55+
*/
56+
public function getUser(): array
57+
{
58+
return $this->data['user'];
59+
}
6060

61-
/**
62-
* Return session user id
63-
*
64-
* @return string
65-
*/
66-
public function getUserId(): string
67-
{
68-
if (isset($this->data['user']['id'])) {
69-
return $this->data['user']['id'];
70-
}
71-
return "";
61+
/**
62+
* Return session user id
63+
*
64+
* @return string
65+
*/
66+
public function getUserId(): string
67+
{
68+
if (isset($this->data['user']['id'])) {
69+
return $this->data['user']['id'];
7270
}
71+
return "";
72+
}
7373

74-
/**
75-
* Get the actual raw JWT
76-
*
77-
* @return string
78-
*/
79-
public function getToken(): string
80-
{
81-
return $this->token;
82-
}
74+
/**
75+
* Get the actual raw JWT
76+
*
77+
* @return string
78+
*/
79+
public function getToken(): string
80+
{
81+
return $this->token;
82+
}
8383

84-
/**
85-
* Set token payload for this session
86-
*
87-
* @param array $data
88-
*/
89-
public function setData(array $data)
90-
{
91-
$this->data = $data;
92-
}
84+
/**
85+
* Set token payload for this session
86+
*
87+
* @param array $data
88+
*/
89+
public function setData(array $data)
90+
{
91+
$this->data = $data;
92+
}
9393

94-
/**
95-
* Set raw JWT for this session
96-
*
97-
* @param string $token
98-
*/
99-
public function setToken(string $token)
100-
{
101-
$this->token = $token;
102-
}
94+
/**
95+
* Set raw JWT for this session
96+
*
97+
* @param string $token
98+
*/
99+
public function setToken(string $token)
100+
{
101+
$this->token = $token;
102+
}
103103

104-
/**
105-
* @return array
106-
*/
107-
public function getData(): array
108-
{
109-
return $this->data;
110-
}
104+
/**
105+
* @return array
106+
*/
107+
public function getData(): array
108+
{
109+
return $this->data;
110+
}
111111

112-
/**
113-
* @return boolean
114-
*/
115-
public function isAdmin(): bool
116-
{
117-
return (boolean)$this->data['user']['is_admin'];
118-
}
119-
}
112+
/**
113+
* @return boolean
114+
*/
115+
public function isAdmin(): bool
116+
{
117+
return (bool)$this->data['user']['is_admin'];
118+
}
119+
}

0 commit comments

Comments
 (0)