Developing your own yii2-extension process

Hi, folks!

I have the greatest puzzle of this week. How to properly develop an extension?

First of all, my configuration.

Laptop: composer, git, IDE with enabled autoupload (excluded /vendor and /runtime)

Dev-server: nginx, php, composer, git, etc. (in the same subnet, literally near, no potential network problems)

Typical workflow:

  1. Write code in IDE (phpstorm)

  2. Ctrl+S (autoupload)

  3. F5 in browser (figuratively)

  4. It works!

  5. "git commit, git push" on the laptop

  6. "git reset, git pull" on the dev

There are implemented feature and two clean and updated copies of repo with predictable behavior without trash, forgotten changes, etc.

Probably not the best way. If the main problem is here, kick me immediately!

(Nota bene! I’m the only developer, there is no conflicts like “another” developer uploads code in seconds before my surprise “git clear” and his “F5 in browser” makes him cry.)

Anyway. I’m trying to create extension.

How it looks like:

  1. Google it twice

  2. RTFM

  3. Go to gii, fill all fields, press "Generate"

  4. Go to runtime/tmp-extensions/yii2-myextension

  5. "git init, git commit, git push"

  6. Add repo into "repositories" section of composer.json

  7. Run "composer require mynickname/yii2-myextension"

  8. DEVELOP! (<— a problem)

  9. Publish on packagist

  10. World-wide fame, girls, cold beer (<— not a problem)

But, emmm…

Do I understand correctly, when I develop I need to:

  1. Clone repo to dev (or laptop - depends on the scene of action from previous list)

  2. Write code in IDE

  3. "git commit, git push" from the laptop

  4. Go to dev runtime/tmp-extensions/yii2-myextension

  5. git pull

  6. composer update

  7. F5 in browser

  8. It doesn’t work :’( Go to 1.

Too many steps and too many odd commits, isn’t it? Moreover, to many network transmissions.

Okay. Delete “runtime/tmp-extensions/yii2-myextension” from autoupload excluded list. Not cool. Now we don’t need no bad connection. We don’t need no push and pull. But there are commits and “composer update”.

Okay. Add “packages” directory under @app/. Now I don’t delete /runtime from excluded. But (see previous).

Okay. Try to use “path” type of repository instead of “git” type (docs promise that “package/yii2-myextension” directory will be symlinked to “vendor/mynickname/yii2-myextension”. Or I read it wrong?). It seems to be awesome. I don’t need commit any change, autoupload is on.

But last method doesn’t work for me. composer throws “No composer.json file found in any path repository” when it exists and “composer validate” == ok.

And now the major question: What kind of developing process of extension do you use?

And another one: What am I doing wrong? ("All of it" is probably correct answer.)

As you probably have guessed, there is a better option when developing Yii extensions that uses Composer and that is to set up a repositories mapping that points to a path.

See this:

You can point that path to a neighbour directory to your test project on your own machine.

If you want to use source control you can also set up a repository mapping, set the type to ‘vcs’ and point it at your local git repository.

Only publish to Packagist when it is 100 % ready - it is a royal pain in the backside to have to deal with composer, the cache, tags, etc…