Installing Intervention Image without composer - php

I would like to test Intervention Image. It looks like a nice package. The installation instructions say:
The best way to install Intervention Image is quickly and easily with
Composer.
The sentence above implies there's also a inferior, slower and difficult, way to install it. I assume the author is referring to an installation without Composer? That is exactly what I am looking for!
However, I am unable to find a way to do that. I have looked for an autoloader file, or even any autoload call in the code. There's none. No documentation either. It seems that only an installation with Composer is supported in a meaningful way.
Has anybody of you tried to use Intervention Image without resorting to Composer?

The way without composer is simply to fetch the source from github, move it in one off your vendor directories and load all needed files.
As there's no autoload file provided inside the package, you have to extend your own autoload script or register a new autoload handler, as including each required file is a really annyoing task.
If you take a deeper look inside the composer.json file, you may notice inside the require section, that this package also need Guzzle. If you want to install Guzzle, you will again read the sentence "The recommended way to install Guzzle is through Composer". So you have to do the same thing again for Guzzle. This time you need the other two Guzzle dependencies psr7 and promises....
At this point, I hope you build your autoloader robust enough to simply add only a new mapping from namespace prefix to path, as their might be many other required packages.
If you don't want to include composer directly inside your project, for what reasons ever, you could also create a empty composer project, just for managing the dependencies and the autoloader. That might be easier to do everything by hand.
Note: If you are lucky, you could use the Intervention/Image package
without the guzzle dependency.

Related

PHP Composer: Require at least one dependency or another?

I'm writing a new composer.json file for a project so that it can be available or Packagist or direct reference to its GitHub repo. The project requires either one or both of the HTTP client extensions, pecl_http or curl. If I specify both of the packages under require, Composer will give an error if both are not installed.
How can I tell Composer it's okay to have just one of those two extensions installed?
You cannot define it in a way that you only need one of these extensions, but make Composer fail if none are present.
The usual way for packages is to mention extensions as "suggest". Your code already has to deal with detecting which extension is present and select the correct code path, it's no additional problem to emit an error if all are missing.
Alternatively, have two packages with their dependency exactly on one extension. Or have a main package on top of that which suggests the two implementation packages and makes it clear via it's interface that the developer has to provide at least one implementation.
On the other hand: Dealing with HTTP stuff looks like you should probably rely on PSR-7 interfaces, and let the developer choose the HTTP client implementation to use.

How to choose the right Composer packages?

I'm a bit confused about using Composer.
I have built my own package manager, that uses a config-file and a large SVN-repo that contains all possible libraries (both PHP and Javascript / CSS) I need in several different projects. I download these packages myself from the library websites.
Now I'm trying to use Composer instead, since I like the automatic dependency checking and want to use something that everybody else does. But how do you decide what packages are best?
For example, for CodeMirror, I used to download the latest stable version from https://codemirror.net/ . But when I look in Packagist I see so many different versions that I don't know which to choose. It seems everybody can create new packages for Composer ? I just need the official ones.
So, how do you guys pick the packages you need?
To answer your question directly, for any component you want to import into your project, the way to find the "canonical" source - as opposed to various forks - is to go back to the original source and see what their usage/install instructions suggest. If they support a Packagist-based install, they will usually say so. If not, but there is a composer.json in their (typically) Github repository, then you can add the repository to your composer.json and then require the package as normal.
However, more generally, I think there is some confusion about what Composer really does. As noted in the comments, Composer is a dependency manager for PHP. Packagist is the primary repository for composer-managed packages. The CodeMirror library you cited is fundamentally a javascript library.
Now it's true that if you search for "codemirror" on Packagist, you will see lots of results there, some of which are labeled as Javascript components. But they are primarily:
wrappers that allow consumers to interact with or simply load CodeMirror in PHP-based view-scripts, like conquer/codemirror for the Yii framework, or nitrado/code-mirror-bundle for the Symfony framework; or
shim repositories for the Components project - like components/jquery, for example - which are then installed using the command-line script from their Component Installer for Composer
Bottom line: Composer is primarily used for importing PHP packages. It takes some gymnastics - like the Component Installer for Composer noted above - to make it usable/helpful for non-PHP packages.

How to install specific files from a package using composer.json

I am writing a 1 page script to do a relatively simple task. So I decided to use Flourish Unframework which provides a bunch of cool classes that can used separately.
I only want to use specific classes, say fDatabase, however composer let's download the entire package!
I know I could just delete the unwanted files BUT is there a way that composer could just let me require specific files?
This is not what I am looking for because it's just autoload and note installing 1 file from an entire package.
please assist.
possible duplicate of this but has not been answered too!
Composer only allows installing the whole package. Only installing the files necessary to run the only one function you need is next to impossible to do in general, because the file/class you need might have code that needs one other class.
How to detect that class? Classes can be instantiated with variables, the classname could be concatenated with several strings. Composer would have to detect and possibly execute the code that creates class names.
If you are really concerned about uploading too much code, you could either search for a more appropriate package with less files, do the installation of this package yourself and remove the things you don't need, or simply just use it the way it is.

PHP Composer - How to work with multiple vendors?

The project I'm working on requires using the PHP SDK's from multiple 3rd parties. Two of these are Amazon Web Services and the Google API Client (for Google+), and both of them use Composer to manage their files / dependencies. I'm not sure how to best set it up code / structure wise, though, because I don't need both AWS and Google loaded together. I might need AWS in one area and Google in another, so I don't want to just autoload everything every time and have the additional overhead from libraries I don't need right then. Right now I have the structure set up like this:
awscode.php
googlecode.php
libs
composer.json
composer.lock
vendor
autoload.php
aws
google
So, everything Composer related is in a shared composer.json file, and all vendor files in the single vendor directory. But, I can't seem to find a way to just load up say AWS. It wants me to use the autoload.php from what I can tell, which seems to want to load up everything.
Do I need to set it up more like this if I want control over each library?
awscode.php
googlecode.php
libs
aws
composer.json
composer.lock
vendor
autoload.php
aws
google
composer.json
composer.lock
vendor
autoload.php
google
I'm obviously new to Composer and how to best utilize it, and want to make sure that I am setting it up the best way for both my situation, and for future management.
When using Composer, it only loads the classes when they are actually called in your code. To my knowledge this uses the PHP spl_autoload_register.
So in answer to your question, there won't be a significant extra overhead (if any).
Autoloading means that the file which defines a class gets read when you first use that class.
You should include all your project dependencies in one composer.json, they won't be loaded in files you don't use them in.

How can I safely add to a composer package?

I am using the Composer package Omnipay in my project and I want to add a new class to the package (in my case it is support for a new payment gateway). The naming does not conflict with anything and it follows the same naming and structure conventions as sibling folders. However, when I run composer update it deletes my whole folder of changes even though it didn't need to. Is there a way I can tell composer not to delete that directory?
Leave everything under /vendor alone, don't change any files there. You should treat libraries as external dependencies - don't check them into source control or change them in any way. Just reference them in your own code.
If you need to customize a composer library, you can either work around it in your own code (most PHP libraries support dependency injection, which will let you override any of the libraries' classes), or alternatively you can fork the library on github, then reference your own fork in composer.json, or submit the pull request so everyone can benefit from it.
As far as I'm aware, you cannot add to a Composer package as it is external and therefore out of your control. You should treat the packages as libraries only, and add all classes into your own project, ensuring that the packages you need are still set up in your .json file

Categories