Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0.0] Some misc updates / docs. #77

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ It supports encryption of the LDAP connection through TLS via the OpenSSL extens

# Documentation

**Note**: If you were previously using a version prior to `1.X`, see the [upgrade doc](UPGRADE-1.0.md) for important changes.

* [LDAP Client](/docs/Client)
* [Configuration](/docs/Client/Configuration.md)
* [SASL Bind Authentication](/docs/Client/SASL-Bind-Authentication.md)
Expand Down
79 changes: 73 additions & 6 deletions UPGRADE-1.0.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
Upgrading from 0.x to 1.0
=======================

Client Options
--------------
* [Client Changes](#client-changes)
* [Client Options](#client-options)
* [Server Changes](#server-changes)
* [Server Options](#server-options)
* [Constructing a Proxy Server](#constructing-a-proxy-server)
* [Using a Custom ServerRunner](#using-a-custom-serverrunner)

## Client Changes

### Client Options

When instantiating the `LdapClient`, options are now an options object instead of an associative array.

Expand Down Expand Up @@ -34,8 +42,9 @@ $ldap = new LdapClient(
);
```

Server Options
--------------
# Server Changes

## Server Options

When instantiating the `LdapServer`, options are now an options object instead of an associative array.

Expand Down Expand Up @@ -63,8 +72,7 @@ $ldap = new LdapServer(
);
```

Proxy Server Options
--------------------
## Constructing a Proxy Server

When instantiating an `LdapServer` instance with `LdapServer::makeProxy()`, options are now an options object instead
of an associative array.
Expand Down Expand Up @@ -109,3 +117,62 @@ $server = LdapServer::makeProxy(
->setPort(3389)
);
```

## Using a Custom ServerRunner

Previously, when constructing a `LdapServer` instance you could pass in a second param with an object implementing `ServerRunnerInterface`.
This is no longer a param on the constructor, you must set it in the ServerOptions.

**Before**:

```php
use FreeDSx\Ldap\LdapServer;
use App\MyServerRunner;

$ldap = new LdapServer(
[],
new MyServerRunner(),
);
```

**After**:

```php
use FreeDSx\Ldap\LdapServer;
use FreeDSx\Ldap\ServerOptions;

$ldap = new LdapServer(
(new ServerOptions)
->setServerRunner(new MyServerRunner())
);
```

## Using Request Handlers

Previously, you could have set request handlers using the fully qualified class name. These must now be class instances.

**Before**:

```php
use FreeDSx\Ldap\LdapServer;
use Foo\LdapProxyHandler;

$server = new LdapServer([
'request_handler' => LdapProxyHandler::class,
]);
$server->run();
```

**After**:

```php
use FreeDSx\Ldap\LdapServer;
use FreeDSx\Ldap\ServerOptions;
use Foo\LdapProxyHandler;

$server = new LdapServer(
(new ServerOptions)
->setRequestHandler(new LdapProxyHandler())
);
$server->run();
```
22 changes: 14 additions & 8 deletions src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@
*/
class ExtendedDnControl extends Control
{
public function __construct(private bool $useHexFormat = false)
{
parent::__construct(self::OID_EXTENDED_DN);
public function __construct(
private bool $useHexFormat = false,
string $controlType = self::OID_EXTENDED_DN,
bool $criticality = false,
) {
parent::__construct(
controlType: $controlType,
criticality: $criticality,
);
}

public function getUseHexFormat(): bool
Expand Down Expand Up @@ -73,11 +79,11 @@ public static function fromAsn1(AbstractType $type): static
$useHexFormat = ($useHexFormat->getValue() === 0);
}

$control = new static($useHexFormat);
$control->controlType = $oid;
$control->criticality = $criticality;

return $control;
return new static(
$useHexFormat,
$oid,
$criticality,
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/FreeDSx/Ldap/Control/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class Control implements ProtocolElementInterface, Stringable
public const OID_VLV_RESPONSE = '2.16.840.1.113730.3.4.10';

public function __construct(
protected string $controlType,
protected bool $criticality = false,
private string $controlType,
private bool $criticality = false,
protected AbstractType | ProtocolElementInterface | string | null $controlValue = null
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/FreeDSx/Ldap/Entry/EscapeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public static function escapeAll(string $value): string
/**
* Replace non-printable ASCII with escaped hex.
*/
protected static function escapeNonPrintable(string $value): string
private static function escapeNonPrintable(string $value): string
{
return (string) preg_replace_callback('/([\x00-\x1F\x7F])/', function ($matches) {
return '\\' . bin2hex($matches[1]);
}, $value);
}

protected static function shouldNotEscape(string $value): bool
private static function shouldNotEscape(string $value): bool
{
return (preg_match('/^(\\\\[0-9A-Fa-f]{2})+$/', $value) === 1 || $value === '');
}
Expand Down
2 changes: 1 addition & 1 deletion src/FreeDSx/Ldap/Entry/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class Option implements Stringable
{
protected const MATCH_RANGE = '/range=(\d+)-(.*)/';
private const MATCH_RANGE = '/range=(\d+)-(.*)/';

private ?string $lcOption = null;

Expand Down
Loading