Using composer without dependencies - php

I have project with this scheme:
main project depends on subprojects
subproject 1 with some own dependencies
subproject 2 with some own dependencies
subproject 3 with some own dependencies
I'm curious if I can use composer to do job. I would like that packages (subprojects) with type "project" behave like standalone project, not like library.
I found workaround, if in main project composer.json provide/replace all dependencies from subprojects, I can use composer install/update and don't bother about conflicts. I can use custom installer to put subprojects in proper directories and plugin or script to install dependencies for every subproject. This works but is quite hard to maintain, if any subproject adds dependency I need to modify main project composer.json.
Is way to use composer for this task or I should abandon idea write simple tool? What do you think?

Related

Why should we install Laravel with composer?

I downloaded Laravel from github and save it on c:/htdocs/laravel1
and I created a copy of my laravel with CMD (with composer) and I install this as laravel2 in c:/htdocs/laravel2 directory.
Laravel1:
c:/htdocs/laravel1
Laravel2:
c:/htdocs/laravel2
And I have access to both of them in localhost:8080/laravel1/public/ and
localhost:8080/laravel2/public/
My question is : Why should I install laravel by composer? There is no different between the installed laravel and downloaded laravel.
There are many, many valid reasons to use composer:
Composer creates optimized autoloaders if you want it to
Allows you to add thrird party dependencies easily (just add them to composer.json)
You can track the composer.lock file, and use composer install to ensure the exact same versions of the dependencies are being used throughout (on all environments, by everyone contribbuting) This is a must-have, if you're using automated builds!
Updating all dependencies, including Laravel, is a simple matter of composer update
Composer supports post-install and post-update scripts, to be executed after a composer install/update is run. This is quite commonly used to prompt the dev for configuration parameters. Downloading the code means you have to edit the config files by hand, and worse of all: track them in git or svn
... I'll probably add more reasons along the way, these are just a few off the top of my head
Update:
Just thought of some more reasons why using composer is a good idea:
Composer packages themselves can, and often do, define dependencies and requirements. Things like "php": ">=5.4.0", or "ext-curl": "*" will alert you to any missing PHP extensions or a version mismatch. These requirements can also trigger composer to fetch additional dependencies. Which brings me on to the next point:
Laravel itself has dependencies: Laravel uses components from Symfony2, for example. The easiest way to manage its own dependencies is to use composer, seeing as Symfony does, too. If you run composer update, the dependencies of Laravel will be checked, and updated where needed. Doing this manually is possible, but it's tedious, and really not worth the bother. Repetitive, dull jobs make people grumpy. Computers don't have this problem.
Composer is a dependancy manager similar to node's npm which allows quick and easy management of 3rd party libraries & packages on a per-project basis.
I recommend reading https://getcomposer.org/doc/00-intro.md to find out more about composer and explore https://packagist.org to find out the kind of things that are available through composer

"plugin" composer project, dependencies to be able to access main project

So I can't quite figure this one out. We have an API as a composer project.
No we which to add functionality to this API in a modular fashion creating separate composer projects for each module.
But how do I resolve dependencies while developing? Each module need access to the "core" API project to be able to test out code.
The current API is not a real composer package yet. But my initial thought is to create a new package for the module I'm about to develope, and then add a dev-dependency for the "core" API.
Or how should I do it?
Are your modules standalone resp. without the "Core" package usable?
I suppose not, so the "Core" module is a dependency for each of your modules.
Ergo the "you/core" package needs to be in the require block of composer.json of every module.
Note that this is not a dev-dependancy then, because i suppose your module wouldnt be usable without the core package.
Phpunit is a classic dev-dependency because the functionality of your module would still work if there would be no phpunit.
To test & develop the module, you would run a composer install in your module project folder to fetch all dependencies into a vendor folder. Then you can develop and have all your dependencies present. You would need to require the composer autoloader, though. F.e in your phpunit.xml.dist.
Dont forget to add vendor to your .gitignore

PHP Composer mixed with Git Submodules and Symfony2

