Some PHP-libraries can be used after installing them via composer.
What this mean?
Is that only way to use those libraries or is there a way to use them copying the code in to correct location and referring them in the code?
Examples:
mPDF can be used (only?) via composer
https://mpdf.github.io/
PHPMailer can be used just copying files in correct location and referring to them
https://github.com/PHPMailer/PHPMailer
The thing with libraries is, that they might require other libraries and those libraries might require other libraries and so on. So downloading them and putting them in some location will be tedious and when two libraries require the same library in a different version you will run into problems. Composer will solve this issue for you by figuring out which libraries are needed to resolve all requirements and make sure to download a version that fits all or raise an error that the current collection of libraries contains incompatible libraries and which ones.
The other problem is finding the right location to store those libraries since PHP has to figure out where each class is stored you will either have to add require/include statements to your code and libraries which is tedious and will complicate future updates, e.g. when classes are renamed or removed. A way around this is is having a shared lib directory, but then you will run into problems when you have multiple projects requiring different library versions.
For libraries composer is the de facto standard and you will always need/want to install libraries in your project with it. It takes care of resolving correct versions, autoloading and updating making it incredibly helpful, especially if you were still around when composer was not a thing. I would use it even if I need no libraries just for the autoloading and the ability to later add libraries, when my project grows/changes.
edit: Even PHPMailer provides a composer.json even though it does not require other libraries, but if you install it via composer you can make sure that your system fulfills the requirements (PHP version & installed extensions) which you might miss otherwise, leading to a possibly long debugging session figuring out why some feature won't work.
edit You can use composer for projects on shared hosting as well. Instead of running the command on the server, you must then run it on your local machine or build server for the actual server. You can copy your project including the vendor folder to your shared host and things should work. The vendor folder contains all libraries and the autoload.php and can be copied along with your code.
In order to do that reliably, in your composer.json under config you can specify the platform you will run your code on. You should define the correct PHP version at the very least, but the installed extensions as well, to make sure you don't accidentally install libraries where you don't have the required extension. When you run composer install or composer update it will use these platform details as a basis to download libraries that match them. This is especially important when you have PHP 7 installed, but your host does not have it yet.
When running composer on a separate server than the one that uses code, a few options will not work like --apcu-autoloader, but you probably don't use them anyway.
If you run composer on your local machine and copy stuff over, you can improve the experience a bit by adding a few options to your composer install:
composer install --no-dev --prefer-dist --classmap-authoritative
You can get details about these options in the documentation. The important things are:
--no-dev, to possibly reduce the number of libraries downloaded to the ones needed for production (because we only want to run the project on our server not develop on it).
--prefer-dist (why is explained in the docs)
--classmap-authoritative or --optimize-autoloader, (the first might not work with some projects/libraries) but it will improve autoloading making your application a teeny, tiny bit faster in production
The first 2 options, you should not run if you copy your development environment, as they will not provide all dependencies for development. Maybe setup a second project that is just used for checking out the latest changes from git, running tests to make sure everything works, then removing vendor & running that command, (possibly make some changes to the config for prod) and finally copy things to your shared hosting environment. If you use something like gitlab that provides CI-capabilities, you could also do these steps on the ci-server and let that copy stuff, but it takes some time to set things up.
Related
I'm kinda new to using composer (but I think it is awesome) so please pardon the noob question.
Folks are requesting exports fancier than csv so I thought I'd install phpOffice excel using composer. But, the master is 'build failing' and the develop is 'build error'. An I correct in assuming the master build failed means I should not install this with composer because it won't work?
In researching this I also found phpOffice spreadsheet, but that appears to be in development still.
Any other alternatives if I cannot use phpOffice excel due to the build status issue?
Regardless of what package you are talking about, if the builds for any of the branches are failing it just means that the builds for any of the branches are failing, that's it.
The master and develop branches may be well ahead of the latest tag, and chances are the maintainers are experimenting with it, and working towards a passing build again.
If you trust the maintainers not to release broken software, then it's safe to use one of the tagged versions, so for example, run
$ composer require phpoffice/phpexcel:^1.8.1
to install the latest stable version.
Note It appears that phpoffice/phpexcel:1.8.1 has been released on 2015-05-01; quite some time has passed since. Whether or not this package works for you, then, is something you have to find out for yourself.
For reference, see:
https://packagist.org/packages/phpoffice/phpexcel
Is it possible to include Nunjucks in a project with Composer?
Or do I have to download it manually?
No, you cannot install it via Composer, as it is a PHP dependency manager, used almost exclusively for PHP packages (which Nunjucks is obviously not). It's not impossible for non-PHP packages to be installable via Composer, but that's a rare occasion.
As a general rule of thumb, to check Composer availability - look at the source code repository and see if a file named composer.json exists.
But that doesn't mean you have to download it by hand, as there's an equivalent solution for JavaScript packages - NPM; and Mozilla have made it available there.
In drupal 8, I am encountering modules that require libraries to be installed by Composer. However, I was wondering if I could skip the composer part and just install the libraries by hand.
Would I ever be able to do this?
(I have never gotten Composer to work)
Just extract the library at /libraries.
For colorbox, you should have root/libraries/colorbox/jquery.colorbox-min.js
But this way you miss the main purpose of composer cause it won't be possible to update all the dependence automatically.
I have a project where I can't install or use composer.
However, I want to use the OmniPay library, which is a composer package. So I want to just take the libraries out and use them as standard libraries in Code Igniter.
This is what I get from the Composer install (below). If I take them into my application/libraries/ folder, how can i load them into my controller?
I think the easiest way would be to actually USE Composer on the machine you are developing on, and then commit the vendor folder to the repository.
If you don't want to do this, you'd have to manually do the steps Composer does. And this is more complicated than you think:
The last steps would be to extract the source from the package, put it somewhere suitable, and recreate the autoloading for it. This is the easy step, because the autoloading usually is PSR-0 or PSR-4. "Onmipay/Common" has one addtional class that doesn't fit into this and is loaded as classmap by Composer, so this class has to be handled extra.
The more complicated step before this: Omnipay is also using "guzzle/http" as a HTTP client, and "symfony/http-foundation". These packages also need to be included both as a file and then with their respective autoloading. And these also have dependencies with autoloading and dependencies...
Let Composer do the error-prone work, and commit the vendor folder if you can't provide the infrastructure to add the dependencies later during deployment.
I am used to Drupal, and it is fairly clear with Drupal which modules are on a server. I am new to phpBB and looking to learn just enough to migrate an install to Drupal. I can see that phpBB has 'modules' but I can't see how to tell which modules are are Installed or enabled.
From what I can see, installing modules in phpbb3 is a lot of hacking flies in the install, is this true? Is there a way to tell what is installed. even if I have to run some grep over the code?
Installing modules is 'complicated' in PHPBB3. However, anything in the MOD Database can be installed (or uninstalled) using AutoMOD. This should make your life easier if you are looking for mods in the MOD Database. The 'complicated' part of the install is any Do-It-Yourself instructions. You have to execute these by hand. This is the 'hacking files' that you mentioned. It seems to be fairly common in the 3.0.x versions of PHPBB. 3.1 is supposed to reduce this, but PHPBB development is slow. 3.1 entered feature freeze in July of 2010
A basic tutorial to install a mod using AutoMOD is available.
AutoMOD also allows you to see which modules have been installed (using AutoMOD). If you manually installed something by hacking through the install script yourself, it won't appear on this list.