Your IP : 216.73.216.79


Current Path : /var/www/html/caknatani/backend/modules/installer/helpers/
Upload File :
Current File : /var/www/html/caknatani/backend/modules/installer/helpers/SystemChecker.php

<?php

namespace backend\modules\installer\helpers;

use Yii;

/**
 * SystemChecker is a helper class which checks all dependencies of the application.
 *
 * @since  1.0
 * @author Awsaf Anam Chowdhury
 */
class SystemChecker
{
    /**
     * Get Results of the Application SystemChecker.
     *
     * Fields
     *  - title
     *  - state (OK, WARNING or ERROR)
     *  - hint
     *
     * @return Array
     */
    public static function getResults()
    {
        /**
         * ['title']
         * ['state']    = OK, WARNING, ERROR
         * ['hint']
         */
        $checks = [];

        // Checks PHP Version
        $title = 'PHP - Version - ' . PHP_VERSION;

        # && version_compare(PHP_VERSION, '5.9.0', '<')
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } elseif (version_compare(PHP_VERSION, '5.3.0', '<=')) {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Minimum 5.4'];
        }

        // PDO extension
        $title = 'PDO extension';
        if (extension_loaded('pdo')) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Install PDO Extension'];
        }

        // PDO MySQL extension
        $title = 'PDO MySQL extension';
        if (extension_loaded('pdo_mysql')) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Required by database'];
        }

        // Checks GD Extension
        $title = 'PHP - GD Extension';
        if (function_exists('gd_info')) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Install GD Extension'];
        }

        // PHP SMTP
        $title = 'PHP Mail SMTP';
        if (strlen(ini_get('SMTP')) > 0) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'WARNING', 'hint' => 'SMTP is required to send mails'];
        }

        // Checks Writable Config
        $title = 'Permissions - Config';
        $configFile = dirname(__DIR__ . DIRECTORY_SEPARATOR);
        if (is_writeable($configFile)) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Make ' . $configFile . " writable"];
        }

        // Check Runtime Directory
        $title = 'Permissions - Runtime';
        if (is_writable(Yii::$app->runtimePath)) {
            $checks[] = ['title' => $title, 'state' => 'OK'];
        } else {
            $checks[] = ['title' => $title, 'state' => 'ERROR', 'hint' => 'Make ' . Yii::$app->runtimePath . ' writable'];
        }

        return $checks;
    }
}