public function format(EventInterface $event) {
        $response = $event->getResponse();
        $model = $response->getModel();

        if ($response->getStatusCode() === 204 || !$model) {
            // No content to write
            return;
        }

        $request = $event->getRequest();

        // If we are dealing with an image we want to trigger an event that handles a possible
        // conversion
        if ($model instanceof Model\Image) {
            $outputConverterManager = $event->getOutputConverterManager();
            $eventManager = $event->getManager();

            if (
                ($model->getExtension() !== $this->formatter) &&
                ($outputConverterManager->getMimeTypeFromExtension($this->formatter) !== $model->getMimeType()) &&
                $outputConverterManager->supportsExtension($this->formatter)
            ) {
                $outputConverterManager->convert($model, $this->formatter);
            // for clarity - if we just have a requested compression / quality value, we still have to invoke the
            // conversion / writer for the existing format
            } else if (
                $model->getOutputQualityCompression() &&
                $outputConverterManager->supportsExtension($this->formatter)
            ) {
                $outputConverterManager->convert($model, $this->formatter);
            }

            // Finished transforming the image
            $eventManager->trigger('image.transformed', ['image' => $model]);

            $formattedData = $model->getBlob();
            $contentType = $model->getMimeType();
        } else {
            // Create an instance of the formatter
            $formatter = $this->formatters[$this->formatter];

            $formattedData = $formatter->format($model);
            $contentType = $formatter->getContentType();
        }

        if ($contentType === 'application/json') {
            foreach (['callback', 'jsonp', 'json'] as $validParam) {
                if ($request->query->has($validParam)) {
                    $formattedData = sprintf("%s(%s)", $request->query->get($validParam), $formattedData);
                    break;
                }
            }
        }

        $response->headers->add([
            'Content-Type' => $contentType,
            'Content-Length' => strlen($formattedData),
        ]);

        if ($request->getMethod() !== 'HEAD') {
            $response->setContent($formattedData);
        }
    }
public function format(EventInterface $event) {
        $response = $event->getResponse();
        $model = $response->getModel();

        if ($response->getStatusCode() === 204 || !$model) {
            // No content to write
            return;
        }

        $request = $event->getRequest();

        // If we are dealing with an image we want to trigger an event that handles a possible
        // conversion
        if ($model instanceof Model\Image) {
            $outputConverterManager = $event->getOutputConverterManager();
            $eventManager = $event->getManager();

            if (
                ($model->getExtension() !== $this->formatter) &&
                ($outputConverterManager->getMimeTypeFromExtension($this->formatter) !== $model->getMimeType()) &&
                $outputConverterManager->supportsExtension($this->formatter)
            ) {
                $outputConverterManager->convert($model, $this->formatter);
            // for clarity - if we just have a requested compression / quality value, we still have to invoke the
            // conversion / writer for the existing format
            } else if (
                $model->getOutputQualityCompression() &&
                $outputConverterManager->supportsExtension($this->formatter)
            ) {
                $outputConverterManager->convert($model, $this->formatter);
            }

            // Finished transforming the image
            $eventManager->trigger('image.transformed', ['image' => $model]);

            $formattedData = $model->getBlob();
            $contentType = $model->getMimeType();
        } else {
            // Create an instance of the formatter
            $formatter = $this->formatters[$this->formatter];

            $formattedData = $formatter->format($model);
            $contentType = $formatter->getContentType();
        }

        if ($contentType === 'application/json') {
            foreach (['callback', 'jsonp', 'json'] as $validParam) {
                if ($request->query->has($validParam)) {
                    $formattedData = sprintf("%s(%s)", $request->query->get($validParam), $formattedData);
                    break;
                }
            }
        }

        $response->headers->add([
            'Content-Type' => $contentType,
            'Content-Length' => strlen($formattedData),
        ]);

        if ($request->getMethod() !== 'HEAD') {
            $response->setContent($formattedData);
        }
    }
public function format ( EventInterface $ event ) { $ response = $ event -> getResponse ( ) ; $ model = $ response -> getModel ( ) ; if ( $ response -> getStatusCode ( ) === 204 || ! $ model ) { // No content to write return ; } $ request = $ event -> getRequest ( ) ; // If we are dealing with an image we want to trigger an event that handles a possible // conversion if ( $ model instanceof Model \ Image ) { $ outputConverterManager = $ event -> getOutputConverterManager ( ) ; $ eventManager = $ event -> getManager ( ) ; if ( ( $ model -> getExtension ( ) !== $ this -> formatter ) && ( $ outputConverterManager -> getMimeTypeFromExtension ( $ this -> formatter ) !== $ model -> getMimeType ( ) ) && $ outputConverterManager -> supportsExtension ( $ this -> formatter ) ) { $ outputConverterManager -> convert ( $ model , $ this -> formatter ) ; // for clarity - if we just have a requested compression / quality value, we still have to invoke the // conversion / writer for the existing format } else if ( $ model -> getOutputQualityCompression ( ) && $ outputConverterManager -> supportsExtension ( $ this -> formatter ) ) { $ outputConverterManager -> convert ( $ model , $ this -> formatter ) ; } // Finished transforming the image $ eventManager -> trigger ( 'image.transformed' , [ 'image' => $ model ] ) ; $ formattedData = $ model -> getBlob ( ) ; $ contentType = $ model -> getMimeType ( ) ; } else { // Create an instance of the formatter $ formatter = $ this -> formatters [ $ this -> formatter ] ; $ formattedData = $ formatter -> format ( $ model ) ; $ contentType = $ formatter -> getContentType ( ) ; } if ( $ contentType === 'application/json' ) { foreach ( [ 'callback' , 'jsonp' , 'json' ] as $ validParam ) { if ( $ request -> query -> has ( $ validParam ) ) { $ formattedData = sprintf ( "%s(%s)" , $ request -> query -> get ( $ validParam ) , $ formattedData ) ; break ; } } } $ response -> headers -> add ( [ 'Content-Type' => $ contentType , 'Content-Length' => strlen ( $ formattedData ) , ] ) ; if ( $ request -> getMethod ( ) !== 'HEAD' ) { $ response -> setContent ( $ formattedData ) ; } }
Response send hook

@param EventInterface $event The current event
Response send hook