|
9 | 9 | use Eghamat24\DatabaseRepository\Commands\MakeRedisRepository; |
10 | 10 | use Illuminate\Support\Str; |
11 | 11 |
|
12 | | - |
13 | 12 | class CreatorRepository implements IClassCreator |
14 | 13 | { |
15 | 14 | public function __construct( |
@@ -39,28 +38,37 @@ private function writeFunction(string $functionStub, string $functionName, strin |
39 | 38 | { |
40 | 39 | $columnNameSingle = Str::camel($columnName); |
41 | 40 |
|
| 41 | + $returnResult = ''; |
| 42 | + $functionReturnType = ''; |
| 43 | + |
42 | 44 | if ($functionName === 'getOneBy') { |
43 | 45 | $functionReturnType = 'null|{{ EntityName }}'; |
44 | 46 | $functionName .= ucfirst(Str::camel($columnName)); |
45 | 47 | $columnName = Str::camel($columnName); |
46 | 48 | $redisCashFunction = $this->getRedisCashFunctionGetOneBy($this->strategyName); |
| 49 | + $returnResult = 'return $entity;'; |
47 | 50 | } elseif ($functionName === 'getAllBy') { |
48 | 51 | $functionReturnType = 'Collection'; |
49 | 52 | $functionName .= ucfirst(Str::plural(Str::camel($columnName))); |
50 | 53 | $columnName = Str::plural(Str::camel($columnName)); |
51 | 54 | $redisCashFunction = $this->getRedisCashFunctionGetAllBy($this->strategyName); |
| 55 | + $returnResult = 'return $entities;'; |
52 | 56 | } elseif ($functionName === 'create') { |
53 | 57 | $functionReturnType = $attributeType; |
54 | 58 | $redisCashFunction = $this->getRedisCashFunctionCreate($this->strategyName); |
| 59 | + $returnResult = 'return $this->{{ SqlRepositoryVariable }}->{{ FunctionName }}(${{ AttributeName }});'; |
55 | 60 | } elseif (in_array($functionName, ['update', 'remove', 'restore'])) { |
56 | 61 | $functionReturnType = 'int'; |
57 | 62 | $redisCashFunction = $this->getRedisCashFunctionUpdate($this->strategyName); |
| 63 | + $returnResult = 'return $this->{{ SqlRepositoryVariable }}->{{ FunctionName }}(${{ AttributeName }});'; |
58 | 64 | } |
59 | 65 |
|
60 | 66 | $redisCashFunction = str_replace(['{{ FunctionName }}', '{{ ColumnName }}', '{{ ColumnNameSingle }}'], [$functionName, $columnName, $columnNameSingle], $redisCashFunction); |
61 | 67 |
|
62 | | - return str_replace(['{{ FunctionName }}', '{{ AttributeType }}', '{{ AttributeName }}', '{{ FunctionReturnType }}', '{{redisFunction}}'], |
63 | | - [$functionName, $attributeType, Str::camel($columnName), $functionReturnType, $redisCashFunction], |
| 68 | + $returnResult = str_replace(['{{ SqlRepositoryVariable }}', '{{ FunctionName }}', '{{ AttributeName }}'], [$this->sqlRepositoryVariable, $functionName, Str::camel($columnName)], $returnResult); |
| 69 | + |
| 70 | + return str_replace(['{{ FunctionName }}', '{{ AttributeType }}', '{{ AttributeName }}', '{{ FunctionReturnType }}', '{{redisFunction}}', '{{returnResult}}'], |
| 71 | + [$functionName, $attributeType, Str::camel($columnName), $functionReturnType, $redisCashFunction, $returnResult], |
64 | 72 | $functionStub); |
65 | 73 | } |
66 | 74 |
|
|
0 commit comments