<commit_before><?php

/**
 * This file is part of the Krystal Framework
 * 
 * Copyright (c) 2015 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view
 * the license file that was distributed with this source code.
 */

namespace Krystal\Application\Component;

use Krystal\Application\InputInterface;
use Krystal\InstanceManager\DependencyInjectionContainerInterface;
use Krystal\Cache\FileEngine\FileEngineFactory;
use Krystal\Cache\Sql\SqlEngineFactory;
use Krystal\Cache\WinCache;
use Krystal\Cache\APC;
use Krystal\Cache\XCache;

final class Cache implements ComponentInterface
{
	/**
	 * {@inheritDoc}
	 */
	public function getInstance(DependencyInjectionContainerInterface $container, array $config, InputInterface $input)
	{
		// First of all, check cache component is required
		if (isset($config['components']['cache']['engine'])) {

			// Reference as a short-cut
			$component =& $config['components']['cache'];
			$options =& $config['components']['cache']['options'];

			switch ($component['engine']) {
				case 'file' :
					// By default, a file need to be created automatically if it doesn't exist
					$autoCreate = true;

					if (isset($options['auto_create']) && is_bool($options['auto_create'])){
						$autoCreate = $options['auto_create'];
					}

					return FileEngineFactory::build($options['file'], $autoCreate);
				break;
				
				case 'wincache';
					return new WinCache();
				
				case 'apc':
					return new APC();
				
				case 'xcache':
					return new XCache();
				
				case 'sql':
					
					$table = $options['table'];
					
					$db = $container->get('db');
					$connection = $db[$options['connection']];
					
					$pdo = $connection->getPdo();
					
					return SqlEngineFactory::build($pdo, $table);
					
				default : 
					throw new \RuntimeException(sprintf('Invalid engine provided %s', $component['engine']));
			}

		} else {
			// Not defined in configuration
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public function getName()
	{
		return 'cache';
	}
}<commit_msg>Minor improvements<commit_after><?php

/**
 * This file is part of the Krystal Framework
 * 
 * Copyright (c) 2015 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view
 * the license file that was distributed with this source code.
 */

namespace Krystal\Application\Component;

use Krystal\Application\InputInterface;
use Krystal\InstanceManager\DependencyInjectionContainerInterface;
use Krystal\Cache\FileEngine\FileEngineFactory;
use Krystal\Cache\Sql\SqlEngineFactory;
use Krystal\Cache\WinCache;
use Krystal\Cache\APC;
use Krystal\Cache\XCache;
use RuntimeException;

final class Cache implements ComponentInterface
{
	/**
	 * {@inheritDoc}
	 */
	public function getInstance(DependencyInjectionContainerInterface $container, array $config, InputInterface $input)
	{
		// First of all, check cache component is required
		if (isset($config['components']['cache']['engine'])) {

			// Reference as a short-cut
			$component =& $config['components']['cache'];
			$options =& $config['components']['cache']['options'];

			switch ($component['engine']) {
				case 'file' :
					// By default, a file need to be created automatically if it doesn't exist
					$autoCreate = true;

					if (isset($options['auto_create']) && is_bool($options['auto_create'])){
						$autoCreate = $options['auto_create'];
					}

					return FileEngineFactory::build($options['file'], $autoCreate);
				break;
				
				case 'wincache';
					return new WinCache();
				
				case 'apc':
					return new APC();
				
				case 'xcache':
					return new XCache();
				
				case 'sql':

					if (!isset($options['table']) || !isset($options['connection'])) {
						throw new RuntimeException('Cache SQL service request connection and table names to run');
					}

					$table = $options['table'];

					$db = $container->get('db');
					$connection = $db[$options['connection']];

					$pdo = $connection->getPdo();

					return SqlEngineFactory::build($pdo, $table);

				default : 
					throw new RuntimeException(sprintf('Invalid engine provided %s', $component['engine']));
			}

		} else {

			// Not defined in configuration
			return false;
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public function getName()
	{
		return 'cache';
	}
}
{'fraction_non_alphanumeric': 0.14132462686567165, 'fraction_numerical': 0.0018656716417910447, 'mean_word_length': 3.646803900325027, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '1452328', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1195, 'n_words': 332}