<commit_before><?php
/**
 * @package    Fuel\Session
 * @version    2.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2013 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Fuel\Session\Providers;

use Fuel\Session\Driver;

use Fuel\Dependency\ServiceProvider;


/**
 * FuelPHP ServiceProvider class for this package
 *
 * @package  Fuel\Session
 *
 * @since  1.0.0
 */
class FuelServiceProvider extends ServiceProvider
{
	/**
	 * @var  array  list of service names provided by this provider
	 */
	public $provides = array(
		'session',
		'session.native',
		'session.cookie',
		'session.file',
	);

	/**
	 * Service provider definitions
	 */
	public function provide()
	{
		// \Fuel\Session\Manager
		$this->register('session', function ($dic, $config = array())
		{
			// get the session config
			$stack = $this->container->resolve('requeststack');
			if ($request = $stack->top())
			{
				$app = $request->getApplication();
			}
			else
			{
				$app = $this->container->resolve('application.main');
			}

			// check if only a driver name or object is passed
			if ( ! is_array($config))
			{
				$config = array('driver' => $config);
			}

			$config = \Arr::merge($app->getConfig()->load('session', true), $config);

			// determine the driver to load
			if ($config['driver'] instanceOf Driver)
			{
				$driver = $config['driver'];
			}
			elseif (strpos('\\', $config['driver']) !== false and class_exists($config['driver']))
			{
				$class = $config['driver'];
				$driver = new $class($config);
			}
			else
			{
				$driver = $dic->resolve('session.'.strtolower($config['driver']), array($config));
			}

			$manager = $dic->resolve('Fuel\Session\Manager', array($driver, $config, $app));

			// start the session
			$manager->start();

			// and use the applications' event instance make sure it ends too
			$app->getEvent()->on('shutdown', function($event) { $this->stop(); }, $manager);

			// return the instance
			return $manager;
		});

		// \Fuel\Session\Driver\Cookie
		$this->register('session.cookie', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\Cookie', array($config));
		});

		// \Fuel\Session\Driver\Native
		$this->register('session.native', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\Native', array($config));
		});

		// \Fuel\Session\Driver\File
		$this->register('session.file', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\File', array($config));
		});
	}
}<commit_msg>rewrite to support Fuel Components<commit_after><?php
/**
 * @package    Fuel\Session
 * @version    2.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2013 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Fuel\Session\Providers;

use Fuel\Session\Driver;

use Fuel\Dependency\ServiceProvider;


/**
 * FuelPHP ServiceProvider class for this package
 *
 * @package  Fuel\Session
 *
 * @since  1.0.0
 */
class FuelServiceProvider extends ServiceProvider
{
	/**
	 * @var  array  list of service names provided by this provider
	 */
	public $provides = array(
		'session',
		'session.native',
		'session.cookie',
		'session.file',
	);

	/**
	 * Service provider definitions
	 */
	public function provide()
	{
		// \Fuel\Session\Manager
		$this->register('session', function ($dic, $config = array())
		{
			// get the session config
			$stack = $this->container->resolve('requeststack');
			if ($request = $stack->top())
			{
				$component = $request->getComponent();
			}
			else
			{
				$component = $this->container->resolve('application::__main')->getComponent();
			}

			// check if only a driver name or object is passed
			if ( ! is_array($config))
			{
				$config = array('driver' => $config);
			}

			$config = \Arr::merge($component->getConfig()->load('session', true), $config);

			// determine the driver to load
			if ($config['driver'] instanceOf Driver)
			{
				$driver = $config['driver'];
			}
			elseif (strpos('\\', $config['driver']) !== false and class_exists($config['driver']))
			{
				$class = $config['driver'];
				$driver = new $class($config);
			}
			else
			{
				$driver = $dic->resolve('session.'.strtolower($config['driver']), array($config));
			}

			$manager = $dic->resolve('Fuel\Session\Manager', array($driver, $config, $component->getApplication()));

			// start the session
			$manager->start();

			// and use the applications' event instance make sure it ends too
			$component->getApplication()->getEvent()->on('shutdown', function($event) { $this->stop(); }, $manager);

			// return the instance
			return $manager;
		});

		// \Fuel\Session\Driver\Cookie
		$this->register('session.cookie', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\Cookie', array($config));
		});

		// \Fuel\Session\Driver\Native
		$this->register('session.native', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\Native', array($config));
		});

		// \Fuel\Session\Driver\File
		$this->register('session.file', function ($dic, Array $config = array())
		{
			return $dic->resolve('Fuel\Session\Driver\File', array($config));
		});
	}
}
{'fraction_non_alphanumeric': 0.18121942039894617, 'fraction_numerical': 0.004892736168611215, 'mean_word_length': 3.388934764657308, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3000267', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1637, 'n_words': 378}