CoreFiles by mySites.guru
AbstractConnection.php63 lines, 1,918 bytes, from Joomla_4.0.0-alpha6-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha5
md5
c279cbb0d564f00559884c699d6c81b3
sha1
ff9ff0cac7f8f09c2fdf5def7268fbdd619f96cc
sha256
ea29b741e55f1aefc0863a323e9c43f445490ab9f0529e22761a80276e4f9d0e
<?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 $config;

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

        $this->configureOptions($resolver);

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

    /**
     * Configures the adapter's options.
     *
     * @param OptionsResolver $resolver An OptionsResolver instance
     */
    protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'host' => 'localhost',
            'version' => 3,
            'connection_string' => null,
            'encryption' => 'none',
            'options' => array(),
        ));

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

        $resolver->setDefault('connection_string', function (Options $options) {
            return 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', array('none', 'ssl', 'tls'));
        $resolver->setAllowedTypes('options', 'array');
    }
}

The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.