PHP code example of imunew / laravel-value-objects
1. Go to this page and download the library: Download imunew/laravel-value-objects 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/ */
namespace App\ValueObjects;
use Imunew\Laravel\ValueObjects\ImmutableObject;
class Range extends ImmutableObject
{
/**
* Range constructor.
* @param int $start
* @param int $end
* @param int $step
*/
public function __construct(int $start, int $end, int $step = 1)
{
$this->setAttribute('start', $start);
$this->setAttribute('end', $end);
$this->setAttribute('step', $step);
}
/**
* @return array
*/
public function getRangeAttribute()
{
return range($this->start, $this->end, $this->step);
}
}
$range = new Range(1, 10);
echo $range;
// [1,2,3,4,5,6,7,8,9,10]
namespace App\ValueObjects;
use Imunew\Laravel\ValueObjects\ImmutableObject;
class DirectoryTree extends ImmutableObject
{
/**
* Range constructor.
* @param array $directoryTree
*/
public function __construct(array $directoryTree)
{
$this->attributes = $directoryTree;
}
}