PHP code example of krisanalfa / b-comp

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

    

krisanalfa / b-comp example snippets


'bono.providers' => array(
    'BComp\\Provider\\LogProvider' => array(
        'log.name' => 'My Awesome App',
    ),
),

$log = App::getInstance()->log;

// Usage $log->{logLevel}($message, array $context = array());

$log->emergency('Foo', ['foo' => 'bar']);
$log->alert('Foo', ['foo' => 'bar']);
$log->critical('Foo', ['foo' => 'bar']);
$log->error('Foo', ['foo' => 'bar']);
$log->warn('Foo', ['foo' => 'bar']);
$log->notice('Foo', ['foo' => 'bar']);
$log->info('Foo', ['foo' => 'bar']);
$log->debug('Foo', ['foo' => 'bar']);

'bono.providers' => array(
    'BComp\\Provider\\VersionProvider' => array(
        // Enter the team hostnames computer here
        'local' => array(
            'farid.macbook',
            'ali.macbook',
            'alfa.macbook',
        ),

        // Enter the remote hostnames computer here
        'remote' => array(
            'semut',
            'lebah',
            'cicak',
        ),
    ),
),

use Bono\App;

// Create bulb application
$app = new App(
    array(
        // Should application autostart after construction?
        'autorun'    => false,

        // The mode of application
        'mode'       => 'development',

        // Enable Slim debug
        'debug'      => true,

        // Enable Bono debug
        'bono.debug' => true,
    )
);

$app->run();

use BComp\Helper\Arr as A;

$array = [
    'name' => 'Alfa',
    'sex' => 'Male',
    'age' => 23,
];

A::except($array, ['sex']); // hasilnya ['name' => 'Alfa', 'sex' => 'Male']
A::isEmpty($array); // hasilnya false
A::isEmpty(['name' => '', 'age' => '']); // hasilnya true
A::only($array, ['name']); // hasilnya ['name' => 'Alfa']

$multi = [
    ':type_address'     => 'Foo',
    ':type_citizenship' => 'Bar',
    ':type_city'        => 'Baz',
    ':type_country'     => 'Qux',
];

A::replaceKey($multi, ':type', 'user');
// Hasilnya
// $array = [
//     'user_address'     => 'Foo',
//     'user_citizenship' => 'Bar',
//     'user_city'        => 'Baz',
//     'user_country'     => 'Qux',
// ]

$header = [
    ':type_address',
    ':type_citizenship',
    ':type_city',
    ':type_country',
];

A::replaceValue($header, ':type_', '');

// Hasilnya
// $header = [
//     'address',
//     'citizenship',
//     'city',
//     'country',
// ];

A::depth($multi); // hasilnya 2
A::depth($header); // hasilnya 1


use BComp\Helper\Str as S;

S::camel("my_method") // "myMethod"
S::contains('my_method', 'x'); // false
S::contains('my_method', 'd'); // true
S::contains('my_method', ['x', 'd']); // true
S::endsWith('my_method', 'd'); // true
S::endsWith('my_method', 'x'); // false
S::endsWith('my_method', ['x', 'd']); // true
S::is('*.php', 'myFile.php'); // true
S::is('php', 'myFile.php'); // false
S::is('*.php', 'myFile.php'); // true
S::is('php', 'myFile.php'); // false

S::limit("You see me because you haven't overriden templates yet or default routes. May be this is your fist journey through the world of Bono. I wish you will enjoy and get comfy to the world of productive application development.");
// output: "You see me because you haven't overriden templates yet or default routes. May be this is your fist j..."

S::words("You see me because you haven't overriden templates yet or default routes. May be this is your fist journey through the world of Bono. I wish you will enjoy and get comfy to the world of productive application development.", 10));
// output: "You see me because you haven't overriden templates yet or..."

S::parseCallback('Class@methodName', 'defaultMethod'); // ["Class", "methodName"]
S::parseCallback('ClassName', 'defaultMethod'); // ["ClassName", "defaultMethod"]
S::title('this is a title'); // "This Is A Title"
S::slug('mr. ganesha, this is a title'); // "mr-ganesha-this-is-a-title"
S::snake('theCamelCaseVariable'); // "the_camel_case_variable"
S::startsWith('theCamelCaseVariable', 't'); // true
S::startsWith('theCamelCaseVariable', 'z'); // false
S::startsWith('theCamelCaseVariable', ['t', 'z']); // true
S::studly('the_snake_case_class_name'); // "TheSnakeCaseClassName"