protected function castToClass($value)
    {
        if (!class_exists($this->class)) {
            return $this->dontCast($value, "Class doesn't exist");
        }

        if (is_object($value) && is_a($value, $this->class)) {
            return $value;
        }

        $value = $this->createWithSetState($value);

        if (!is_a($value, $this->class)) {
            $class = $this->class;
            $value = new $class($value);
        }

        return $value;
    }
protected function castToClass($value)
    {
        if (!class_exists($this->class)) {
            return $this->dontCast($value, "Class doesn't exist");
        }

        if (is_object($value) && is_a($value, $this->class)) {
            return $value;
        }

        $value = $this->createWithSetState($value);

        if (!is_a($value, $this->class)) {
            $class = $this->class;
            $value = new $class($value);
        }

        return $value;
    }
protected function castToClass ( $ value ) { if ( ! class_exists ( $ this -> class ) ) { return $ this -> dontCast ( $ value , "Class doesn't exist" ) ; } if ( is_object ( $ value ) && is_a ( $ value , $ this -> class ) ) { return $ value ; } $ value = $ this -> createWithSetState ( $ value ) ; if ( ! is_a ( $ value , $ this -> class ) ) { $ class = $ this -> class ; $ value = new $ class ( $ value ) ; } return $ value ; }
Cast value to a specific class

@param mixed $value
@return object|mixed
Cast value to a specific class