src/Titon/Db/Behavior/ConverterBehavior.php
public function preSave(Event $event, Query $query, $id, array &$data) {
        $repo = $this->getRepository();
        $converters = $this->getConverters();

        foreach ($data as $key => $value) {
            if (empty($converters[$key])) {
                continue;
            }

            $converter = $converters[$key];

            // Exit if encoding should not happen
            if (!$converter['encode']) {
                continue;
            }

            switch ($converter['type']) {
                case self::SERIALIZE:   $value = $this->toSerialize($value, $converter); break;
                case self::JSON:        $value = $this->toJson($value, $converter); break;
                case self::BASE64:      $value = $this->toBase64($value, $converter); break;
                case self::CUSTOM:
                    if (method_exists($repo, $converter['encode'])) {
                        $value = call_user_func_array([$repo, $converter['encode']], [$value, $converter]);
                    }
                break;
            }

            $data[$key] = $value;
        }

        return true;
    }
public function preSave(Event $event, Query $query, $id, array &$data) {
        $repo = $this->getRepository();
        $converters = $this->getConverters();

        foreach ($data as $key => $value) {
            if (empty($converters[$key])) {
                continue;
            }

            $converter = $converters[$key];

            // Exit if encoding should not happen
            if (!$converter['encode']) {
                continue;
            }

            switch ($converter['type']) {
                case self::SERIALIZE:   $value = $this->toSerialize($value, $converter); break;
                case self::JSON:        $value = $this->toJson($value, $converter); break;
                case self::BASE64:      $value = $this->toBase64($value, $converter); break;
                case self::CUSTOM:
                    if (method_exists($repo, $converter['encode'])) {
                        $value = call_user_func_array([$repo, $converter['encode']], [$value, $converter]);
                    }
                break;
            }

            $data[$key] = $value;
        }

        return true;
    }
public function preSave ( Event $ event , Query $ query , $ id , array & $ data ) { $ repo = $ this -> getRepository ( ) ; $ converters = $ this -> getConverters ( ) ; foreach ( $ data as $ key => $ value ) { if ( empty ( $ converters [ $ key ] ) ) { continue ; } $ converter = $ converters [ $ key ] ; // Exit if encoding should not happen if ( ! $ converter [ 'encode' ] ) { continue ; } switch ( $ converter [ 'type' ] ) { case self :: SERIALIZE : $ value = $ this -> toSerialize ( $ value , $ converter ) ; break ; case self :: JSON : $ value = $ this -> toJson ( $ value , $ converter ) ; break ; case self :: BASE64 : $ value = $ this -> toBase64 ( $ value , $ converter ) ; break ; case self :: CUSTOM : if ( method_exists ( $ repo , $ converter [ 'encode' ] ) ) { $ value = call_user_func_array ( [ $ repo , $ converter [ 'encode' ] ] , [ $ value , $ converter ] ) ; } break ; } $ data [ $ key ] = $ value ; } return true ; }
Apply the encoding converter before a record is saved.

@param \Titon\Event\Event $event
@param \Titon\Db\Query $query
@param int|int[] $id
@param array $data
@return bool
Apply the encoding converter before a record is saved .