To what extent Laravel uses composer? - laravel

I try to run Laravel on a server that doesn't provide composer. I am aware of these issues which I've resolved:
1) Problem: installing the framework
Solution: installed on local machine and copied files over.
2) Problem: installing packages
Solution: installed them mannually by adding files and modifying autoloader files.
3) Problem: creating and rolling back migrations via artisan
Solution: not found yet. Probably new classes need to be manually added in composer autoloader file.
Is there any more tasks where composer is necessary? I'd like to know to what extent the framework really relies on in before starting development.

Related

PHP-library installation via composer

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.

Mozilla Nunjucks composer package

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.

How to update CodeIgniter with Composer?

I switched from Symfony to CodeIgniter and I would like it to stay up-to-date with the framework.
I understand that you can easely install and update all kind of packages, I know how to do it as I did it over and over again with Symfony.
I already set $config['composer_autoload'] = TRUE; in application/config/config.php. (Thanks to a lot of other SO questions)
My problem: Composer seems to update all the packages fine, but not the framework itself. Is it possible or am I doomed to do it manually?
EDIT
Please consider using CodeIgniter 4, which is made to be used with Composer from the start. CodeIgniter 3 is old and should only be used on legacy projects.
You can update your codeigniter using composer by below method:
$ cd /path/to/codeigniter
$ composer update
Here you can get more info about this
CodeIgniter hasn't been made as a composer packageā€¦ except that someone eventually did it anyway!
It is possible to keep CodeIgniter up-to-date by installing it throught composer in the first place. The project is hosted on GitHub.
In order to use it, it's quite easy: composer create-project kenjis/codeigniter-composer-installer codeigniter should do the trick!

Laravel Download and Installation

I'm a webdeveloper and I'm starting a huge project requested by a company.
I'm trying to figure out if is best to use a PHP framework or not, and in case, which one.
I know Codeigniter, but I wanted to look around to see what's the best framework at the moment. I found out Laravel is trending at the top so I wanted to try it out.
Being used to Codeigniter I usually download the zip file with all the phps inside and start working. I'm trying to do the same with Laravel but I saw you are to download and use composer to install it.
I'm not really used to the Terminal and I wanted to ask if that's the only way of installing it or if there is a downloadable version as in Codeigniter, CakePHP, etc...
You can always download the ZIPped code directly from project's GitHub site. You can find the base application here: https://github.com/laravel/laravel - you'll find a link at the bottom of the right column. This code is what composer downloads when you use that to setup the application.
If you want to use Laravel you will have to use Composer as this is what the application uses to manage its dependencies. It's not hard, as you'll only need to run a few commands.
You can learn more about how to install and use composer in the docs: https://getcomposer.org/download/

CodeIgniter: Using Composer libraries without composer

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.

Resources