PHP code example of novara / base

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

    

novara / base example snippets


// $GLOBALS
Novara::Globals::GLOBALS();

// $_GET
Novara::Globals::GET();

// ...

Novara::Import::

Novara::Exception::throwIf(
    UserService::getUserName() !== 'admin',
    new Exception('This can\'t be right!'),
);

// This variable infested block:
$unnecessaryVariable = SomeService::getWhatever(); // Buffer to not call getWhatever() thrice
doAThing($unnecessaryVariable);
doAnotherThing($unnecessaryVariable);
if ($unnecessaryVariable > 100) {
    echo 'Wow!';
}

// becomes utter beauty:
Novara::Call::spread(
    SomeService::getWhatever(),
    doAThing(...),
    doAnotherThing(...),
    fn () => func_get_arg(0) > 100 && print 'Wow!',
);

Novara::Call::pass(
    MyService::calculateSomethingComplex('foo', 123, func_get_arg(0)),
    fn () => someFunction(func_get_arg(0)) ?: anotherFunction(func_get_arg(0)),
)

Novara::Call::args(
    [
        'name',
        'age',
    ],
    func_get_args(),
)->age === ...

// Reuse args through passing
return Novara::Call::pass(
    Novara::Call::args(
        [
            'name',
            'age',
        ],
        func_get_args(),
    ),
    fn () => 'Name: ' . func_get_arg(0)->name . '; Age: ' . func_get_arg(0)->age,
);

// Share the args through spreading
return Novara::Call::spread(
    Novara::Call::args(
        [
            'name',
            'age',
        ],
        func_get_args(),
    ),
    function () {
        ... func_get_arg(0)->name ...
    },
    function () {
        ... func_get_arg(0)->age ...
    },
);