PHP code example of damian972 / options-bundle
1. Go to this page and download the library: Download damian972/options-bundle 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/ */
damian972 / options-bundle example snippets
// HelloController.php
use Damian972\OptionsBundle\Contracts\OptionsInterface;
use Damian972\OptionsBundle\Entity\Option;
...
// note: this example is tested with PHP 8
public function greeting(OptionsInterface $options): Response
{
$options->set(Option::make('greeting', 'World'));
// define a parent if you have multiple key with the same name
// will create an new entry with parent field "global"
$options->set(Option::make('greeting', 'World', 'global'));
// if you want to use a custom name
$options->set(Option::make('greeting', 'World')->setName('Greeting to the world'));
$greeting = 'Hello';
$greetingOpt = $options->get('greeting'); // or $options->get('greeting', 'global') if you want the entry with the parent "global"
if (null !== $greetingOpt) {
$greeting .= " {$greetingOpt}"; // or $greetingOpt->getValue();
} else {
$greeting .= ' John';
}
...
}