PHP code example of lenderspender / substitute-class-binding
1. Go to this page and download the library: Download lenderspender/substitute-class-binding 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/ */
lenderspender / substitute-class-binding example snippets
declare(strict_types=1);
use LenderSpender\SubstituteClassBinding\Routing\UrlRoutable;
class Foo implements UrlRoutable
{
public $id = 1;
public function __construct(array $properties)
{
$this->id = $properties['id'];
}
public static function resolveRouteBinding($value)
{
return new Foo(['id' => $value]);
}
public function getRouteKey()
{
return $this->id;
}
public function getRouteKeyName() : string
{
return 'id';
}
}
Route::get('/foo/{foo}', function (Foo $foo) {
echo $foo->id; // 12345 when calling /foo/12345
});