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