baumrock / RockMigrations

The Ultimate Automation and Deployment-Tool for ProcessWire
MIT License
34 stars 10 forks source link

Provide functional access to RockMigrations #41

Closed hirasso closed 11 months ago

hirasso commented 11 months ago

Hi there! Right now, RockMigrations needs to be referenced like this everywhere it's being used:

/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
$rm->...

How about providing a little helper function with the module, similar to ProcessWire's functions API? That would make code completion feel much cleaner IMO. This little snippet in the module would be enough:

/**
 * Provide access to RockMigrations
 * @return RockMigrations
 */
function rm(): RockMigrations {
    return wire()->modules->get('RockMigrations');
}

Than we could save us the additional like $rm = $this->wire->modules->get('RockMigrations'); throughout our code bases by using the function directly:

/** anywhere, migrate.php, page classes, ... */
rm()->migrate(...)
BernhardBaumrock commented 11 months ago

Nice idea, thx @hirasso check out the dev branch. Will be merged next month.

I used rockmigrations() instead of rm() to make it more verbose and avoid naming conflicts.

hirasso commented 11 months ago

@BernhardBaumrock woaaa that was fast! Looking forward! :)