Yii Framework Forum: Composer Depency Of Dependency - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Composer Depency Of Dependency Rate Topic: -----

#1 User is offline   joewoodhouse 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-January 13

Posted 22 January 2013 - 09:35 AM

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",
  "require":{
    "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
<package_root>/
<package_root>/vendor/
<package_root>/vendor/yiisoft/yii/
etc


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>
{
  "require":{
    "myvendor/mypackage"
  }
}


## dir structure
<project_root>/
<project_root>/vendor/
<project_root>/vendor/myvendor/mypackage
<project_root>/vendor/yiisoft/yii


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 );
Yii::createApplication(...)



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

Cheers
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 January 2013 - 06:32 PM

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).
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users