public function createHydratorFor($objectClass)
    {
        $metadata = $this->getMetadata($objectClass);
        $propertyAccessStrategy = $metadata->isPropertyAccessStrategyEnabled();

        $hydrator = new Hydrator\Hydrator($this, $propertyAccessStrategy);
        if ($this->classResolver) {
            $hydrator->setClassResolver($this->classResolver);
        }

        $fieldsWithHydrationStrategy = $metadata->computeFieldsWithHydrationStrategy();

        $mappedFieldNames = $metadata->getMappedFieldNames();

        foreach ($mappedFieldNames as $mappedFieldName) {

            $strategy = null;

            if ($metadata->isMappedFieldWithStrategy($mappedFieldName)) {

                $fieldStrategy = $fieldsWithHydrationStrategy[$mappedFieldName];
                $strategy = new ClosureHydrationStrategy(
                    $fieldStrategy[$metadata::INDEX_EXTRACTION_STRATEGY],
                    $fieldStrategy[$metadata::INDEX_HYDRATION_STRATEGY]
                );
            }

            if ($metadata->isMappedDateField($mappedFieldName)) {

                $readDateConverter = $metadata->getReadDateFormatByMappedField($mappedFieldName, null);
                $writeDateConverter = $metadata->getWriteDateFormatByMappedField($mappedFieldName, null);

                if (! is_null($readDateConverter) && ! is_null($writeDateConverter)) {
                    $strategy = new DateHydrationStrategy($readDateConverter, $writeDateConverter, $strategy);
                } else {
                    throw new ObjectMappingException(
                        sprintf(
                            'The date field "%s" should provide "readDateConverter" and "writeDateConverter" metadata.',
                            $mappedFieldName
                        )
                    );
                }
            }

            if (! is_null($strategy)) {
                $hydrator->addStrategy($mappedFieldName, $strategy);
            }
        }

        //------------------------------------------------------------------------------------------
        if ($metadata->eventsExist()) {
            $hydrator = new Hydrator\EventHydrator($hydrator, $this);
        }

        return $hydrator;
    }
public function createHydratorFor($objectClass)
    {
        $metadata = $this->getMetadata($objectClass);
        $propertyAccessStrategy = $metadata->isPropertyAccessStrategyEnabled();

        $hydrator = new Hydrator\Hydrator($this, $propertyAccessStrategy);
        if ($this->classResolver) {
            $hydrator->setClassResolver($this->classResolver);
        }

        $fieldsWithHydrationStrategy = $metadata->computeFieldsWithHydrationStrategy();

        $mappedFieldNames = $metadata->getMappedFieldNames();

        foreach ($mappedFieldNames as $mappedFieldName) {

            $strategy = null;

            if ($metadata->isMappedFieldWithStrategy($mappedFieldName)) {

                $fieldStrategy = $fieldsWithHydrationStrategy[$mappedFieldName];
                $strategy = new ClosureHydrationStrategy(
                    $fieldStrategy[$metadata::INDEX_EXTRACTION_STRATEGY],
                    $fieldStrategy[$metadata::INDEX_HYDRATION_STRATEGY]
                );
            }

            if ($metadata->isMappedDateField($mappedFieldName)) {

                $readDateConverter = $metadata->getReadDateFormatByMappedField($mappedFieldName, null);
                $writeDateConverter = $metadata->getWriteDateFormatByMappedField($mappedFieldName, null);

                if (! is_null($readDateConverter) && ! is_null($writeDateConverter)) {
                    $strategy = new DateHydrationStrategy($readDateConverter, $writeDateConverter, $strategy);
                } else {
                    throw new ObjectMappingException(
                        sprintf(
                            'The date field "%s" should provide "readDateConverter" and "writeDateConverter" metadata.',
                            $mappedFieldName
                        )
                    );
                }
            }

            if (! is_null($strategy)) {
                $hydrator->addStrategy($mappedFieldName, $strategy);
            }
        }

        //------------------------------------------------------------------------------------------
        if ($metadata->eventsExist()) {
            $hydrator = new Hydrator\EventHydrator($hydrator, $this);
        }

        return $hydrator;
    }
public function createHydratorFor ( $ objectClass ) { $ metadata = $ this -> getMetadata ( $ objectClass ) ; $ propertyAccessStrategy = $ metadata -> isPropertyAccessStrategyEnabled ( ) ; $ hydrator = new Hydrator \ Hydrator ( $ this , $ propertyAccessStrategy ) ; if ( $ this -> classResolver ) { $ hydrator -> setClassResolver ( $ this -> classResolver ) ; } $ fieldsWithHydrationStrategy = $ metadata -> computeFieldsWithHydrationStrategy ( ) ; $ mappedFieldNames = $ metadata -> getMappedFieldNames ( ) ; foreach ( $ mappedFieldNames as $ mappedFieldName ) { $ strategy = null ; if ( $ metadata -> isMappedFieldWithStrategy ( $ mappedFieldName ) ) { $ fieldStrategy = $ fieldsWithHydrationStrategy [ $ mappedFieldName ] ; $ strategy = new ClosureHydrationStrategy ( $ fieldStrategy [ $ metadata :: INDEX_EXTRACTION_STRATEGY ] , $ fieldStrategy [ $ metadata :: INDEX_HYDRATION_STRATEGY ] ) ; } if ( $ metadata -> isMappedDateField ( $ mappedFieldName ) ) { $ readDateConverter = $ metadata -> getReadDateFormatByMappedField ( $ mappedFieldName , null ) ; $ writeDateConverter = $ metadata -> getWriteDateFormatByMappedField ( $ mappedFieldName , null ) ; if ( ! is_null ( $ readDateConverter ) && ! is_null ( $ writeDateConverter ) ) { $ strategy = new DateHydrationStrategy ( $ readDateConverter , $ writeDateConverter , $ strategy ) ; } else { throw new ObjectMappingException ( sprintf ( 'The date field "%s" should provide "readDateConverter" and "writeDateConverter" metadata.' , $ mappedFieldName ) ) ; } } if ( ! is_null ( $ strategy ) ) { $ hydrator -> addStrategy ( $ mappedFieldName , $ strategy ) ; } } //------------------------------------------------------------------------------------------ if ( $ metadata -> eventsExist ( ) ) { $ hydrator = new Hydrator \ EventHydrator ( $ hydrator , $ this ) ; } return $ hydrator ; }
Factory method to create an hydrator.

@param $objectClass Object class to hydrate

@return AbstractHydrator
Factory method to create an hydrator .