PHP code example of shalvah / clara

1. Go to this page and download the library: Download shalvah/clara 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/ */

    

shalvah / clara example snippets


$output = clara('myappname');

$output->info("Installing package");
$output->debug("Attempt 3 of 5");
$output->warn("The file does not exist.");
$output->error("Something went wrong!");
$output->success("Done. Go and be awesome.");

$output = clara('myappname', \Shalvah\Clara\Clara::MODE_LABELS);
// The default
$output = clara('myappname', \Shalvah\Clara\Clara::MODE_ICONS);

$output = clara('myappname', \Shalvah\Clara\Clara::MODE_ICONS, [
    'info' => 'blue',
]);

$isVerbose = $this->getFlag('verbose');

// If $isVerbose is true,
// Clara won't print or capture any debug logs
$app1 = clara('app1')->showDebugOutput($isVerbose); 
$app1->debug("App 1 - Output 1");

// You can also toggle debug output manually
$app1->hideDebugOutput();
$app1->debug("App 1 - Output 2");

$app1->showDebugOutput();
$app1->debug("App 1 - Output 3");

$output1 = clara('myapp1');
$output2 = clara('myapp2');

// Mute only output from "myapp1"
Clara::mute('myapp1');
// Won't be printed.
$output1->info("Installing package");

// Will be printed
$output2->info("Installing package");

Clara::mute(); // Mute all apps
Clara::unmute("myapp1"); // Unmute myapp1
Clara::unmute(); // Unmute all apps

// SHow only output from mymainapp
$output1 = clara('mymainapp')->only();

// This is equivalent to doing:
Clara::mute();
Clara::unmute('yourappname');

Clara::startCapturingOutput('myapp1'); // Clara will start capturing output from myapp1
$output1 = clara('myapp1');
$output1->warn("Going to fail");
$output1->error("Failed");

$capturedOutput = Clara::getCapturedOutput('myapp1');
// $capturedOutput = [
//   "⚠ <fg=yellow>Going to fail</>",
//   "✖ <fg=red>Failed</>",
// ]

Clara::stopCapturingOutput('myapp1');
Clara::clearCapturedOutput('myapp1'); // Will empty saved output


$this->clara = clara('myapp'
  ->showDebugOutput($this->option('verbose'))
  ->useOutput($this->output)
  ->only();