File size: 1,926 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

namespace Mautic\Middleware;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class VersionCheckMiddleware implements HttpKernelInterface, PrioritizedMiddlewareInterface
{
    public const PRIORITY = 10;

    /**
     * @var HttpKernelInterface
     */
    protected $app;

    /**
     * @var string
     */
    private $minimumPHPVersion;

    /**
     * @var string
     */
    private $maximumPHPVersion;

    public function __construct(HttpKernelInterface $app)
    {
        $this->app = $app;

        $metadata = json_decode(
            file_get_contents(__DIR__.'/../release_metadata.json'),
            true
        );

        $this->minimumPHPVersion = $metadata['minimum_php_version'];
        $this->maximumPHPVersion = $metadata['maximum_php_version'];
    }

    /**
     * Check Minimum / Maximum PHP versions.
     *
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true)
    {
        // Are we running the minimum version?
        if (version_compare(PHP_VERSION, $this->minimumPHPVersion, 'lt')) {
            return new Response('Your server does not meet the minimum PHP requirements. Mautic requires PHP version '.$this->minimumPHPVersion.' while your server has '.PHP_VERSION.'. Please contact your host to update your PHP installation.', 500);
        }

        // Are we running a version newer than what Mautic supports?
        if (version_compare(PHP_VERSION, $this->maximumPHPVersion, 'gt')) {
            return new Response('Mautic does not support PHP version '.PHP_VERSION.' at this time. To use Mautic, you will need to downgrade to an earlier version.', 500);
        }

        return $this->app->handle($request, $type, $catch);
    }

    public function getPriority()
    {
        return self::PRIORITY;
    }
}