Server IP : / Your IP : 10.244.4.16 [ Web Server : nginx/1.25.3 System : Linux escuela-portal-app-54f56585bc-kst6g 5.15.0-1084-azure #93-Ubuntu SMP Sat Mar 15 14:12:29 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.2.13 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /proc/449/root/var/www/app/vendor/inertiajs/inertia-laravel/src/ |
Upload File : |
<?php namespace Inertia; use Closure; use Illuminate\Support\Arr; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\App; use GuzzleHttp\Promise\PromiseInterface; use Illuminate\Support\Traits\Macroable; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Responsable; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\ResourceResponse; use Illuminate\Support\Facades\Response as ResponseFactory; class Response implements Responsable { use Macroable; protected $component; protected $props; protected $rootView; protected $version; protected $viewData = []; /** * @param array|Arrayable $props */ public function __construct(string $component, $props, string $rootView = 'app', string $version = '') { $this->component = $component; $this->props = $props instanceof Arrayable ? $props->toArray() : $props; $this->rootView = $rootView; $this->version = $version; } /** * @param string|array $key * @param mixed $value * * @return $this */ public function with($key, $value = null): self { if (is_array($key)) { $this->props = array_merge($this->props, $key); } else { $this->props[$key] = $value; } return $this; } /** * @param string|array $key * @param mixed $value * * @return $this */ public function withViewData($key, $value = null): self { if (is_array($key)) { $this->viewData = array_merge($this->viewData, $key); } else { $this->viewData[$key] = $value; } return $this; } public function rootView(string $rootView): self { $this->rootView = $rootView; return $this; } /** * Create an HTTP response that represents the object. * * @param \Illuminate\Http\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function toResponse($request) { $only = array_filter(explode(',', $request->header('X-Inertia-Partial-Data', ''))); $props = ($only && $request->header('X-Inertia-Partial-Component') === $this->component) ? Arr::only($this->props, $only) : array_filter($this->props, static function ($prop) { return ! ($prop instanceof LazyProp); }); $props = $this->resolvePropertyInstances($props, $request); $page = [ 'component' => $this->component, 'props' => $props, 'url' => $request->getBaseUrl().$request->getRequestUri(), 'version' => $this->version, ]; if ($request->header('X-Inertia')) { return new JsonResponse($page, 200, ['X-Inertia' => 'true']); } return ResponseFactory::view($this->rootView, $this->viewData + ['page' => $page]); } /** * Resolve all necessary class instances in the given props. */ public function resolvePropertyInstances(array $props, Request $request, bool $unpackDotProps = true): array { foreach ($props as $key => $value) { if ($value instanceof Closure) { $value = App::call($value); } if ($value instanceof LazyProp) { $value = App::call($value); } if ($value instanceof PromiseInterface) { $value = $value->wait(); } if ($value instanceof ResourceResponse || $value instanceof JsonResource) { $value = $value->toResponse($request)->getData(true); } if ($value instanceof Arrayable) { $value = $value->toArray(); } if (is_array($value)) { $value = $this->resolvePropertyInstances($value, $request, false); } if ($unpackDotProps && str_contains($key, '.')) { Arr::set($props, $key, $value); unset($props[$key]); } else { $props[$key] = $value; } } return $props; } }