6.0.0-git
2024-04-26
Last Modified 2019-02-14 by Ralf Lang

No More Pear: Move to composer

Remove any hard runtime or installation dependency on pear

Bugs

List any tickets on http://bugs.horde.org/ that cover this issue or are relevant to it.

People

Ralf Lang

Description

The PHP ecosystem has increasingly moved from pear to composer as the default installer. The changed paradigm (global versus local dependency management) attracts many users and developers.

Runtime dependencies

horde-db-migrate and web migrator

horde-db-migrate "forgets" to migrate or even acknowledge libraries in git checkouts where the pear channel is not present.
https://github.com/horde/Core/pull/2

l10n/translation tools?

Installation

Document .horde.yml format and how it relates to composer json and pear xml

Generate composer json file from .horde.yml

components/lib/Helper/Composer.php currently depends on conductor and gets its data from package.xml
anything handling package.xml is broken without pear though. Always need to register the horde channel

rewrite all pear.horde.org dependencies to vcs type dependencies github/horde/

https://github.com/horde/components/pull/3

Other resources
Do we want to keep a whitelist of other channels/packages which should be pulled from packagist or github rather than pear?

Composer plugin: install apps below base rather than vendor/

(we don't want /vendor/ web-readable)
horde apps are type "horde-application" and get installed to /$appname or base/appname
Installing/updating an app should clear cache and autoloader cache
Check if the app provides a registry snippet in /doc/
write horde.local.php if necessary
installing base should provide some initialization

Composer plugin: copy, move or link js content from libraries to horde/js

horde libs are type "horde-library" and get installed to /vendor/Horde/Foo
Maybe we find some trick

Packagist

Add tool chain to create and update packages on packagist for easier consumption.

Autoloading and fixed loading

Examining horde base bootstrapping:

horde/horde/index.php require_once lib/Application
Horde/Application.php require_once core.php
core.php checks for horde.local.php -- possible to announce a composer setup here
Either include_once Horde/Autoloader/Cache.php or require_once Horde/Autoloader/Default.php

Examining nag bootstrapping:

horde/nag/index.php and other client pages require_once nag/lib/Application.php
nag probes for horde_dir (either info from horde.local.php or directory above nag dir)
finally load (hordedir)/lib/core.php

-> both in base and apps, we can edit horde.local.php for hinting and autoloader ultimately comes from horde/lib/core.php

Issues with Horde_Autoloader_Default and Horde_Autoloader_Cache

Horde_Autoloader_Default has unconditional require_onces
Horde_Autoloader_Default registers unconditionally when loaded
Horde_Autoloader_Cache requires/registers Horde_Autoloader_Default unconditionally

Examining git-tools as a composer-native app:

git-tools binary detects the composer autoloader entrypoint vendor/autoload.php and require_once it.
the composer autoloader is configured to provide a psr-4 autoloader for the \\Horde\\GitTools namespace to ./lib

PSR-0 and packages

Most horde library packages are simple to map to the psr-0 autoloader.
Package Horde_Foo would have all its classes in lib/Horde/Foo.

Some packages though have class names you would not expect from the package name
Horde_Core has Horde_ErrorHandler & friends
Horde_Form has multiple classes in one file
Horde_Util has Horde_String

These either need to be scanned for additional mappings or need "classmap" style autoload hints.

We also need to think about db migrations and unit tests.

Resources

https://getcomposer.org/doc/articles/custom-installers.md composer notes on custom installers and plugins
https://github.com/composer/installers multi-framework collection of installers


Back to the Project List