PHP code example of moonspot / builder
1. Go to this page and download the library: Download moonspot/builder 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/ */
moonspot / builder example snippets
use Moonspot\Builder;
use Example\MyObject;
class MyBuilder extends Builder {
public function create(array|object $data): object {
// need an array to work with
if(is_object($data)) {
$data = (array)$data;
}
$obj = new MyObject();
// setValue handles nulls and isset issues
$this->setValue($obj, 'id', $data);
// setValue can also look for multiple keys
// If either name or description is set in the data array
// it will be set to name in the object.
$this->setValue($obj, 'name', $data, ['description'])
}
}
$object = MyBuilder::build([
'id' => 12345,
'name' => 'Some name',
]);