-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #664 from tighten/dts-generation
Add type declarations and `ziggy.d.ts` generation
- Loading branch information
Showing
19 changed files
with
528 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Tightenco\Ziggy\Output; | ||
|
||
use Illuminate\Support\Arr; | ||
use Stringable; | ||
use Tightenco\Ziggy\Ziggy; | ||
|
||
class Types implements Stringable | ||
{ | ||
protected $ziggy; | ||
|
||
public function __construct(Ziggy $ziggy) | ||
{ | ||
$this->ziggy = $ziggy; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
$routes = collect($this->ziggy->toArray()['routes'])->map(function ($route) { | ||
return collect($route['parameters'] ?? [])->map(function ($param) use ($route) { | ||
return Arr::has($route, "bindings.{$param}") | ||
? ['name' => $param, 'binding' => $route['bindings'][$param]] | ||
: ['name' => $param]; | ||
}); | ||
}); | ||
|
||
return <<<JAVASCRIPT | ||
/* This file is generated by Ziggy. */ | ||
declare module 'ziggy-js' { | ||
interface RouteList {$routes->toJson(JSON_PRETTY_PRINT)} | ||
} | ||
export {}; | ||
JAVASCRIPT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.