When calling values, it doesn't use the given name of class-based features when the key given is the class name.
app/Features/FooBar.php
<?php
namespace App\Features;
class FooBar
{
public string $name = 'foobar';
public function resolve(mixed $value): bool
{
return true;
}
}
Usage
use App\Features\Foobar;
use Laravel\Pennant\Feature;
// ...
Feature::define(Foobar::class);
Feature::active('foobar'); // true, as expected
Feature::values([ 'foobar' ]); // [ 'foobar' => true ], as expected
Feature::values([ Foobar::class ]); // [ 'App\Features\Foobar' => true ], I would rather this use the given name, 'foobar'
My use case is that I want to use Foobar::class internally. It's easier for other members of the team to quickly jump to the feature and see what it is. However, I also want to dump a whole lot of features out into an API, so the frontend can ingest it, and I want a simpler name to be used there.
A workaround on my end could be to make $name get it's value from a const, and use that const in values
class FooBar
{
public const NAME = 'foobar';
public string $name = self::NAME;
public function resolve(mixed $value): bool
{
return true;
}
}
Feature::define(Foobar::class);
Feature::values([ Foobar::NAME ]); // [ 'foobar' => true ]
But it feels to me that it maybe shouldn't work this way. I'm not sure if it's a bug.
When calling
values
, it doesn't use the given name of class-based features when the key given is the class name.app/Features/FooBar.php
Usage
My use case is that I want to use Foobar::class internally. It's easier for other members of the team to quickly jump to the feature and see what it is. However, I also want to dump a whole lot of features out into an API, so the frontend can ingest it, and I want a simpler name to be used there.
A workaround on my end could be to make $name get it's value from a const, and use that const in values
But it feels to me that it maybe shouldn't work this way. I'm not sure if it's a bug.