Quote from: BobRay at Apr 17, 2013, 03:14 AM
Can you say a little more about how you use Composer with MODX? I'm still trying to wrap my head around Composer. The docs are awful for people who know nothing about it, imo. I get the concepts, but I still don't know what it actually does, physically, or at what point it acts in the package management process (during development?, during the build? during the install?). I'm wondering how I could use Composer and if it would make sense to integrate it into MyComponent.
I use Packagist as an helper when I need to use a feature that already exists and/or have a generic implementation available via Composer.
For example, for the next Cliche (modx package) version, I'm using 3 packages from Composer (for upload, phpthumb and oembed). Those 3 librairies are/will be generic and reusable "as is" in other project (not using modx).
The rest of the code is modx related and is developed following modx conventions for most of it.
So far, that gives me a basic folder structure like the following:
As you can see, it does change very much from any modx package appart from the composer related files and folder (composer.json + vendor folder) and a custom autoloader(.php) that i use for my modx project.
What it actually does ?
It let me use/reuse librairies/code that should be framework agnostic.
It's also a dependency manager, as each package can specifiy if they have some dependencies, which will be retreived when i install/update composer.
It's a huge helper when you use different tools per client request, as you can reuse the same code with different core tool.
What it actually does physically ?
Composer is used via the command line and when you use the command "composer.phar install", it will retreive the packages precised in the composer.json file (along with all their dependencies if any) in the vendor directory.
It will also generate an autoloader file (also in the vendor directory), and a composer.lock file (similar to ruby gem's lock files).
Then, include the "vendor/autoload.php" file from your project to use the loaded Composer packages.
At what point it acts in the package management process ?
Within Modx 2.x, I believe that it should be used per project if needed.
Since they're php librairies, they are used during development process and if the package is distributed for end users
, all composer packages should be shipped in the modx package as well.
Note that I would not forcefully take this "all shipped" approach if the package was geared toward developpers.
How I could use Composer and if it would make sense to integrate it into MyComponent
With Modx 2.x realm, you should use Composer as you see fit.
What i showed is only one approach (and i would be happy if some other composer users can show us how they would do).
As for if it make sense for MyComponent, I would say only if your component needs it.
Unless i'm wrong, from what i can see on github, it's mostly modx related and does not use code that can be defined as generic/useful outside of Modx 2.x