src/db/orm/PersistableObject.php
private function getPhysicalValue($column, $type = null) {
        $mapping = $this->dao()->getMapping();
        $column  = strtolower($column);
        if (!isset($mapping['columns'][$column])) throw new RuntimeException('Not a mapped column "'.func_get_arg(0).'"');

        $property      = &$mapping['columns'][$column];
        $propertyName  =  $property['name'];
        $propertyValue =  $this->$propertyName;             // the logical or physical column value

        if ($propertyValue === null)
            return null;

        if (isset($property['assoc'])) {
            if ($propertyValue === false)
                return null;
            if (!is_object($propertyValue)) {               // a foreign-key value of a not-yet-fetched relation
                if ($type !== null) throw new RuntimeException('Unexpected parameter $type="'.$type.'" (not null) for relation [name="'.$propertyName.'", column="'.$column.'", ...] of entity "'.$mapping['class'].'"');
                return $propertyValue;
            }

            /** @var PersistableObject $object */
            $object = $propertyValue;                       // a single instance of "one-to-one"|"many-to-one" relation, no join table
            if (!isset($property['ref-column']))
                $property['ref-column'] = $object->dao()->getMapping()['identity']['column'];
            $fkColumn = $property['ref-column'];
            return $object->getPhysicalValue($fkColumn);
        }

        $columnType = $property['column-type'];

        switch ($columnType) {
            case 'bool'   :
            case 'boolean': return (bool)(int) $propertyValue;

            case 'int'    :
            case 'integer': return (int) $propertyValue;

            case 'real'   :
            case 'float'  :
            case 'double' :
            case 'decimal': return (float) $propertyValue;

            case 'text'   :
            case 'string' : return (string) $propertyValue;

            default:
                // TODO: convert custom types (e.g. Enum|DateTime) to physical values
                //if (is_class($propertyType)) {
                //    $object->$propertyName = new $propertyType($row[$column]);
                //    break;
                //}
        }
        throw new RuntimeException('Unsupported attribute "column-type"="'.$columnType.'" in property [name="'.$propertyName.'", ...] of entity "'.$mapping['class'].'"');
    }
private function getPhysicalValue($column, $type = null) {
        $mapping = $this->dao()->getMapping();
        $column  = strtolower($column);
        if (!isset($mapping['columns'][$column])) throw new RuntimeException('Not a mapped column "'.func_get_arg(0).'"');

        $property      = &$mapping['columns'][$column];
        $propertyName  =  $property['name'];
        $propertyValue =  $this->$propertyName;             // the logical or physical column value

        if ($propertyValue === null)
            return null;

        if (isset($property['assoc'])) {
            if ($propertyValue === false)
                return null;
            if (!is_object($propertyValue)) {               // a foreign-key value of a not-yet-fetched relation
                if ($type !== null) throw new RuntimeException('Unexpected parameter $type="'.$type.'" (not null) for relation [name="'.$propertyName.'", column="'.$column.'", ...] of entity "'.$mapping['class'].'"');
                return $propertyValue;
            }

            /** @var PersistableObject $object */
            $object = $propertyValue;                       // a single instance of "one-to-one"|"many-to-one" relation, no join table
            if (!isset($property['ref-column']))
                $property['ref-column'] = $object->dao()->getMapping()['identity']['column'];
            $fkColumn = $property['ref-column'];
            return $object->getPhysicalValue($fkColumn);
        }

        $columnType = $property['column-type'];

        switch ($columnType) {
            case 'bool'   :
            case 'boolean': return (bool)(int) $propertyValue;

            case 'int'    :
            case 'integer': return (int) $propertyValue;

            case 'real'   :
            case 'float'  :
            case 'double' :
            case 'decimal': return (float) $propertyValue;

            case 'text'   :
            case 'string' : return (string) $propertyValue;

            default:
                // TODO: convert custom types (e.g. Enum|DateTime) to physical values
                //if (is_class($propertyType)) {
                //    $object->$propertyName = new $propertyType($row[$column]);
                //    break;
                //}
        }
        throw new RuntimeException('Unsupported attribute "column-type"="'.$columnType.'" in property [name="'.$propertyName.'", ...] of entity "'.$mapping['class'].'"');
    }
private function getPhysicalValue ( $ column , $ type = null ) { $ mapping = $ this -> dao ( ) -> getMapping ( ) ; $ column = strtolower ( $ column ) ; if ( ! isset ( $ mapping [ 'columns' ] [ $ column ] ) ) throw new RuntimeException ( 'Not a mapped column "' . func_get_arg ( 0 ) . '"' ) ; $ property = & $ mapping [ 'columns' ] [ $ column ] ; $ propertyName = $ property [ 'name' ] ; $ propertyValue = $ this -> $ propertyName ; // the logical or physical column value if ( $ propertyValue === null ) return null ; if ( isset ( $ property [ 'assoc' ] ) ) { if ( $ propertyValue === false ) return null ; if ( ! is_object ( $ propertyValue ) ) { // a foreign-key value of a not-yet-fetched relation if ( $ type !== null ) throw new RuntimeException ( 'Unexpected parameter $type="' . $ type . '" (not null) for relation [name="' . $ propertyName . '", column="' . $ column . '", ...] of entity "' . $ mapping [ 'class' ] . '"' ) ; return $ propertyValue ; } /** @var PersistableObject $object */ $ object = $ propertyValue ; // a single instance of "one-to-one"|"many-to-one" relation, no join table if ( ! isset ( $ property [ 'ref-column' ] ) ) $ property [ 'ref-column' ] = $ object -> dao ( ) -> getMapping ( ) [ 'identity' ] [ 'column' ] ; $ fkColumn = $ property [ 'ref-column' ] ; return $ object -> getPhysicalValue ( $ fkColumn ) ; } $ columnType = $ property [ 'column-type' ] ; switch ( $ columnType ) { case 'bool' : case 'boolean' : return ( bool ) ( int ) $ propertyValue ; case 'int' : case 'integer' : return ( int ) $ propertyValue ; case 'real' : case 'float' : case 'double' : case 'decimal' : return ( float ) $ propertyValue ; case 'text' : case 'string' : return ( string ) $ propertyValue ; default : // TODO: convert custom types (e.g. Enum|DateTime) to physical values //if (is_class($propertyType)) { //    $object->$propertyName = new $propertyType($row[$column]); //    break; //} } throw new RuntimeException ( 'Unsupported attribute "column-type"="' . $ columnType . '" in property [name="' . $ propertyName . '", ...] of entity "' . $ mapping [ 'class' ] . '"' ) ; }
Return the value of a mapped column.

@param  string $column          - column name
@param  string $type [optional] - column type (default: type as configured in the entity mapping)

@return mixed - column value
Return the value of a mapped column .