Mozilla Nunjucks composer package - composer-php

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.

Related

install introduction package in TYPO3 11 with composer

TYPO3 11 LTS with composer.
I tried:
composer require typo3/cms-introduction
the introduction package and bootstrap package are loaded.
Then i tried:
vendor/bin/typo3 extension:setup
but nothing happens. In the extensions manager i can see both extensions but no page in the page tree, nothing in the backend.
There are different descriptions out in the world:
composer exec typo3 extension:setup
results in this error message:
Script typo3 handling the __exec_command event returned with error code 255
It seems impossible to install the introduction package in TYPO3 11 with composer.
Any hints?
Thanks
Peter
I use always
vendor/bin/typo3cms install:setup
vendor/bin/typo3cms install:extensionsetupifpossible
and never had any problems, it requires this though:
"helhum/typo3-console": "^7.0.2"
I tested it with the introduction package too and the pages are created. The frontend is directly shown correctly after this.
My setup was completely based on composer, so there is no general problem to install the introduction package by composer.
If you want to repair the installation, keep care about the hint in the installation instruction:
If you want to re-install ext:introduction on an instance that had ext:introduction
loaded before, the data import is only performed if you (manually) remove the keys
marked with extensionDataImport in column entry_namespace from database table
sys_registry that are related to the introduction paths.
Note it is often easier to just install TYPO3 from scratch if you just want to play around.
TYPO3 and composer
Documentation related to composer is included in several documents:
TYPO3 installation
There exist two distributions that can be installed:
minmal is a very slim collection of system extensions.
base-distribution is a collection with most of the common system extensions.
naturally it's also possible to start with an individual composer.json file that is defining an own set of system extensions, so the packages above wouldn't be used.
It's also possible to install just an extension by composer without having installed TYPO3 before, then TYPO3 gets automatically installed as dependency if the extension defines at least one system extension as dependency.
Minor TYPO3 upgrade
Major TYPO3 upgrade
Explanation of composer.json for TYPO3
Furthermore there is an online helper for composer that makes it easier to collect all the desired packages for commandline:
https://get.typo3.org/misc/composer/helper
Note that it's not always better to install more packages and that not every package is available for every TYPO3 version.
typo3-console
The manual for the typo3-console can be found here:
https://docs.typo3.org/p/helhum/typo3-console/7.1/en-us/
You can switch the version in the top left corner of the manual.
The typo3-console can be used for non-composer installations too, it can be downloaded here:
https://extensions.typo3.org/extension/typo3_console
https://github.com/TYPO3-Console/TYPO3-Console/tags
TYPO3 v12
For TYPO3 v12 the typo3-console is not compatible yet (Oct. 7, 2022), so some steps in the install-process have to be done manually and are not available yet by command line.
All composer commands can be used and are not concerned by the missing console. Just in composer.json files usually this block is used and has to be removed until typo3-console is compatibel to v12:
"scripts":{
"typo3-cms-scripts": [
"typo3cms install:fixfolderstructure"
],
"post-autoload-dump": [
"#typo3-cms-scripts"
]
},

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.

How to install a "composer mode only" extension in "non-composer" TYPO3

The question says it all. I'd like to install https://github.com/lochmueller/staticfilecache in a non-composerified TYPO3 instance. What is the recommended procedure?
I thought I could download the source, cd into it and then do composer install on the command line and then I would get the complete extension. But I didn't see that worked.
You could ask the author to add support for the TYPO3 Classic Mode which basically means embedding dependencies for extension packages uploaded to the TER. There is no other way to achieve this in Classic Mode, thus obviously I strongly recommend switching to Composer Mode.

Requiring a package in composer that is not PSR compliant

I'd like to just pull the following package in using composer so it will be autoloaded, but can't figure out how (or if) that can be done:
https://code.google.com/p/freshbooks-php-library/
Is this possible, and if so, how?
I know the question is a little old, but I don't think you can include packages, archives or libraries without the target resource containing a (valid) composer.json in the project root.
However; Google has given me this repo https://github.com/Isinlor/freshbooks-php which would seem to do the trick.

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