PHP framework for LTB project applications

v0.1.0 2023-04-24 13:24 UTC

This package is auto-updated.

Last update: 2024-04-08 13:26:09 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads

Presentation

This is a PHP library to share code between LTB applications like Self Service Password, White Pages, Service Desk, ...

Installation

Add the dependency in your composer configuration:

{
    "require": {
        "ltb-project/ldap": "v0.1"
    }
}

Then update dependencies:

composer update

Use autoloading in your code to load composer dependencies:

require __DIR__ . 'vendor/autoload.php';

Usage

LDAP connection

$ldap_url = "ldap://ldap.example.com";
$ldap_starttls = false;
$dn = "cn=admin,dc=example,dc=com";
$password = "secret";
$ldap_network_timeout = 3;

$ldap_connection = \Ltb\Ldap::connect($ldap_url, $ldap_starttls, $dn, $password, $ldap_network_timeout);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];

if (!$result) {
    error_log("Unable to connect to $ldap_url");
    exit 1;
}

Tests

Unit tests

Get composer dependencies:

composer update

Run the tests:

vendor/bin/phpunit tests/Ltb

If you want coverage analysis, make sure to install xdebug PHP extension, and run:

XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --configuration phpunit.xml

Integration tests

Make sure you have docker or podman installed

Get composer dependencies:

composer update

Run the tests (requires an internet connection for donwloading the openldap docker image):

./runIntegrationTests.sh

If you already have an openldap server, you can also adapt the tests in tests/ directory, and run them with:

vendor/bin/phpunit tests/IntegrationTests