Download the PHP package jhavenz/laravel-migration-table-parser without Composer
On this page you can find all versions of the php package jhavenz/laravel-migration-table-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jhavenz/laravel-migration-table-parser
More information about jhavenz/laravel-migration-table-parser
Files in jhavenz/laravel-migration-table-parser
Package laravel-migration-table-parser
Short Description extract the table name from a Laravel migration using the nikic/php-parser
License MIT
Homepage https://github.com/jhavenz/laravel-migration-table-parser
Informations about the package laravel-migration-table-parser
Laravel Migration Table Parser
Extracts the table name(s) from a Laravel migration with the assistance of the nikic/php-parser
Basic Usage
This package looks at the code used inside the up/down method of a migration file.
$result is a value object of type \Jhavenz\LaravelMigrationTableParser\ParserResult
$optionalTable is an instance of \Prewk\Option
, a rust-inspired Some/None monad. Read more here
$tablesFoundCollection is an instance of \Illuminate\Support\Collection<string>
Dive into the /tests to learn more
Implementation Notes
You can run any other logic within your migration file(s), but the table name is extracted based on when you call one of these methods:
->drop('users');
->dropIfExists('users');
->table('users', function (Blueprint $table) {...});
->create('users', function (Blueprint $table) {...});
In all cases, the package will extract 'users' as the table name
This package provides a couple extension points for you to implement your own logic.
Check out these interfaces:
- Write your own extraction logic using this interface
- To write your own visitor logic using this interface
Once implemented, you can pass your custom classes to the parser like so:
Note: When the parser runs, these implementations get resolved by the service container.
An alternative way to add your own logic is to add your implentation(s) to the config file: `
Installation
You can install the package via composer:
Publishing
You can publish the config file with:
This is the contents of the published config file:
Advanced Usage
The \Jhavenz\LaravelMigrationTableParser\ParserResult
provides a
handful of convenience methods to help you work with each result that's
extracted from the migration file(s). It's basic makeup is:
Beyond the getters for the properties listed above, it has methods with the following signatures:
public function search(string $name): Option
public function table(int $index = 0): ?string
public function expect(): \Pest\Expectation
Lastly, the parser emits events that you can listen for.
Their basic makeup includes:
and
You can listen to these events using Laravel's event system, e.g.
Testing
Pest is used for testing and the initial commit for this repo is being pushed with ~30-40 tests.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome.
Security Vulnerabilities
Please email me asap if you discover any security related issues:
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-migration-table-parser with dependencies
illuminate/contracts Version ^10.0||^11.0
nikic/php-parser Version ^5.1
prewk/result Version ^4.0
spatie/laravel-package-tools Version ^1.16