CoreFiles by mySites.guru
AbstractConnection.php54 lines, 1,709 bytes, from Joomla_6.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.4.0-beta3
md5
e6867e2acd98c11f80149e03df7dcc24
sha1
05b911b3a5fd7d44f1e3f934a824acac5a13d054
sha256
f99a68f32c4fc836ca16c602845efd093d2a3d707578a8c57f8bdace8a175cc5
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Ldap\Adapter;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * @author Charles Sarrazin <[email protected]>
 */
abstract class AbstractConnection implements ConnectionInterface
{
    protected array $config;

    public function __construct(array $config = [])
    {
        $resolver = new OptionsResolver();

        $this->configureOptions($resolver);

        $this->config = $resolver->resolve($config);
    }

    protected function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'host' => 'localhost',
            'version' => 3,
            'connection_string' => null,
            'encryption' => 'none',
            'options' => [],
        ]);

        $resolver->setDefault('port', fn (Options $options) => 'ssl' === $options['encryption'] ? 636 : 389);

        $resolver->setDefault('connection_string', fn (Options $options) => \sprintf('ldap%s://%s:%s', 'ssl' === $options['encryption'] ? 's' : '', $options['host'], $options['port']));

        $resolver->setAllowedTypes('host', 'string');
        $resolver->setAllowedTypes('port', 'numeric');
        $resolver->setAllowedTypes('connection_string', 'string');
        $resolver->setAllowedTypes('version', 'numeric');
        $resolver->setAllowedValues('encryption', ['none', 'ssl', 'tls']);
        $resolver->setAllowedTypes('options', 'array');
    }
}

The same content is in 38 releases, Joomla 6.0.0-beta1 to 6.2.0-alpha1. See them all, or every version of this file.