<commit_before><?php

namespace Recommerce\Asset;

use Recommerce\Asset\Exception\InvalidConfigurationException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AssetFactory implements FactoryInterface
{

    /**
     * @param ServiceLocatorInterface $serviceManager
     * @return mixed
     * @throws \Exception
     */
    public function createService(ServiceLocatorInterface $serviceManager)
    {
        if (!$serviceManager->has('Config')) {
            throw new ServiceNotFoundException("No Config service has been registered.");
        }

        return $this->createServiceFromConfig($serviceManager->get('Config')['asset']);
    }

    /**
     * @param array $config
     * @return object
     * @throws InvalidConfigurationException
     */
    public function createServiceFromConfig(array $config)
    {
        if (empty($config['name'])) {
            throw new InvalidConfigurationException("Asset configuration was not found.");
        }

        $reflect  = new \ReflectionClass($config['name']);

        return $reflect->newInstanceArgs($config['args']);
    }
}<commit_msg>Try to use callback in config<commit_after><?php

namespace Recommerce\Asset;

use Recommerce\Asset\Exception\InvalidConfigurationException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AssetFactory implements FactoryInterface
{

    /**
     * @param ServiceLocatorInterface $serviceManager
     * @return mixed
     * @throws \Exception
     */
    public function createService(ServiceLocatorInterface $serviceManager)
    {
        if (!$serviceManager->has('Config')) {
            throw new ServiceNotFoundException("No Config service has been registered.");
        }

        return $this->createServiceFromConfig($serviceManager->get('Config')['asset']);
    }

    /**
     * @param array $config
     * @return object
     * @throws InvalidConfigurationException
     */
    public function createServiceFromConfig(array $config)
    {
        if (empty($config['name'])) {
            throw new InvalidConfigurationException("Asset configuration was not found.");
        }

        $reflect  = new \ReflectionClass($config['name']);

        $args = array_map(function($value) { return is_callable($value) ? call_user_func($value) : $value;}, $config['args']);

        return $reflect->newInstanceArgs($args);
    }
}
{'fraction_non_alphanumeric': 0.11198120595144871, 'fraction_numerical': 0.0, 'mean_word_length': 3.5625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2821044', 'n_tokens_mistral': 634, 'n_tokens_neox': 617, 'n_words': 138}