Download the PHP package mudandstars/sync-enum-types without Composer
On this page you can find all versions of the php package mudandstars/sync-enum-types. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mudandstars/sync-enum-types
More information about mudandstars/sync-enum-types
Files in mudandstars/sync-enum-types
Package sync-enum-types
Short Description This is my package sync-enum-types
License MIT
Homepage https://github.com/mudandstars/sync-enum-types
Informations about the package sync-enum-types
This is my package sync-enum-types
This package ships a command that creates typescript declaration files for your php Enums. This command can be set so it automatically runs on-save, for example.
Installation
You can install the package via composer:
Usage (VS Code)
- Check if the published config needs changes, based on your project structure
- Install the 'Run on Save' Extension
- Add the 'Run on Save' command to your settings.json (I like the workspace settings for this):
Configuration
You can publish the config file with:
The recommended config has SYNC_CASES set to true to provide the enum cases as typed array for use in the frontend. Its latest version looks like this:
Possible Enum Features and Flags
Using Custom Method's Description
To avoid conflicts with existing data when changing Enum values in your database, some engineers prefer to use simple integers as their values and make use of functions to describe what the values represent, like the following:
If you want to sync the descriptions from an Enum's method instead of its cases' values, put the sync-using-method flag above the corresponding function like so:
Linking Other Enums
To maintain a single source of truth when using many Enums, sometimes it is necessary to define a case like this:
This is automatically handled correctly and resolves the value of the other Enum, as long as its source file also resides in the same directory.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Paul Sochiera
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of sync-enum-types with dependencies
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.0