getAttributes(UseAllDirective::class); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return $instance->shouldUse; } return false; } /** * Resolve the auth directive as an attribute. */ protected function resolveAuthAttribute(): bool { $reflection = new ReflectionClass($this); $attributes = $reflection->getAttributes(UseAuthDirective::class); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return $instance->shouldUse; } return false; } /** * Resolve the builder directive as an attribute. */ protected function resolveBuilderAttribute(): ?string { $reflection = new ReflectionClass($this); $attributes = []; while ($reflection) { $attributes = array_merge($attributes, $reflection->getAttributes(UseBuilderDirective::class)); $reflection = $reflection->getParentClass(); } if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return sprintf('%s@%s', $instance->controllerClass, $instance->method); } return null; } /** * Resolve the deprecated directive as an attribute. */ protected function resolveDeprecatedAttribute(): ?string { $reflection = new ReflectionClass($this); $attributes = $reflection->getAttributes(Deprecated::class); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return $instance->reason; } return null; } /** * Resolve the field directive as an attribute. */ protected function resolveFieldAttribute(): ?string { $reflection = new ReflectionClass($this); $attributes = []; while ($reflection) { $attributes = array_merge($attributes, $reflection->getAttributes(UseFieldDirective::class)); $reflection = $reflection->getParentClass(); } if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return sprintf('%s@%s', $instance->fieldClass, $instance->method); } return null; } /** * Resolve the first directive as an attribute. */ protected function resolveFirstAttribute(): bool { $reflection = new ReflectionClass($this); $attributes = []; while ($reflection) { $attributes = array_merge($attributes, $reflection->getAttributes(UseFirstDirective::class)); $reflection = $reflection->getParentClass(); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return $instance->shouldUse; } } return false; } /** * Resolve the find directive as an attribute. */ protected function resolveFindAttribute(): bool { $reflection = new ReflectionClass($this); $attributes = $reflection->getAttributes(UseFindDirective::class); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); return $instance->shouldUse; } return false; } /** * Resolve the paginate directive as an attribute. */ protected function resolvePaginateAttribute(): array|bool { $reflection = new ReflectionClass($this); $attributes = $reflection->getAttributes(UsePaginateDirective::class); if (filled($attributes)) { $instance = Arr::first($attributes)->newInstance(); if ($instance->shouldUse && is_string($instance->builder)) { return [ 'builder' => $instance->builder, ]; } return $instance->shouldUse; } return false; } /** * Resolve the search directive as an attribute. */ protected function resolveSearchAttribute(): bool { $reflection = new ReflectionClass($this); $attributes = []; while ($reflection) { $attributes = array_merge($attributes, $reflection->getAttributes(UseSearchDirective::class)); $reflection = $reflection->getParentClass(); } return filled($attributes); } }