PHP code example of inanepain / inane

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

    

inanepain / inane example snippets


'factories' => [
    'LogService' => function ($sm) {
        $logger = new Logger();
        $priority = new Priority(getenv('LOG_LEVEL') ?: $logger::WARN);

        $fileWriterGeneral = new Stream('log/general.log');

        $dbWriter = new Db(GlobalAdapterFeature::getStaticAdapter(), 'logs');
        $dbWriter->setFormatter(new \Laminas\Log\Formatter\Db('Y-m-d H:i:s'));

        $fileWriterGeneral->addFilter($priority);
        $dbWriter->addFilter($priority);

        $logger->addWriter($fileWriterGeneral);
        $logger->addWriter($dbWriter);

        return $logger;
    },
]

/**
 * Dumper shortcut
 *
 * @param mixed $data
 * @param string|null $label
 * @param array $options
 *
 * @return \Inane\Debug\Dumper
 */
function dd(mixed $data = null, ?string $label = null, array $options = []): \Inane\Debug\Dumper {
    return \Inane\Debug\Dumper::dump($data, $label, $options);
}

$var1 = someFunction();
$var2 = another($var1);
$var3 = again($var1);

dd($var1, 'someFunction')($var2, 'another')($var3, 'again');


// some central place: config.php
define('DUMPER_SILENCE_CLASS', false);
define('DUMPER_SILENCE_METHOD', true);

// IndexDemo.php
#[Silence(DUMPER_SILENCE_CLASS)]
class IndexDemo {
    protected function logSilence(): void {
		dd(DUMPER_SILENCE_CLASS, 'This WILL show since DUMPER_SILENCE_CLASS == false');
	}

    #[Silence(DUMPER_SILENCE_METHOD)]
	public function indexAction() {
		$this->logSilence();
        dd(DUMPER_SILENCE_METHOD, 'This will NOT show since DUMPER_SILENCE_METHOD == true');
    }
}
shell
php composer.phar 
shell
php composer.phar update