Add a package to composer - step-by-step (v2019)

Tips submitted by PHPMaker users
Post Reply
LlamaBob
User
Posts: 15

Add a package to composer - step-by-step (v2019)

Post by LlamaBob »

I've recently added a package to my project via composer. That package would not work after I generated code and selected the "Composer update" checkmark. Here's a step-by-step on how to get PHPMaker 2019 to include the package during the Composer update.

  1. From the website packagist dot org, or your package's documentation, find the composer installation command of your 3rd party package. For example:
    composer require xyz/php-sdk
    You will need the text after the "composer require".. in this case, "xyz/php-sdk"

  2. Also from the same website, find the latest version. ie.. v2.3.0

  3. Next, in the PHPMaker 2019 help file, select the "Index" tab and search for "Using User Code".

  4. From the Help file, copy the code example "2. BeginGenerate and EndGenerate Events" and change to BeginGenerate

Events.on("BeginGenerate", () => {
// Your code to do something after generation
});

  1. From the help file, copy the example "4. Project Settings". Paste it to the Event.on section above.

Events.on("BeginGenerate", () => {
// Your code to do something after generation
PROJ.Require = { "aws/aws-sdk-php": "3.65.1" }; // In JSON format
});

  1. Now substitute your package install and version information you collected above.

Events.on("BeginGenerate", () => {
// Your code to do something after generation
PROJ.Require = { "xyz/php-sdk": "2.3.0" }; // In JSON format
});

Hint.. you can add the "^" to the version to indicate this version or future versions:

Events.on("BeginGenerate", () => {
// Your code to do something after generation
PROJ.Require = { "xyz/php-sdk": "2.3.0" }; // In JSON format
});

  1. Paste this code to the bottom of your usercode.js file located in the install directory as indicated at the top of the help file.

  2. Generate your PHPMaker 2019 code with the "Composer update" checkmarked. It should all compile without errors.


arbei
User
Posts: 9389

Post by arbei »

You can use, e.g.

PROJ.Require = { "aws/aws-sdk-php": "3.65.1", "xyz/php-sdk": "2.3.0" , ...others... }; // In JSON format

withOUT the need to put it in "BeginGenerate" event,


sticcino
User
Posts: 1043

Post by sticcino »

excellent!, thanks. i'm usually going crazy as to why something broke in the app, not realizing that i had the "composer" option enabled and the additional packages would get removed.


Post Reply