/cot-package_connector

Cotonti plugin for testing «Package Connector» library

Primary LanguagePHP

🇷🇺 Russian version can be found here

PackageConnector

Plugin for CMF Cotonti. Provide smooth integration with packages installed to project with Composer (Dependency Manager for PHP).

Description

First of all Package Connector allow to use autoloader for all Composer installed packages. That is practical way to use installed PHP package without a headache with manual adding require / include directive with proper library paths.

Beside this it has interface to installed package info. Using it you can get info about package version, requirements (and other info provided by Composer package).

Features

  • Support and use Composer generated autoloader
  • Getting complete info about installed package (version, requirements, etc.)

Requirements

Current version 0.2.1 works with Cotonti Siena v0.9.18. (can work in older versions but not tested)

For use it needs at least composer.json located in base folder of working project (base folder with Cotonti install).

For getting info about installed packages there should be composer.lock file (normally generated by Composer itself after package installation):

composer install

or adding certain package to the project:

composer require "vendor/package"

Comments

Plugin works out right after had been installed and not require any addition settings.

How extension works

Inspite of PackageConnector class can be easily integrated right into the core it distributed now as a extension Plugin «package_connector».

Plugin utilizes main routines (see file package_connector.input.php) that serve class usage, like class initialization and data caching.

Plugin defines in a global scope variable $cot_packages — instance of PackageConnector class:

$cot_packages = new PackageConnector();

Class instance with necessary data are cached:

$cache && $cache->db->store('cot_packages', $cot_packages, 'system');

To eliminate needless initialization (with loading and parsing files data) class had stateChanged() method to check state of composer files. If state had changed you can reinitialize (setup) Connector once more:

if ($cot_packages->stateChanged()) $cot_packages->setup();

More detailed info for Class can be found on library repo «Package Connector»

Install

  • Unpack, copy files to root folder of your site.
  • Install via Admin → Extensions menu (Administration panel → Extensions)

Pay attention: file PackageConnector.php with library classes for PackageConnector should be located in system class folder system\classes.

Licence

Distributed under BSD license.

Author

Andrey Matsovkin

References