0

I've recently started using zend framework 3 for work; and was asked about the possibility of using the same library files within another application, or project.

The application folder 'manufactoring' contains all expected folders within a zf3 structure, such as modules, library, etc.

The question is: can you refer to the library files within 'manufactoring' within another application/project?

This would reduce code duplication.

I have tried answers to other questions on Stack Overflow; however they related to files within the same project.

I was able to link and execute using include or require, which allowed variables to be defined, or functions to be called from a source outside the application/project; however for my use I needed to define a new class, and this method did not work for that purpose.

Any insight would be greatly appreciated.

EDIT: I found this answer from another stackoverflow question: https://stackoverflow.com/a/3272684/10647325 which suggests a solution I am aiming for. This example has a common folder at the same level as the application folders, which contains libraries which can be linked to application folders.

EDIT: I've also tried changing the library path on composer.json. This worked after running composer dump-autoload for migration.

1 Answer 1

1

Modules are autoloaded from vendor as well as module, so you'd split the module with code you want to share out into its own repository and then install it using composer in both applications in the same way as you would any other PHP library.

Sign up to request clarification or add additional context in comments.

3 Comments

If the file is updated, will it update for both applications; or will it have to be installed using composer each time a change is made?
There are a few different ways to set it up locally (symlinks, docker volumes) but it's a while since I did it so I'm not sure what's best these days.
Thanks for your help Tim. I found a solution by changing the path on composer.json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.