PHP code example of philiprehberger / php-install-doctor

1. Go to this page and download the library: Download philiprehberger/php-install-doctor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

philiprehberger / php-install-doctor example snippets


use PhilipRehberger\InstallDoctor\Doctor;

$report = Doctor::diagnose();

if ($report->isHealthy()) {
    echo "All checks passed!\n";
} else {
    echo $report->toConsoleOutput();
}

use PhilipRehberger\InstallDoctor\Doctor;
use PhilipRehberger\InstallDoctor\Checks\PhpVersionCheck;
use PhilipRehberger\InstallDoctor\Checks\ExtensionCheck;
use PhilipRehberger\InstallDoctor\Checks\MemoryLimitCheck;
use PhilipRehberger\InstallDoctor\Checks\DirectoryWritableCheck;

$report = Doctor::check(
    new PhpVersionCheck('8.2.0'),
    new ExtensionCheck(['pdo', 'redis', 'imagick']),
    new MemoryLimitCheck(256),
    new DirectoryWritableCheck(['/tmp', '/var/log']),
);

echo $report->toConsoleOutput();

$report = Doctor::diagnose();
$data = $report->toArray();

// [
//     ['status' => 'pass', 'name' => 'PHP Version', 'message' => '...'],
//     ['status' => 'pass', 'name' => 'Extensions', 'message' => '...'],
//     ...
// ]

use PhilipRehberger\InstallDoctor\Contracts\Check;
use PhilipRehberger\InstallDoctor\CheckResult;

final class DatabaseConnectionCheck implements Check
{
    public function run(): CheckResult
    {
        try {
            new \PDO('mysql:host=localhost;dbname=app', 'root', '');
            return CheckResult::pass('Database', 'Connection successful');
        } catch (\PDOException $e) {
            return CheckResult::fail('Database', $e->getMessage());
        }
    }
}

$report = Doctor::check(
    new DatabaseConnectionCheck(),
);
bash
composer