<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
melchiorkokernoot / laravel-autowire-config example snippets
class Foo {
public function __construct(
#[Config('app.name')]
public string $myConfiguredAppName,
){}
}
return [
//Either AttributeStrategy::class or AutowiredPropNameStrategy::class
'strategy' => PropNameStrategy::class,
];
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__),
);
use MelchiorKokernoot\LaravelAutowireConfig\Application;
$app = new Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__),
);
class Foo {
public function __construct(
#[Config('app.name','default value')]
public string $myConfiguredAppName,
){}
}
class Foo implements AutowiresConfigs{
public function __construct(
#[StringConfig('app.name')]
public StringConfig $appName,
){}
}
$foo = new Foo(config('app.name'));
class Foo implements AutowiresConfigs{
public function __construct(
public StringConfig $appName,
){}
}
$foo = new Foo(config('app.name'));
class Foo implements AutowiresConfigs{
public function __construct(
public StringConfig $appName,
){}
public function bar(){
//Casting to string
(string) $this->appName
//Shorthand method call
$this->appName->value->v();
//Shorthand property access
$this->appName->value->v;
//Ordinary method call
return $this->appName->value();
}
}