<commit_before><?php
namespace Bolt\Provider;

use Bolt\EventListener\StorageEventListener;
use Bolt\Legacy\Storage;
use Bolt\Storage\ContentLegacyService;
use Bolt\Storage\EntityManager;
use Bolt\Storage\Entity\Builder;
use Bolt\Storage\Field\Type\TemplateFieldsType;
use Bolt\Storage\FieldFactory;
use Bolt\Storage\Hydrator;
use Bolt\Storage\Mapping\MetadataDriver;
use Bolt\Storage\NamingStrategy;
use Bolt\Storage\Persister;
use Bolt\Storage\RecordModifier;
use Silex\Application;
use Silex\ServiceProviderInterface;

class StorageServiceProvider implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $app['storage.legacy'] = $app->share(
            function ($app) {
                return new Storage($app);
            }
        );

        $app['storage.legacy_service'] = $app->share(
            function ($app) {
                return new ContentLegacyService($app);
            }
        );

        $app['storage'] = $app->share(
            function ($app) {
                $storage = new EntityManager(
                    $app['db'],
                    $app['dispatcher'],
                    $app['storage.metadata'],
                    $app['logger.system']
                );
                $storage->setLegacyStorage($app['storage.legacy']);

                foreach ($app['storage.repositories'] as $entity => $repo) {
                    $storage->setRepository($entity, $repo);
                }

                $storage->setDefaultRepositoryFactory($app['storage.content_repository']);

                return $storage;
            }
        );

        $app['storage.content_repository'] = $app->protect(
            function ($classMetadata) use ($app) {
                $repoClass = $app['storage.repository.default'];
                $repo = new $repoClass($app['storage'], $classMetadata);
                $repo->setLegacyService($app['storage.legacy_service']);
                $repo->setHydrator(new Hydrator($classMetadata, $app['storage.field_factory']));
                $repo->setPersister(new Persister($classMetadata, $app['storage.field_factory']));
                $repo->setBuilder($app['storage.entity_builder']);
                
                return $repo;
            }
        );

        $app['storage.field_factory'] = $app->share(
            function ($app) {
                $factory = new FieldFactory($app['storage.typemap']);
                foreach ($app['storage.typemap'] as $field) {
                    if (isset($app[$field])) {
                        $factory->setHandler($field, $app[$field]);
                    }
                }

                return $factory;
            }
        );

        $app['Bolt\Storage\Field\Type\TemplateFieldsType'] = $app->protect(
            function ($mapping) use ($app) {
                $field = new TemplateFieldsType(
                    $mapping,
                    $app['storage'],
                    $app['templatechooser']
                );

                return $field;
            }
        );
        
        $app['storage.entity_builder'] = $app->share(<commit_msg>change the constructor parameter for FieldFactory<commit_after><?php
namespace Bolt\Provider;

use Bolt\EventListener\StorageEventListener;
use Bolt\Legacy\Storage;
use Bolt\Storage\ContentLegacyService;
use Bolt\Storage\EntityManager;
use Bolt\Storage\Entity\Builder;
use Bolt\Storage\Field\Type\TemplateFieldsType;
use Bolt\Storage\FieldFactory;
use Bolt\Storage\Hydrator;
use Bolt\Storage\Mapping\MetadataDriver;
use Bolt\Storage\NamingStrategy;
use Bolt\Storage\Persister;
use Bolt\Storage\RecordModifier;
use Silex\Application;
use Silex\ServiceProviderInterface;

class StorageServiceProvider implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $app['storage.legacy'] = $app->share(
            function ($app) {
                return new Storage($app);
            }
        );

        $app['storage.legacy_service'] = $app->share(
            function ($app) {
                return new ContentLegacyService($app);
            }
        );

        $app['storage'] = $app->share(
            function ($app) {
                $storage = new EntityManager(
                    $app['db'],
                    $app['dispatcher'],
                    $app['storage.metadata'],
                    $app['logger.system']
                );
                $storage->setLegacyStorage($app['storage.legacy']);

                foreach ($app['storage.repositories'] as $entity => $repo) {
                    $storage->setRepository($entity, $repo);
                }

                $storage->setDefaultRepositoryFactory($app['storage.content_repository']);

                return $storage;
            }
        );

        $app['storage.content_repository'] = $app->protect(
            function ($classMetadata) use ($app) {
                $repoClass = $app['storage.repository.default'];
                $repo = new $repoClass($app['storage'], $classMetadata);
                $repo->setLegacyService($app['storage.legacy_service']);
                $repo->setHydrator(new Hydrator($classMetadata, $app['storage.field_factory']));
                $repo->setPersister(new Persister($classMetadata, $app['storage.field_factory']));
                $repo->setBuilder($app['storage.entity_builder']);
                
                return $repo;
            }
        );

        $app['storage.field_factory'] = $app->share(
            function ($app) {
                $factory = new FieldFactory($app['storage']);
                foreach ($app['storage.typemap'] as $field) {
                    if (isset($app[$field])) {
                        $factory->setHandler($field, $app[$field]);
                    }
                }

                return $factory;
            }
        );

        $app['Bolt\Storage\Field\Type\TemplateFieldsType'] = $app->protect(
            function ($mapping) use ($app) {
                $field = new TemplateFieldsType(
                    $mapping,
                    $app['storage'],
                    $app['templatechooser']
                );

                return $field;
            }
        );
        
        $app['storage.entity_builder'] = $app->share(
{'fraction_non_alphanumeric': 0.13201267828843105, 'fraction_numerical': 0.0, 'mean_word_length': 1.8011540168664004, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4111538', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1575, 'n_words': 264}