Skip to content
Snippets Groups Projects
Select Git revision
  • 06629e19ca03c3431a64302a18a1ff2a2f011be1
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

StudipResponse.php

Blame
  • Forked from Stud.IP / Stud.IP
    1467 commits behind the upstream repository.
    Jan-Hendrik Willms's avatar
    Jan-Hendrik Willms authored and David Siegfried committed
    Closes #4105
    
    Merge request studip/studip!2936
    06629e19
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StudipResponse.php 1.46 KiB
    <?php
    class StudipResponse extends Trails_Response
    {
        /**
         * Outputs this response to the client using "echo" and "header".
         *
         * This extension allows the body to be a callable and handles generators
         * by outputting the chunks yielded by the generator.
         */
        public function output()
        {
            if (isset($this->status)) {
                $this->send_header(
                    "{$_SERVER['SERVER_PROTOCOL']} {$this->status} {$this->reason}",
                    true,
                    $this->status
                );
            }
    
            // Send headers
            foreach ($this->headers as $k => $v) {
                $this->send_header("{$k}: {$v}");
            }
    
            // Determine output
            if (is_callable($this->body)) {
                $output = call_user_func($this->body);
            } else {
                $output = $this->body;
            }
    
            if ($output instanceof Generator) {
                // Clear output buffer
                while (ob_get_level()) {
                    ob_end_clean();
                }
    
                // Ensure generator will run to the end
                $abort = ignore_user_abort(true);
    
                // Output chunks yielded by generator
                foreach ($output as $chunk) {
                    if (!connection_aborted()) {
                        echo $chunk;
                        flush();
                    }
                }
    
                // Reset user abort to previous state
                ignore_user_abort($abort);
            } else {
                echo $output;
            }
        }
    }