11<?php
2-
32declare (strict_types=1 );
43
54namespace Webfox \InertiaDataProviders ;
65
7- use Illuminate \Contracts \Support \Arrayable ;
8- use Inertia \LazyProp ;
96use ReflectionClass ;
7+ use Inertia \LazyProp ;
8+ use Inertia \Response ;
109use ReflectionMethod ;
11- use ReflectionNamedType ;
1210use ReflectionProperty ;
11+ use ReflectionNamedType ;
12+ use Symfony \Component \VarDumper \VarDumper ;
13+ use Illuminate \Contracts \Support \Arrayable ;
1314
1415abstract class DataProvider implements Arrayable
1516{
1617 protected array |Arrayable $ staticData = [];
1718
19+ protected array $ excludedMethods = ['__construct ' , 'toArray ' , 'dd ' , 'dump ' ,];
20+
1821 public static function collection (DataProvider |array ...$ dataProviders ): DataProviderCollection
1922 {
2023 return new DataProviderCollection (...$ dataProviders );
@@ -32,7 +35,7 @@ public function toArray(): array
3235
3336 $ convertedMethods = collect ($ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC ))
3437 ->filter (fn (ReflectionMethod $ method ) => ! $ method ->isStatic ())
35- ->filter (fn (ReflectionMethod $ method ) => ! $ method ->isStatic () && ! in_array ($ method ->name , [ ' toArray ' , ' __construct ' ] ))
38+ ->filter (fn (ReflectionMethod $ method ) => ! $ method ->isStatic () && ! in_array ($ method ->name , $ this -> excludedMethods ))
3639 ->mapWithKeys (function (ReflectionMethod $ method ) {
3740 $ returnType = $ method ->getReturnType ();
3841 // @phpstan-ignore-next-line
@@ -45,4 +48,19 @@ public function toArray(): array
4548
4649 return collect ()->merge ($ staticData )->merge ($ convertedProperties )->merge ($ convertedMethods )->toArray ();
4750 }
51+
52+ public function dump (): static
53+ {
54+ $ response = new Response ('' , []);
55+ $ props = $ response ->resolvePropertyInstances ($ this ->toArray (), request ());
56+ VarDumper::dump ($ props );
57+ return $ this ;
58+ }
59+
60+ #[\JetBrains \PhpStorm \NoReturn]
61+ public function dd ()
62+ {
63+ $ this ->dump ();
64+ exit (1 );
65+ }
4866}
0 commit comments