Download the PHP package ctasca/mage-bundle without Composer
On this page you can find all versions of the php package ctasca/mage-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ctasca/mage-bundle
More information about ctasca/mage-bundle
Files in ctasca/mage-bundle
Package mage-bundle
Short Description Easily create Magento/Adobe Commerce PHP/XML/JS files from a set of templates
License MIT
Informations about the package mage-bundle
ctasca/mage-bundle
Easily create Magento2/AdobeCommerce PHP/XML/JS files from a set of templates via the command-line.
Allows you to define your own templates as well as the data provided at files' creation time.
1 Installation
2 Copy template files to Magento root dev/ directory
After executing the above command, check that dev/
directory of your Magento installation contains a mage-bundle/
directory.
Enable the module
Run setup:upgrade
command
Run setup:di:compile
command (optional)
If Magento is running in production
mode you will need to also run:
Available commands
Shortcut
Creates a skeleton Magento module in app/code directory, generating the required registration.php and etc/module.xml files
Shortcut
Creates a Controller namespace and Action class in specified module.
Developer is prompted to choose a router (either standard or admin), and an Action template from the ones available in mage-bundle/http-controller
or mage-bundle/adminhtml-http-controller
directories.
Shortcut
Creates an XML file in Company/Module/etc directory. Templates can be chosen after specifying the area where the template applies to.
Shortcut
Creates a Model, Resource Model and Collection classes in specified Company/Module.
Shortcut
Creates all the required class for a Repository in specified Company/Module.
IMPORTANT: In order to create a repository a model implementing an interface must exist.
If you need a Repository when creating a model-set with the command magebundle:model:set:create
you can choose a template that will also create a Model implementing an interface
This command creates the following:
- An API Interface for the repository
- An API Data Interface for the model (if it doesn't exist)
- An API Data Search Result Interface
- The repository Model implementing the repository Interface
Do not forget to add the preferences to your di.xml for the repository classes once created. For example:
Shortcut
Creates a Model class in specified Company/Module. There is also the template to create an interface instead of a class.
Shortcut
Creates a template Block class in specified Company/Module.
Shortcut
Creates a Helper class in specified Company/Module.
Shortcut
Creates a CustomerData class in specified Company/Module.
Shortcut
Creates a View Model class in specified Company/Module.
Shortcut
Creates an Observer class in specified Company/Module.
Shortcut
Creates a Plugin class in specified Company/Module.
Shortcut
Creates a Cron class in specified Company/Module.
Shortcut
Creates a Console Command class in specified Company/Module.
Shortcut
Creates a Setup Data Patch class in specified Company/Module.
Shortcut
Creates a Setup Schema Patch class in specified Company/Module.
Shortcut
Creates an API interface in specified Company/Module. Templates can be chosen after specifying the area where the template applies to.
For functional API interfaces, the generated file will be created in the Company/Module/Api directory
For data API interfaces, the generated file will be created in the Company/Module/Api/Data directory
Shortcut
Creates a JQuery widget file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js
directory.
Shortcut
Creates an Ui Component JS file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js
directory.
Shortcut
Creates a Logger Handler and Logger classes files in specified Company/Module.
Log filename can be specified when executing this command.
Shortcut
Creates a JS mixin file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js
directory.
Shortcut
Creates an Exception class in specified Company/Module.
Utilities commands
Shortcut
Encrypts/Decrypts a string using Magento crypt key
Setting custom working directory
By default, MageBundle creates files in the app/code
directory and in the specified module's namespace
It is possible, to change this behaviour by creating a json file named pwd.json
in the $MAGENTO-ROOT/dev/mage-bundle
directory and specifying the directory (relative to magento root) where files will be created when executing MageBundle commands.
This can be useful, for example, when developing a module which is not located in app/code
directory
Important:
The directory specified in pwd.json
must end with a forward-slash
pwd.json example:
About template files:
Template files are written in PHP version 8.1.
For example the http-get-action-json-result.tpl.php
contains the following
{{php}} declare(strict_types=1); namespace {{namespace}}; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\Controller\Result\Json; class {{class_name}} implements HttpGetActionInterface { /** * @param RequestInterface $request * @param JsonFactory $jsonFactory */ public function __construct( private readonly RequestInterface $request, private readonly JsonFactory $jsonFactory ){} /** * @return Json */ public function execute(): Json { $jsonResponse = $this->jsonFactory->create(); return $jsonResponse->setData([]); } }
To set your own templates just place them in the MAGENTO_ROOT/dev/mage-bundle/$TEMPLATES_DIRECTORY/
directory and choose the template when executing the magebundle create commands.
Note: When executing the magebundle:etc:xml:create
command, files are generated with the same name as the template file.
To create your own templates, use the filename for the xml file to be generated appending __$STRING to the template filename.
For example to define your own global acl.xml template, create, for example, the template file naming like so: acl__custom.tpl.xml. Then simply place it in the dev/mage-bundle/etc/global directory and select it when executing the create command.
IMPORTANT: If a filename already exists in a module's directory, the create command will not be executed and an error is output to the console.
This is to prevent overwriting an existing file.
For a list of the templates defined within the module go to...
Templates Data Provider
It is possible to define your own templates as well as the data that are passed when these are generated.
In order to do so, simply create a JSON file in the MAGENTO_ROOT/dev/mage-bundle/custom-data/#path-to-template#
directory, naming the file exactly as the template file that is being generated and defining a JSON Object with setter methods as keys and their corresponding values.
As an example, for XML files generated in Company/Module/etc
directories, custom data should be stored in MAGENTO_ROOT/dev/mage-bundle/custom-data/etc/#area#/#template_name#.tpl.json
Example
After creating this JSON file, it will be possible to use the placeholder {{test_namespace}}
in a template file.
As setCustomDataArray
provides an array, this will be imploded with PHP_EOL
separator. To use it in your template files you would use the placeholder: {{custom_data_array}}