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: 
<?php
namespace Omeka\Installation\Task;

use Omeka\Installation\Installer;

/**
 * Check environment task.
 */
class CheckEnvironmentTask implements TaskInterface
{
    const PHP_MINIMUM_VERSION = '5.6';

    public static $requiredExtensions = [
        'PDO',
        'pdo_mysql',
        'xml',
    ];

    public function perform(Installer $installer)
    {
        if (version_compare(PHP_VERSION, self::PHP_MINIMUM_VERSION, '<')) {
            $installer->addError(sprintf(
                'The installed PHP version (%1$s) is too low. Omeka requires at least version %2$s',
                PHP_VERSION,
                self::PHP_MINIMUM_VERSION
            ));
        }

        foreach (self::$requiredExtensions as $ext) {
            if (!extension_loaded($ext)) {
                $installer->addError(sprintf(
                    'Omeka requires the PHP extension %s, and it is not loaded.',
                    $ext
                ));
            }
        }

        $this->testRandomGeneration();
    }

    /**
     * Test if we can successfully generate random data. If not, refuse to install.
     */
    protected function testRandomGeneration()
    {
        try {
            random_bytes(32);
        } catch (\Exception $e) {
            $installer->addError('Omeka is unable to securely generate random numbers.');
        }
    }
}