Page 1 of 1

Composer based tutorials?

Posted: Tue Apr 05, 2016 11:03 am
by thinsoldier
I've never used composer. Actually in the last decade 95% of the php code I maintained was written by either myself or 1 other co-worker and the other 5% I eventually read every line of code enough times to mostly understand how it all worked. So I have almost no experience working with other people's code and the idea of building 25% to 75% of a project by pulling in other people's packages is foreign to me.

Can anyone suggest a good tutorial that walks you through building an actual application using primarily packages available through Composer?

Re: Composer based tutorials?

Posted: Tue Apr 05, 2016 11:09 am
by Celauran
http://code.tutsplus.com/tutorials/easy ... -net-25530

That does a good job of covering the basics. There's no magic to Composer, really. You're pulling in namespaced packages and using them elsewhere in the application you're building. If you understand namespaces, it should be pretty straightforward. If not, give these a read:

http://php.net/manual/en/language.namespaces.php
http://www.phptherightway.com/#namespaces

Re: Composer based tutorials?

Posted: Thu Apr 21, 2016 10:07 am
by thinsoldier
Celauran wrote:http://code.tutsplus.com/tutorials/easy ... -net-25530

That does a good job of covering the basics. There's no magic to Composer, really. You're pulling in namespaced packages and using them elsewhere in the application you're building. If you understand namespaces, it should be pretty straightforward. If not, give these a read:

http://php.net/manual/en/language.namespaces.php
http://www.phptherightway.com/#namespaces
I've used composer once or twice to download a class but what I'm really looking for is: Today we're going to build a web app that does X,Y,Z using the following community packages for features Xa, Xb, Ya, Yb, Xc, and Za.

Re: Composer based tutorials?

Posted: Thu Apr 21, 2016 1:59 pm
by Christopher
The issue will not be using Composer for packages x, y and z. It will be getting you app using Composer's autoloader scheme, which means writing simple composer.json file for you app. Then you just need to add something like:

Code: Select all

require __DIR__ . '/vendor/autoload.php';

Re: Composer based tutorials?

Posted: Fri Apr 22, 2016 1:47 pm
by thinsoldier
Maybe I should have called this post "Small Community Library based tutorial" where someone has already created their app using mostly pre-existing code from the community and then their tutorial is about why they chose the packages they chose and the process of making them work together. Aside from the phpMailer class and my co-worker & boss I've NEVER used anyone else's code! So I'm looking for an "explain it tome like I'm a 5 year old: how do you use other people's code?" kind of thing.

Re: Composer based tutorials?

Posted: Fri Apr 22, 2016 2:31 pm
by Celauran
I don't know of any tutorials aimed specifically at what you're looking for, and writing one from the ground up also involves writing an app from the ground up. It's quite a bit of work. Do you have a small project you'd like to integrate some third-party components into? Maybe refactor out some NIH code for something a little more robust? I'd be happy to work with you to achieve that.

Re: Composer based tutorials?

Posted: Fri Apr 22, 2016 11:48 pm
by Christopher
Have you looked at the composer.json files for various framework apps? The files are pretty simple. Once you have your code working, then add other libraries.