1. Go to this page and download the library: Download illuminatech/array-factory 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/ */
illuminatech / array-factory example snippets
class Car
{
public $condition;
public $registrationNumber;
private $type = 'unknown';
private $color = 'unknown';
private $engineRunning = false;
public function __construct(string $condition)
{
$this->condition = $condition;
}
public function setType(string $type)
{
$this->type = $type;
}
public function getType(): string
{
return $this->type;
}
public function color(string $color): self
{
$this->color = $color;
return $this;
}
public function startEngine(): self
{
$this->engineRunning = true;
return $this;
}
}
/* @var $factory \Illuminatech\ArrayFactory\FactoryContract */
$car = $factory->make([
'__class' => Car::class, // class name
'__construct()' => ['condition' => 'good'], // constructor arguments
'registrationNumber' => 'AB1234', // set public field `Car::$registrationNumber`
'type' => 'sedan', // pass value to the setter `Car::setType()`
'color()' => ['red'], // pass arguments to the method `Car::color()`
'()' => function (Car $car) {
// final adjustments to be made after object creation and other config application:
$car->startEngine();
},
]);
namespace MyVendor\GeoLocation;
use Illuminate\Http\Request;
interface DetectorContract
{
public function detect(Request $request): LocationInfo;
}
namespace MyVendor\GeoLocation;
use Illuminatech\ArrayFactory\Factory;
use Illuminate\Support\ServiceProvider;
class DetectorServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(DetectorContract::class, function ($app) {
$factory = new Factory($app);
$factory->make(array_merge(
['__class' => DefaultDetector::class], // default config
$app->config->get('geoip', []) // developer defined config
));
});
}
}