I have a project here that's a large Symfony2 app, I'm looking to introduce git submodules to components we're building here in-house. The issue here is that each component also requires composer packages for itself to function properly and now I have composer packages for the symfony2 app and composer packages needed for the component and I'm unsure how to handle/setup these dependencies here.
At the moment I'm manually running 'composer install' for each component (git submodule) we add, implying that each component has its own 'vendor' folder, this is far from ideal so I'm coming to Stack to get come good advice on how to keep these 'symfony composer dependencies' and 'component composer dependencies' easily maintainable.
I don't need to make sure the version of the symfony2 app's deps are synchronised with the components deps, i just need to make it simple and maintainable without having to run 'composer update' with each git submodule we setup.
Thanks!
EDIT
I'm now using composer's repositories key to define URL's to my companies private github repos. I'm able to pull in a singular private repo, lets call it Repo A. However when I add Repo B and make Repo A require Repo B it doesn't resolve properly.
composer.json for Repo A (user-reporting-component): https://gist.github.com/dragoonis/6ea92e062762c516baea
Composer.json for Repo B (database-component): https://gist.github.com/dragoonis/e54b47b75a79b82ebaea
The following error message occurs: https://gist.github.com/dragoonis/d79cd2c2dd5cc50bcd2a
The package of opinurate/database-component does exist as it's one of the repos defined in the respositories key.
Conclusion
The end solution here was to use Satis to setup what is your own private version of 'packagist' what will work alongside packagist.
I setup Satis at 'http://packages.mydomain.com' and added a 'repositories' key in my main apps composer.json file to that URL. Now when evaluating package names it will use your own custom satis server to give you git URL's too.
I would say your best bet is to add those components via composer as opposed to git submodules. It makes coding and maintenance a bit more complex, but it ensures that your application is aware for all the actual dependencies.
If you don't want them to be public and want an easier way to handle them, then i would roll out a Satis deploy locally and register them all there, adding that satis repo to your composer.json.
Satis is a simpler version of Packagist, as long as the server with it, and the machines that run composer install have access to your private repositories, nothing else will see them. There is documentation on the Composer website at: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
You will then setup packages.yourcompany.com and add it to your composer.json as an alternate source of packages. Everything stays private.
Reply to Edit:
This is happening because composer compartimentalizes, which means the "repository" is only known to your project's composer.json, the one in Repo A does not know, so it cannot find it. You must re-define the repository in that one. Even using Satis the "satis" address must be added to all composer.json files involved.
Add the "repository" stuff you added in your app to the composer.json in Repo A and B, it should work it all out.
I think this maybe sounds a bit similar to what you want to do, so I thought I'd post the link in case was helpful and you hadn't already seen it How do I use a Git submodule with a Composer loaded library?
You should use a .gitignore file containing something like that:
web/bundles/
app/cache/*
app/logs/*
app/sessions/*
build/
vendor
When developing you should launch php composer.phar update from time to time. When your work is validated, you should commit the composer.lock file with your development.
When deploying, you can then just launch php composer.phar install.

Download a repository in Github along with composer packages

Without using Composer, is it possible to download a repository in Github along with it's defined composer packages?
For example: FluxBB 2 requires Laravel 4.
I was hoping to download FluxBB and at the same time the packages of Laravel 4 without using Composer.
Usually projects that use composer will ignore 3rd party components. In .gitignore you will see /vendor. This is the place where Composer downloads its dependencies.
This will find the latest version of monolog/monolog that matches the supplied version constraint and download it into the vendor directory. It's a convention to put third party code into a directory named vendor. In case of monolog it will put it into vendor/monolog/monolog.
Tip: If you are using git for your project, you probably want to add vendor into your .gitignore. You really don't want to add all of that code to your repository.
http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies
Doing it manually is a bit of a hassle. Composer uses packagist to get its files (if you look at a package it has a source added to it Laravel https://packagist.org/packages/laravel/framework).
Composer auto loads the needed files automatically so its a big time saver.
For libraries that specify autoload information, Composer generates a vendor/autoload.php file. You can simply include this file and you will get autoloading for free.
require 'vendor/autoload.php';
This makes it really easy to use third party code. For example: If
your project depends on monolog, you can just start using classes from
it, and they will be autoloaded.
http://getcomposer.org/doc/01-basic-usage.md#autoloading

CakePHP and Composer installs -- how to use it for Plugin and Vendor dependencies for a CakePHP 2.x application

I am having some weird issues with git submodule update for a Plugin dependency with Jenkins # CloudBees.
So I am switching some, if not, all my dependencies from git submodule to Composer.
I came across this repo called composer installers. https://github.com/composer/installers
I was wondering how to use this for both Plugin and Vendor dependencies.
I am not familiar with Composer and even after reading the docs, I am uncertain how to say, place this dependency specifically to Plugin/xxx
I know how to do this with git submodule add.
So anyone knows how I should use Composer or better yet, Composer installers, please advise me.
To make things easier, I want to use 2 actual examples.
https://github.com/milesj/Utility is to be placed inside my app/Plugin/Utility
https://github.com/simkimsia/php-gd-simpleimage is to be placed inside my app/Vendor/SimpleImage
There is a Composer plugin for CakePHP that has a Backery article about it. The code is available on Github:
https://github.com/uzyn/cakephp-composer
It's actively being developed (last commit was yesterday), but in my early use of it (today), it seems to be working as expected.
Packagist has loads of Compose-ready libraries. Some of them are CakePHP related. Some are not.
The two examples you listed aren't in Packagist (yet?). Thankfully, Composer makes it possible to work directly with Git (and other VCS) repos. For the milesj/Utility plugin (which has a composer.json file), you'll need to follow the Repositories guide in the Composer docs to set things up properly.
For the php-gd-simpleimage repo, you'll need to write a composer.json file, then follow the Repositories steps.
One of the most confusing things about Composer is that composer.json is the same system/file-format for both libraries and "projects." Really, they're all the same to Composer. In your "project" repo, though, you're only outlining requirements (usually), not making your application installable via Composer. Regardless of their locations, both composer.json files are for the same thing: tracking and installing dependencies. You can imagine it as a tree with your project (and it's composer.json) at the top, and then a branching dependency tree all the way down.
Happy Composing!

Categories