| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Core\Concern; |
| 4: | |
| 5: | use Salient\Contract\Core\Buildable; |
| 6: | use Salient\Contract\Core\BuilderInterface; |
| 7: | |
| 8: | /** |
| 9: | * @api |
| 10: | * |
| 11: | * @template TBuilder of BuilderInterface |
| 12: | * |
| 13: | * @phpstan-require-implements Buildable<TBuilder> |
| 14: | */ |
| 15: | trait BuildableTrait |
| 16: | { |
| 17: | /** |
| 18: | * Get the name of a builder for the class |
| 19: | * |
| 20: | * @return class-string<TBuilder> |
| 21: | */ |
| 22: | protected static function getBuilder(): string |
| 23: | { |
| 24: | return self::class . 'Builder'; |
| 25: | } |
| 26: | |
| 27: | /** |
| 28: | * @inheritDoc |
| 29: | */ |
| 30: | public static function build(): BuilderInterface |
| 31: | { |
| 32: | return static::getBuilder()::create(); |
| 33: | } |
| 34: | |
| 35: | /** |
| 36: | * @inheritDoc |
| 37: | */ |
| 38: | public static function resolve($object) |
| 39: | { |
| 40: | /** @var static */ |
| 41: | return static::getBuilder()::resolve($object); |
| 42: | } |
| 43: | } |
| 44: |