<commit_before><?php
/**
 * This file is part of the PPI Framework.
 *
 * @copyright   Copyright (c) 2012 <NAME> <<EMAIL>>
 * @license     http://opensource.org/licenses/mit-license.php MIT
 * @link        http://www.ppi.io
 */
namespace PPI\ServiceManager\Config;

use Zend\ServiceManager\ServiceManager;

/**
 * ServiceManager configuration for the Session component.
 *
 * @author     <NAME> <<EMAIL>>
 * @package    PPI
 * @subpackage ServiceManager
 */
class SessionConfig extends AbstractConfig
{
    /**
     * {@inheritdoc}
     */
    public function getDefaultOptions()
    {
        return array(

        // internal configuration
        'app.session.class'                     => 'Symfony\Component\HttpFoundation\Session\Session',
        'app.session.storage.class'             => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
        'app.session.flashbag.class'            => 'Symfony\Component\HttpFoundation\Session\Flash\FlashBag',
        'app.session.attribute_bag.class'       => 'Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag',
        'app.session.storage.native.class'      => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
        'app.session.handler.native_file.class' => 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler',

        // user level configuration
        'session'                               => array(
            'storage_id'                        => 'session.storage.native',
            'handler_id'                        => 'session.handler.native_file',
            'name'                              => null,
            'cookie_lifetime'                   => null,
            'cookie_path'                       => null,
            'cookie_domain'                     => null,
            'cookie_secure'                     => null,
            'cookie_httponly'                   => null,
            'gc_divisor'                        => null,
            'gc_probability'                    => null,
            'gc_maxlifetime'                    => null,
            'save_path'                         => '%app.cache_dir%/sessions'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function configureServiceManager(ServiceManager $serviceManager)
    {
        $serviceManager->getOptions()->add($this->getDefaultOptions());

        $config = $serviceManager->getOption('session');

        // session storage
        $serviceManager->setOption('app.session.storage', $config['storage_id']);

        $options = array();
        foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'gc_maxlifetime', 'gc_probability', 'gc_divisor', 'save_path') as $key) {
            // @todo - the default values are null, so isset() fails, make sure this is intentional
            if (isset($config[$key])) {
                $options[$key] = $config[$key];
            }
        }

        $serviceManager->setOption('app.session.storage.options', $options);

        // session handler (the internal callback registered with PHP session management)
        $serviceManager->setFactory('session.handler', function($serviceManager) use ($config) {
            if (null == $config['handler_id']) {
                // Set the handler class to be null
                return null;
            } else {
                return $serviceManager->get($config['handler_id']);
            }
        });

        // session storage native
        $serviceManager->setFactory('session.storage.native', function($serviceManager) {
            $class = $serviceManager->getOption('app.session.storage.native.class');

            return new $class(
                $serviceManager->getOption('app.session.storage.options'),
                $serviceManager->get('session.handler')
            );
        });

        // session flash bag
        $serviceManager->setFactory('session.flash_bag', function($serviceManager) {
            $class = $serviceManager->getOption('app.session.flashbag.class');<commit_msg>Allows session options to be overwritten by user config<commit_after><?php
/**
 * This file is part of the PPI Framework.
 *
 * @copyright   Copyright (c) 2012 <NAME> <<EMAIL>>
 * @license     http://opensource.org/licenses/mit-license.php MIT
 * @link        http://www.ppi.io
 */
namespace PPI\ServiceManager\Config;

use Zend\ServiceManager\ServiceManager;

/**
 * ServiceManager configuration for the Session component.
 *
 * @author     <NAME> <<EMAIL>>
 * @package    PPI
 * @subpackage ServiceManager
 */
class SessionConfig extends AbstractConfig
{
    /**
     * {@inheritdoc}
     */
    public function getDefaultOptions()
    {
        return array(

        // internal configuration
        'app.session.class'                     => 'Symfony\Component\HttpFoundation\Session\Session',
        'app.session.storage.class'             => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
        'app.session.flashbag.class'            => 'Symfony\Component\HttpFoundation\Session\Flash\FlashBag',
        'app.session.attribute_bag.class'       => 'Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag',
        'app.session.storage.native.class'      => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
        'app.session.handler.native_file.class' => 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler',

        // user level configuration
        'session'                               => array(
            'storage_id'                        => 'session.storage.native',
            'handler_id'                        => 'session.handler.native_file',
            'name'                              => null,
            'cookie_lifetime'                   => null,
            'cookie_path'                       => null,
            'cookie_domain'                     => null,
            'cookie_secure'                     => null,
            'cookie_httponly'                   => null,
            'gc_divisor'                        => null,
            'gc_probability'                    => null,
            'gc_maxlifetime'                    => null,
            'save_path'                         => '%app.cache_dir%/sessions'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function configureServiceManager(ServiceManager $serviceManager)
    {
        $userOptions = $serviceManager->getOptions()->has('session') ?
            $serviceManager->getOptions()->get('session') : array();
        $serviceManager->getOptions()->add($this->getDefaultOptions());

        $config = $serviceManager->getOption('session');

        // session storage
        $serviceManager->setOption('app.session.storage', $config['storage_id']);

        $options = array();
        foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'gc_maxlifetime', 'gc_probability', 'gc_divisor', 'save_path') as $key) {
            // @todo - the default values are null, so isset() fails, make sure this is intentional
            if (isset($userOptions[$key])) {
                $options[$key] = $userOptions[$key];
            } else if (isset($config[$key])) {
                $options[$key] = $config[$key];
            }
        }

        $serviceManager->setOption('app.session.storage.options', $options);

        // session handler (the internal callback registered with PHP session management)
        $serviceManager->setFactory('session.handler', function($serviceManager) use ($config) {
            if (null == $config['handler_id']) {
                // Set the handler class to be null
                return null;
            } else {
                return $serviceManager->get($config['handler_id']);
            }
        });

        // session storage native
        $serviceManager->setFactory('session.storage.native', function($serviceManager) {
            $class = $serviceManager->getOption('app.session.storage.native.class');

            return new $class(
                $serviceManager->getOption('app.session.storage.options'),
                $serviceManager->get('session.handler')
            );
        });

        // session flash bag
        $serviceManager->setFactory('session.flash_bag', function($serviceManager) {
            $class = $serviceManager->getOption('app.session.flashbag.class');
{'fraction_non_alphanumeric': 0.1288171288171288, 'fraction_numerical': 0.000936000936000936, 'mean_word_length': 1.9742519137091161, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206003', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2096, 'n_words': 386}