22
33declare (strict_types=1 );
44
5- namespace CalebDW \SqlEntities ;
5+ namespace CalebDW \SqlEntities \ Concerns ;
66
7+ use CalebDW \SqlEntities \Contracts \SqlEntity ;
78use Illuminate \Database \Connection ;
8- use Illuminate \Database \Query \Builder ;
99use Illuminate \Support \Str ;
10- use Stringable ;
10+ use Override ;
1111
12- abstract class SqlEntity implements Stringable
12+ /** @phpstan-require-implements SqlEntity */
13+ trait DefaultSqlEntityBehaviour
1314{
14- /** The entity definition . */
15- abstract public function definition (): Builder | string ;
15+ /** The connection name . */
16+ protected ? string $ connection = null ;
1617
1718 /** The entity name. */
19+ protected ?string $ name = null ;
20+
21+ #[Override]
1822 public function name (): string
1923 {
20- return Str::snake (class_basename ($ this ));
24+ return $ this -> name ?? Str::snake (class_basename ($ this ));
2125 }
2226
23- /** The entity connection name. */
27+ #[Override]
2428 public function connectionName (): ?string
2529 {
26- return null ;
30+ return $ this -> connection ;
2731 }
2832
29- /**
30- * Hook before creating the entity.
31- *
32- * @return bool true to create the entity, false to skip.
33- */
33+ #[Override]
3434 public function creating (Connection $ connection ): bool
3535 {
3636 return true ;
3737 }
3838
39- /** Hook after creating the entity. */
39+ #[Override]
4040 public function created (Connection $ connection ): void
4141 {
42+ return ;
4243 }
4344
44- /**
45- * Hook before dropping the entity.
46- *
47- * @return bool true to drop the entity, false to skip.
48- */
45+ #[Override]
4946 public function dropping (Connection $ connection ): bool
5047 {
5148 return true ;
5249 }
5350
54- /** Hook after dropping the entity. */
51+ #[Override]
5552 public function dropped (Connection $ connection ): void
5653 {
54+ return ;
5755 }
5856
57+ #[Override]
5958 public function toString (): string
6059 {
6160 $ definition = $ this ->definition ();
@@ -67,6 +66,7 @@ public function toString(): string
6766 return $ definition ->toRawSql ();
6867 }
6968
69+ #[Override]
7070 public function __toString (): string
7171 {
7272 return $ this ->toString ();
0 commit comments