<commit_before><?php
namespace SynergyDataGrid\Grid;

/*
 * This file is part of the Synergy package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME>
 * @license http://opensource.org/licenses/BSD-3-Clause
 *
 */

use SynergyDataGrid\Grid\GridType\DoctrineORMGrid;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AbstractGridFactory
    implements AbstractFactoryInterface
{

    protected $_configPrefix = 'jqgrid';

    /**
     * Determine if we can create a service with name
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @param                         $name
     * @param                         $requestedName
     *
     * @return bool
     */
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (substr($requestedName, 0, strlen($this->_configPrefix)) != $this->_configPrefix) {
            return false;
        }

        return true;
    }

    /**
     * Create service with name
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @param                         $name
     * @param                         $requestedName
     *
     * @return mixed
     */
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $gridType = trim(str_replace($this->_configPrefix, '', $requestedName), '\\');
        $config   = $serviceLocator->get('Config');

        switch ($gridType) {
            case 'odm':
                $manager = $serviceLocator->get('doctrine.entitymanager.odm_default');
                $class   = 'SynergyDataGrid\Grid\GridType\DoctrineODMGrid';
                break;
            default:
                $manager = $serviceLocator->get('doctrine.entitymanager.orm_default');
                $class   = 'SynergyDataGrid\Grid\GridType\DoctrineORMGrid';
        }

        $grid = new $class($config['jqgrid'], $serviceLocator, $manager);

        return $grid;
    }
}<commit_msg>added support for factories<commit_after><?php
namespace SynergyDataGrid\Grid;

/*
 * This file is part of the Synergy package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME>
 * @license http://opensource.org/licenses/BSD-3-Clause
 *
 */

use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AbstractGridFactory
	implements AbstractFactoryInterface {

	protected $_configPrefix = 'jqgrid';

	/**
	 * Determine if we can create a service with name
	 *
	 * @param ServiceLocatorInterface $serviceLocator
	 * @param                         $name
	 * @param                         $requestedName
	 *
	 * @return bool
	 */
	public function canCreateServiceWithName( ServiceLocatorInterface $serviceLocator, $name, $requestedName ) {
		if ( substr( $requestedName, 0, strlen( $this->_configPrefix ) ) != $this->_configPrefix ) {
			return false;
		}

		return true;
	}

	/**
	 * Create service with name
	 *
	 * @param ServiceLocatorInterface $serviceLocator
	 * @param                         $name
	 * @param                         $requestedName
	 *
	 * @return mixed
	 */
	public function createServiceWithName( ServiceLocatorInterface $serviceLocator, $name, $requestedName ) {
		$gridType   = trim( str_replace( $this->_configPrefix, '', $requestedName ), '\\' );
		$config     = $serviceLocator->get( 'Config' );
		$gridConfig = $config['jqgrid'];

		if ( isset( $gridConfig['factories'] ) ) {
			foreach ( (array) $gridConfig['factories'] as $alias ) {
				if ( $serviceLocator->has( $alias ) ) {
					$addConfig  = $serviceLocator->get( $alias );
					$gridConfig = array_merge( $gridConfig, $addConfig );
				}
			}
		}

		switch ( $gridType ) {
			case 'odm':
				$manager = $serviceLocator->get( 'doctrine.entitymanager.odm_default' );
				$class   = 'SynergyDataGrid\Grid\GridType\DoctrineODMGrid';
				break;
			default:
				$manager = $serviceLocator->get( 'doctrine.entitymanager.orm_default' );
				$class   = 'SynergyDataGrid\Grid\GridType\DoctrineORMGrid';
		}

		$grid = new $class( $gridConfig, $serviceLocator, $manager );

		return $grid;
	}
}
{'fraction_non_alphanumeric': 0.11770031688546853, 'fraction_numerical': 0.0009053870529651426, 'mean_word_length': 2.7480916030534353, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, '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': '4932472', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1250, 'n_words': 287}