diff --git a/Resources/Json/AnonymousResourceCollection.php b/Resources/Json/AnonymousResourceCollection.php deleted file mode 100644 index 2f26ecb..0000000 --- a/Resources/Json/AnonymousResourceCollection.php +++ /dev/null @@ -1,28 +0,0 @@ -collects = $collects; - - parent::__construct($resource); - } -} diff --git a/Resources/Json/Resource.php b/Resources/Json/Resource.php deleted file mode 100644 index 87338af..0000000 --- a/Resources/Json/Resource.php +++ /dev/null @@ -1,42 +0,0 @@ -version($request->version()); - } - - if (is_null($transformed = $this->toArrayUsingTransformer($request))) { - return parent::toArray($request); - } - - return $transformed; - } -} diff --git a/Resources/Json/ResourceCollection.php b/Resources/Json/ResourceCollection.php deleted file mode 100644 index 5880841..0000000 --- a/Resources/Json/ResourceCollection.php +++ /dev/null @@ -1,30 +0,0 @@ -version($request->version()); - } - - if (is_null($transformed = $this->toArrayUsingTransformer($request))) { - return parent::toArray($request); - } - - return $transformed; - } -} diff --git a/Resources/Json/Transformable.php b/Resources/Json/Transformable.php deleted file mode 100644 index 6af87d9..0000000 --- a/Resources/Json/Transformable.php +++ /dev/null @@ -1,109 +0,0 @@ -transformer = $transformer; - - return $this; - } - - /** - * Set version. - * - * @param string|null $version - * - * @return $this - */ - public function version(string $version = null): self - { - $this->version = $version; - - return $this; - } - - /** - * Get transformer. - * - * @return string|null - */ - public function getTransformer() - { - return $this->transformer; - } - - /** - * Get version. - * - * @return string|null - */ - public function getVersion() - { - return $this->version; - } - - /** - * Transform the resource into an array. - * - * @param \Illuminate\Http\Request $request - * - * @return array|null - */ - public function toArrayUsingTransformer($request) - { - $transformer = $this->resolveTransformer(); - - if (class_exists($transformer, false)) { - $service = new $transformer($request); - - if ($service instanceof Transformer) { - return $service->fromResource($this)->handle($this->instance); - } - } - } - - /** - * Resolve transformer. - * - * @return string - */ - protected function resolveTransformer(): string - { - $transformer = $this->transformer ?? class_basename($this->instance); - - return app('orchestra.http.version')->resolve( - $this->getNamespace(), $this->version, $transformer - ); - } - - /** - * Get namespace. - * - * @return string - */ - abstract public function getNamespace(): string; -} diff --git a/Traits/Transformable.php b/Traits/Transformable.php index 77712b2..1fdc657 100644 --- a/Traits/Transformable.php +++ b/Traits/Transformable.php @@ -46,6 +46,21 @@ public function options(array $options = []) return $this; } + /** + * Add options. + * + * @param array $options + * + * @return $this + * + * @deprecated v3.5.x + * @see static::options() + */ + public function withOptions(array $options = []) + { + return $this->options($options); + } + /** * Get request instance. * diff --git a/Transformer.php b/Transformer.php index 623e29d..307643c 100644 --- a/Transformer.php +++ b/Transformer.php @@ -8,13 +8,6 @@ abstract class Transformer extends BaseTransformer { use Traits\Transformable; - /** - * Resource instance. - * - * @var Orchestra\Http\Resources\Json\Resource - */ - protected $resource; - /** * Invoke the transformation. * @@ -28,20 +21,6 @@ public static function with($instance, array $options = []) return (new static())->options($options)->handle($instance); } - /** - * Set resource. - * - * @param \Orchestra\Http\Resources\Json|resource $resource - * - * @return $this - */ - public function resource($resource) - { - $this->resource = $resource; - - return $this; - } - /** * Invoke the transformer. *