Composer Depency Of Dependency

Hi all,

So I am creating a yii module as a stand-alone composer package. So the package has a composer.json file in it’s root which requires yiisoft/yii

## package composer.json <simplified>


  "name": "myvendor/mypackage",


    "yiisoft/yii" : "1.1.*"



If I git clone my package repository and run "composer install", a vendor folder is created under my packages root which has yiisoft/yii in it. Which is fine.

## dir structure





However if my packages is used as a dependency of something else (say, I have a project that want’s to require this stand-alone package), then composer will create a vendor folder at the root of the project with both yii and my package next to each other.

# project composer.json <simplified>






## dir structure





So for my package code, yii can be in one of two places relative to it

a) Inside it (at <package_root>/vendor/yiisoft/yii)

B) Next to it ( at <project_root>/vendor/yiisoft/yii)

Now my code in the package needs to know the location of Yii in order to require() bits of it. For example, the tests need to require yiit.php.

# bootstrap.php

require( ...... path to yiit );


Can anyone give me any advice on how to handle this? I don’t really want to have to check in 2+ places every time I need to require a Yii file


I don’t know anything about Composer, but this logic seems flawed.

Your module depends on Yii, it does not require Yii.

It is a ‘dependency’.

What you ‘require’ is what packages your module use, not what it is based on.

So, provided that Yii was installed via composer, your module would depend on Yii being installed.

Then, your module can require other packages (which are put in your module’s vendor directory).