PHP code example of stubbles / values

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

    

stubbles / values example snippets


$filter = fn($value) => 303 === $value;
echo Result::of(303)->filter($filter)->value(); // displays 303
echo Result::of(313)->filter($filter)->value(); // displays nothing
echo Result::of(null)->filter($filter)->value(); // displays nothing

$mapper = fn($value) => 'Roland TB 303';
echo Result::of(303)->map($mapper)->value(); // displays "Roland TB 303"
echo Result::of(null)->map($mapper)->value(); // displays nothing

$default = 909;
echo Result::of(303)->whenNull($default)->value(); // displays 303
echo Result::of(null)->whenNull($default)->value(); // displays 909

$default = function() { return 909; };
echo Result::of(303)->applyWhenNull($default)->value(); // displays 303
echo Result::of(null)->applyWhenNull($default)->value(); // displays 909

$default = 'Roland TB 303';
echo Result::of('Roland 909')->whenEmpty($default)->value(); // displays Roland 909
echo Result::of('')->whenEmpty($default)->value(); // displays Roland TB 303

$default = fn() => 'Roland TB 303';
echo Result::of('Roland 909')->applyWhenEmpty($default)->value(); // displays Roland 909
echo Result::of('')->applyWhenEmpty($default)->value(); // displays Roland TB 303

Parse::toList("foo|bar|baz"); // results in ['foo', 'bar', 'baz']

Parse::toMap("foo:bar|baz"); // results in ['foo' => 'bar', 'baz']

$properties = Properties::fromString($propertyString);
$properties = Properties::fromFile('path/to/properties.ini');

[config]
cool.stuff = "Roland TB 303"
interesting = "Pink fluffy unicorns dancing on rainbows"

[other]
the.answer = 42
github = true

$answer = $properties->getValue('other', 'the.answer'); // $answer now has the value "42" of type string

$answer = $properties->parseInt('other', 'the.answer'); // $answer now has the value 42 of type int

$props = $resourceLoader->load('some/properties.ini');

$props = $resourceLoader->loadWith(
        'some/properties.ini',
        fn($path) => Properties::fromFile($path)
);