Tip: Create a Console Helper

Since version 1.77.0 we provide an easy registration of console helpers.
Console Helpers are way to share functionality with other commands.

I will show you how easy it is to create such a helper.
Out example helper will return the current system time.

Create a new module

Create a new folder in your home directory with the name “.n98-magerun/modules/example-module”.

Now we need a module config file.

Create a file “n98-magerun.yaml” with the following content inside the module folder.
The config defines a new namespace “Example” in the autoloader of n98-magerun, the new helper “datetime”
and an example command “ExampleCommand”.
We will create the new files in this tutorial.

Create the helper

Create a new folder src/Example inside the module folder.

Inside the src folder we will place our helper with the filename “DateTimeHelper.php”.

Create an example command to test new helper

Now we create a command in file ExampleCommand.php with this content:

If you have created all the files you should have this file structure:

You should now be able to run the new command with this command line call:

The command should show the current system time.
I hope you like the console helper.
n98-magerun is already bundles with some build-in helpers which are described in our
wiki. https://github.com/netz98/n98-magerun/wiki/Helpers

Happy Coding!

Download Example Module: example-module.tar.gz