PHP code example of jhavenz / laravel-migration-table-parser

1. Go to this page and download the library: Download jhavenz/laravel-migration-table-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jhavenz / laravel-migration-table-parser example snippets


use Jhavenz\LaravelMigrationTableParser\Facades\MigrationTableParser;

$result = MigrationTableParser::parse($file);

$optionalTable = $result->search('my_table');

$tablesFoundCollection = $result->tables();

use Jhavenz\LaravelMigrationTableParser\Facades\MigrationTableParser;

$result = MigrationTableParser::parse($file)
    ->setStrategies(MyCustomExtractionStrategy::class)
    ->setVisitors(MyCustomTableNameVisitor::class)
    ->parse(database_path('migrations/2021_01_01_000000_create_some_table.php'));

// Push, leaving the default strategies in place
config()->push('migration-table-parser.strategies', [MyCustomExtractionStrategy::class]);

// Override the default strategies
config()->set('migration-table-parser.strategies', [MyCustomExtractionStrategy::class]);



use Jhavenz\LaravelMigrationTableParser\ExtractMigrationTableVisitor;

return [
    'visitors' => [
        ExtractMigrationTableVisitor::class
    ],
    'strategies' => [
        Jhavenz\LaravelMigrationTableParser\ExtractionStrategies\Drop::class,
        Jhavenz\LaravelMigrationTableParser\ExtractionStrategies\DropIfExists::class,
        Jhavenz\LaravelMigrationTableParser\ExtractionStrategies\CreateOrAlterTableMethodIsCalled::class
    ]
];

readonly class ParserResult
{
    public function __construct(
        private bool $successful,
        private string $message,
        private string $migrationFile,
        private array $tablesFound = [],
        private ?Throwable $error = null,
    ) {}

    // ... other methods
}

readonly class ParsingStarted
{
    public function __construct(
        public string $migrationFile,
        public Parser $parser
    ) {}
}

readonly class ParsingCompleted
{
    public function __construct(
        public ParserResult $result,
        public Parser $parser
    ) {}
}

use Jhavenz\LaravelMigrationTableParser\Events\ParsingStarted;

Event::listen(ParsingStarted::class, function (ParsingStarted $event) {
    // do stuff...
});