<commit_before><?php

namespace Tedivm\StashBundle\Factory;
use Stash\Drivers;

class HandlerFactory {

    static function createHandler($types, $options)
    {
        $handlers = Drivers::getDrivers();

        $h = array();

        foreach($types as $type) {
            $class = $handlers[$type];
            $opts = isset($options[$type]) ? $options[$type] : array();
            $h[] = new $class($opts);
        }

        if(count($h) == 1) {
            return reset($h);
        }

        $class = $handlers['Composite'];
        $handler = new $class(array('drivers' => $h));

        return $handler;
    }
}<commit_msg>Fixed Memcache server configuration. Now passes server specs as normal arrays and not hashes.<commit_after><?php

namespace Tedivm\StashBundle\Factory;
use Stash\Drivers;

class HandlerFactory {

    static function createHandler($types, $options)
    {
        $handlers = Drivers::getDrivers();

        $h = array();

        foreach($types as $type) {
            $class = $handlers[$type];
            if ($type === 'Memcache' && isset($options[$type])) {
                // Fix servers spec since underlying drivers expect plain arrays, not hashes.
                $servers = array();
                foreach ($options[$type]['servers'] as $serverSpec) {
                    $servers[] = array(
                        $serverSpec['server'],
                        $serverSpec['port'],
                        isset($serverSpec['weight']) ? $serverSpec['weight'] : null
                    );
                }

                $options[$type]['servers'] = $servers;
            }

            $opts = isset($options[$type]) ? $options[$type] : array();
            $h[] = new $class($opts);
        }

        if(count($h) == 1) {
            return reset($h);
        }

        $class = $handlers['Composite'];
        $handler = new $class(array('drivers' => $h));

        return $handler;
    }
}
{'fraction_non_alphanumeric': 0.15329218106995884, 'fraction_numerical': 0.00102880658436214, 'mean_word_length': 1.8602941176470589, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5800200', 'n_tokens_mistral': 556, 'n_tokens_neox': 527, 'n_words': 121}