Library and Application

Hey all,

I have a Yii2 application, called P, which I would like to use it as a library (or yii2 extension), from others Yii2 applications. This would allow me to deploy P as an Application and also to include it with composer as a library/module in others applications.
Is that possible?

Thanks !

1 Like

Simply publish it on as a new package which you can then include in other applications via composer require yourname/P

If you want to write a module (like yii2-gii or yii2-debug) you should consider to create a yii extension. See the guide for more informations on this:

Thanks. But I might have not explained very well.
We already have several libraries published to our own Satis repo, that is not our issue. My question is: Can I have in a single git repo a Yii2 basic application which can be deployed as it is (a web app) and also included as a library in another application (as a Yii2 module/Extension)?
Or asking the question in another way… take any Yii2 official extension, like yii2-gii, can I deploy yii2-gii as a standalone basic Yii2 application (of course I’m talking about extensions with controllers and views, that can be accesed using the browser)? What should I change or add to the composer.json (and other config files) in order to do this?

I think it should be possible, even though I would advise against it.

I would try to declare the project as type: library in composer.json and add an autoload key to it that provides the name of the root namespace that you can use to include files from your project.

This way, it should be possible to require the project as library in other projects as usual. As for the deployment: nothing should change. You may have to go in detail on how you plan to deploy your app. Cloning the repo would still work.