public function objectToJson($content = null)
    {
        if ($this->getJsonEncodeObject() && is_object($content)) {

            if (method_exists($content, '__toString')) {
                return (string)$content;
            }

            if (method_exists($content, 'toJson')) {
                $this->header('Content-Type: application/json');

                return json_encode($content);
            }

            if (method_exists($content, 'toArray')) {
                $this->header('Content-Type: application/json');

                return json_encode($content->toArray());
            }
        }

        return $content;
    }
public function objectToJson($content = null)
    {
        if ($this->getJsonEncodeObject() && is_object($content)) {

            if (method_exists($content, '__toString')) {
                return (string)$content;
            }

            if (method_exists($content, 'toJson')) {
                $this->header('Content-Type: application/json');

                return json_encode($content);
            }

            if (method_exists($content, 'toArray')) {
                $this->header('Content-Type: application/json');

                return json_encode($content->toArray());
            }
        }

        return $content;
    }
public function objectToJson ( $ content = null ) { if ( $ this -> getJsonEncodeObject ( ) && is_object ( $ content ) ) { if ( method_exists ( $ content , '__toString' ) ) { return ( string ) $ content ; } if ( method_exists ( $ content , 'toJson' ) ) { $ this -> header ( 'Content-Type: application/json' ) ; return json_encode ( $ content ) ; } if ( method_exists ( $ content , 'toArray' ) ) { $ this -> header ( 'Content-Type: application/json' ) ; return json_encode ( $ content -> toArray ( ) ) ; } } return $ content ; }
Encode object to json if configured

@param $content

@return string
Encode object to json if configured