From ec33c81aacccbb6fe3617c47945d258953bc6049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Fri, 4 Dec 2015 21:48:52 +0100 Subject: [PATCH] Removed unnecessary mapping factory behaviour for Eloquent Models --- .../JsonApi/Mapper/MappingFactory.php | 43 +------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/src/NilPortugues/Laravel5/JsonApi/Mapper/MappingFactory.php b/src/NilPortugues/Laravel5/JsonApi/Mapper/MappingFactory.php index 4fdf903..b024641 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Mapper/MappingFactory.php +++ b/src/NilPortugues/Laravel5/JsonApi/Mapper/MappingFactory.php @@ -10,11 +10,9 @@ namespace NilPortugues\Laravel5\JsonApi\Mapper; -use ErrorException; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Schema; use ReflectionClass; -use ReflectionMethod; /** * Class MappingFactory. @@ -38,10 +36,7 @@ protected static function getClassProperties($className) $value = $reflection->newInstanceWithoutConstructor(); if (\is_subclass_of($value, Model::class, true)) { - $attributes = \array_merge( - Schema::getColumnListing($value->getTable()), - self::getRelationshipMethodsAsPropertyName($value, $className, $reflection) - ); + $attributes = Schema::getColumnListing($value->getTable()); self::$eloquentClasses[$className] = $attributes; @@ -52,40 +47,4 @@ protected static function getClassProperties($className) return parent::getClassProperties($className); } - /** - * @param $value - * @param string $className - * @param ReflectionClass $reflection - * - * @return array - */ - protected static function getRelationshipMethodsAsPropertyName($value, $className, ReflectionClass $reflection) - { - $methods = []; - foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { - if (\ltrim($method->class, '\\') === \ltrim($className, '\\')) { - $name = $method->name; - $reflectionMethod = $reflection->getMethod($name); - - // Eloquent relations do not include parameters, so we'll be filtering based on this criteria. - if (0 == $reflectionMethod->getNumberOfParameters()) { - try { - $returned = $reflectionMethod->invoke($value); - //All operations (eg: boolean operations) are now filtered out. - if (\is_object($returned)) { - - // Only keep those methods as properties if these are returning Eloquent relations. - // But do not run the operation as it is an expensive operation. - if (false !== \strpos(\get_class($returned), 'Illuminate\Database\Eloquent\Relations')) { - $methods[] = $method->name; - } - } - } catch (ErrorException $e) { - } - } - } - } - - return $methods; - } }