Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 6
ConnectionOptions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 6
 getOptionName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getOption
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 isOption
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Ldap\Adapter\ExtLdap;
13
14use Symfony\Component\Ldap\Exception\LdapException;
15
16/**
17 * A class representing the Ldap extension's options, which can be used with
18 * ldap_set_option or ldap_get_option.
19 *
20 * @author Charles Sarrazin <charles@sarraz.in>
21 *
22 * @internal
23 */
24final class ConnectionOptions
25{
26    public const API_INFO = 0x00;
27    public const DEREF = 0x02;
28    public const SIZELIMIT = 0x03;
29    public const TIMELIMIT = 0x04;
30    public const REFERRALS = 0x08;
31    public const RESTART = 0x09;
32    public const PROTOCOL_VERSION = 0x11;
33    public const SERVER_CONTROLS = 0x12;
34    public const CLIENT_CONTROLS = 0x13;
35    public const API_FEATURE_INFO = 0x15;
36    public const HOST_NAME = 0x30;
37    public const ERROR_NUMBER = 0x31;
38    public const ERROR_STRING = 0x32;
39    public const MATCHED_DN = 0x33;
40    public const DEBUG_LEVEL = 0x5001;
41    public const TIMEOUT = 0x5002;
42    public const NETWORK_TIMEOUT = 0x5005;
43    public const X_TLS_CACERTDIR = 0x6003;
44    public const X_TLS_CERTFILE = 0x6004;
45    public const X_TLS_CRL_ALL = 0x02;
46    public const X_TLS_CRL_NONE = 0x00;
47    public const X_TLS_CRL_PEER = 0x01;
48    public const X_TLS_KEYFILE = 0x6005;
49    public const X_TLS_REQUIRE_CERT = 0x6006;
50    public const X_TLS_PROTOCOL_MIN = 0x6007;
51    public const X_TLS_CIPHER_SUITE = 0x6008;
52    public const X_TLS_RANDOM_FILE = 0x6009;
53    public const X_TLS_CRLFILE = 0x6010;
54    public const X_TLS_PACKAGE = 0x6011;
55    public const X_TLS_CRLCHECK = 0x600b;
56    public const X_TLS_DHFILE = 0x600e;
57    public const X_SASL_MECH = 0x6100;
58    public const X_SASL_REALM = 0x6101;
59    public const X_SASL_AUTHCID = 0x6102;
60    public const X_SASL_AUTHZID = 0x6103;
61    public const X_KEEPALIVE_IDLE = 0x6300;
62    public const X_KEEPALIVE_PROBES = 0x6301;
63    public const X_KEEPALIVE_INTERVAL = 0x6302;
64
65    public static function getOptionName(string $name): string
66    {
67        return sprintf('%s::%s', self::class, strtoupper($name));
68    }
69
70    /**
71     * Fetches an option's corresponding constant value from an option name.
72     * The option name can either be in snake or camel case.
73     *
74     * @throws LdapException
75     */
76    public static function getOption(string $name): int
77    {
78        // Convert
79        $constantName = self::getOptionName($name);
80
81        if (!\defined($constantName)) {
82            throw new LdapException(sprintf('Unknown option "%s".', $name));
83        }
84
85        return \constant($constantName);
86    }
87
88    public static function isOption(string $name): bool
89    {
90        return \defined(self::getOptionName($name));
91    }
92}