Skip to content

Commit

Permalink
🚧 work in prgoress
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Mar 17, 2022
1 parent bce3196 commit d7ed2b4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Opis\Closure\SerializableClosure;
use ReflectionClass;
use ReflectionMethod;
use ReflectionException;
Expand Down Expand Up @@ -273,6 +274,7 @@ private function getInterfaces(Model $model, array $columns, array $mutators, ar
* @param Model $model
* @return array
* @throws ReflectionException
* @throws Exception
*/
public function getMutators(Model $model): array
{
Expand All @@ -284,6 +286,14 @@ public function getMutators(Model $model): array

// If Model is using v9 Attributes
if ($returnType == 'Illuminate\Database\Eloquent\Casts\Attribute') {

/* TODO: figure out a way to get the returnType from a closure
if ($reflection->name === 'isCaptain') {
$closure = $reflection->getClosure($model)->getReturnType();
ray($closure);
}
*/

// Check to see if the Model has Custom interfaces & has the mutator set with its type
if (isset($model->attrs) && isset($model->attrs[$mutator])) {
$mutations[$mutator] = $model->attrs[$mutator];
Expand All @@ -297,9 +307,6 @@ public function getMutators(Model $model): array
$mutations[$mutator] = $model->attrs[$mutator];
continue;
}

$method = 'get' . $this->camelize($mutator) . 'Attribute';
$reflection = new ReflectionMethod($model, $method);
if (!$returnType) {
throw new Exception(
"Model for table {$model->getTable()} has no return type for mutator: {$mutator}"
Expand Down

0 comments on commit d7ed2b4

Please sign in to comment.