lib/controllers/AppController.php
public function actionStream()
    {
        header("Content-type: text/plain");
        header("Access-Control-Allow-Origin: *");
        ob_implicit_flush(1);

        Yii::$app->response->task = false;
        $refreshed = [];
        $source = $_POST;
        $stream = false;
        if (!empty($source['__TODO_FIGURE_OUT_VIBE_STREAM_HINT__'])) { // @todo figure out this vibe hint thing
            $stream = true;
        }
        if (isset($source['when']) && $source['when'] === 'handshake') {
            echo json_encode(['id' => md5(microtime(true)), 'transports' => ['stream']]);

            return;
        }
        if (empty($source['requests'])) {
            echo json_encode([]);
            return;
        }
        $nonStreamResult = [];
        $baseInstrictions = (isset($source['baseInstructions']) ? $source['baseInstructions'] : []);
        foreach ($source['requests'] as $requestId => $request) {
            $refreshed[$requestId] = false;
            $instructions = $baseInstrictions;
            if (isset($request['instructions'])) {
                $instructions = array_merge($instructions, $request['instructions']);
            }
            if (empty($instructions['type']) || empty($instructions['type'])) {
                continue;
            }
            if (isset($request['state'])) {
                foreach ($request['state'] as $key => $value) {
                    Yii::$app->webState->set($key, $value);
                }
            }

            if (isset($instructions['objectId'])) {
                $object = Yii::$app->request->object = Registry::getObject($instructions['objectId']);
                if (!$object) {
                    $refreshed[$requestId] = ['error' => 'Invalid object ' . $instructions['objectId'] . ''];
                    continue;
                }
                $type = $object->objectType;
            }

            $settings = (isset($instructions['settings'])) ? $instructions['settings'] : [];
            switch ($instructions['type']) {
                case 'widget':
                    $widget = false;
                    if (isset($object)) {
                        $widgets = $object->objectTypeItem->widgets;
                        if (isset($widgets[$instructions['systemId']])) {
                            $widget = $widgets[$instructions['systemId']]->object;
                        }
                    } else {
                        $widget = Yii::$app->collectors['widgets']->getOne($instructions['systemId']);
                    }
                    if (!$widget) {
                        $refreshed[$requestId] = ['error' => 'Unknown widget'];

                        return;
                    }
                    $widgetObject = $widget->object;
                    if (isset($instructions['section'])
                        && ($sectionItem = Yii::$app->collectors['sections']->getOne($instructions['section']))
                        && ($section = $sectionItem->object)) {
                        $widgetObject->attachDecorator($section->widgetDecoratorClass);
                        $widgetObject->section = $section;
                    }
                    $widgetObject->owner = $widget->owner;
                    $refreshed[$requestId] = ['content' => $widgetObject->generate()];
                break;
            }
            if ($refreshed[$requestId]) {
                if ($stream) {
                    echo "data: " . json_encode(['type' => 'handleRequests', 'data' => [$requestId => $refreshed[$requestId]], 'id' => round(microtime(true) * 100)]);
                    echo "\n\n";
                } else {
                    $nonStreamResult[$requestId] = $refreshed[$requestId];
                }
                //echo str_repeat("\n\n",1024*4);
            }
        }
        if (!$stream) {
            echo json_encode(['requests' => $nonStreamResult]);
        }
        ob_implicit_flush(0);
        ob_start();
        Yii::$app->end();
        ob_end_clean();
    }
public function actionStream()
    {
        header("Content-type: text/plain");
        header("Access-Control-Allow-Origin: *");
        ob_implicit_flush(1);

        Yii::$app->response->task = false;
        $refreshed = [];
        $source = $_POST;
        $stream = false;
        if (!empty($source['__TODO_FIGURE_OUT_VIBE_STREAM_HINT__'])) { // @todo figure out this vibe hint thing
            $stream = true;
        }
        if (isset($source['when']) && $source['when'] === 'handshake') {
            echo json_encode(['id' => md5(microtime(true)), 'transports' => ['stream']]);

            return;
        }
        if (empty($source['requests'])) {
            echo json_encode([]);
            return;
        }
        $nonStreamResult = [];
        $baseInstrictions = (isset($source['baseInstructions']) ? $source['baseInstructions'] : []);
        foreach ($source['requests'] as $requestId => $request) {
            $refreshed[$requestId] = false;
            $instructions = $baseInstrictions;
            if (isset($request['instructions'])) {
                $instructions = array_merge($instructions, $request['instructions']);
            }
            if (empty($instructions['type']) || empty($instructions['type'])) {
                continue;
            }
            if (isset($request['state'])) {
                foreach ($request['state'] as $key => $value) {
                    Yii::$app->webState->set($key, $value);
                }
            }

            if (isset($instructions['objectId'])) {
                $object = Yii::$app->request->object = Registry::getObject($instructions['objectId']);
                if (!$object) {
                    $refreshed[$requestId] = ['error' => 'Invalid object ' . $instructions['objectId'] . ''];
                    continue;
                }
                $type = $object->objectType;
            }

            $settings = (isset($instructions['settings'])) ? $instructions['settings'] : [];
            switch ($instructions['type']) {
                case 'widget':
                    $widget = false;
                    if (isset($object)) {
                        $widgets = $object->objectTypeItem->widgets;
                        if (isset($widgets[$instructions['systemId']])) {
                            $widget = $widgets[$instructions['systemId']]->object;
                        }
                    } else {
                        $widget = Yii::$app->collectors['widgets']->getOne($instructions['systemId']);
                    }
                    if (!$widget) {
                        $refreshed[$requestId] = ['error' => 'Unknown widget'];

                        return;
                    }
                    $widgetObject = $widget->object;
                    if (isset($instructions['section'])
                        && ($sectionItem = Yii::$app->collectors['sections']->getOne($instructions['section']))
                        && ($section = $sectionItem->object)) {
                        $widgetObject->attachDecorator($section->widgetDecoratorClass);
                        $widgetObject->section = $section;
                    }
                    $widgetObject->owner = $widget->owner;
                    $refreshed[$requestId] = ['content' => $widgetObject->generate()];
                break;
            }
            if ($refreshed[$requestId]) {
                if ($stream) {
                    echo "data: " . json_encode(['type' => 'handleRequests', 'data' => [$requestId => $refreshed[$requestId]], 'id' => round(microtime(true) * 100)]);
                    echo "\n\n";
                } else {
                    $nonStreamResult[$requestId] = $refreshed[$requestId];
                }
                //echo str_repeat("\n\n",1024*4);
            }
        }
        if (!$stream) {
            echo json_encode(['requests' => $nonStreamResult]);
        }
        ob_implicit_flush(0);
        ob_start();
        Yii::$app->end();
        ob_end_clean();
    }
public function actionStream ( ) { header ( "Content-type: text/plain" ) ; header ( "Access-Control-Allow-Origin: *" ) ; ob_implicit_flush ( 1 ) ; Yii :: $ app -> response -> task = false ; $ refreshed = [ ] ; $ source = $ _POST ; $ stream = false ; if ( ! empty ( $ source [ '__TODO_FIGURE_OUT_VIBE_STREAM_HINT__' ] ) ) { // @todo figure out this vibe hint thing $ stream = true ; } if ( isset ( $ source [ 'when' ] ) && $ source [ 'when' ] === 'handshake' ) { echo json_encode ( [ 'id' => md5 ( microtime ( true ) ) , 'transports' => [ 'stream' ] ] ) ; return ; } if ( empty ( $ source [ 'requests' ] ) ) { echo json_encode ( [ ] ) ; return ; } $ nonStreamResult = [ ] ; $ baseInstrictions = ( isset ( $ source [ 'baseInstructions' ] ) ? $ source [ 'baseInstructions' ] : [ ] ) ; foreach ( $ source [ 'requests' ] as $ requestId => $ request ) { $ refreshed [ $ requestId ] = false ; $ instructions = $ baseInstrictions ; if ( isset ( $ request [ 'instructions' ] ) ) { $ instructions = array_merge ( $ instructions , $ request [ 'instructions' ] ) ; } if ( empty ( $ instructions [ 'type' ] ) || empty ( $ instructions [ 'type' ] ) ) { continue ; } if ( isset ( $ request [ 'state' ] ) ) { foreach ( $ request [ 'state' ] as $ key => $ value ) { Yii :: $ app -> webState -> set ( $ key , $ value ) ; } } if ( isset ( $ instructions [ 'objectId' ] ) ) { $ object = Yii :: $ app -> request -> object = Registry :: getObject ( $ instructions [ 'objectId' ] ) ; if ( ! $ object ) { $ refreshed [ $ requestId ] = [ 'error' => 'Invalid object ' . $ instructions [ 'objectId' ] . '' ] ; continue ; } $ type = $ object -> objectType ; } $ settings = ( isset ( $ instructions [ 'settings' ] ) ) ? $ instructions [ 'settings' ] : [ ] ; switch ( $ instructions [ 'type' ] ) { case 'widget' : $ widget = false ; if ( isset ( $ object ) ) { $ widgets = $ object -> objectTypeItem -> widgets ; if ( isset ( $ widgets [ $ instructions [ 'systemId' ] ] ) ) { $ widget = $ widgets [ $ instructions [ 'systemId' ] ] -> object ; } } else { $ widget = Yii :: $ app -> collectors [ 'widgets' ] -> getOne ( $ instructions [ 'systemId' ] ) ; } if ( ! $ widget ) { $ refreshed [ $ requestId ] = [ 'error' => 'Unknown widget' ] ; return ; } $ widgetObject = $ widget -> object ; if ( isset ( $ instructions [ 'section' ] ) && ( $ sectionItem = Yii :: $ app -> collectors [ 'sections' ] -> getOne ( $ instructions [ 'section' ] ) ) && ( $ section = $ sectionItem -> object ) ) { $ widgetObject -> attachDecorator ( $ section -> widgetDecoratorClass ) ; $ widgetObject -> section = $ section ; } $ widgetObject -> owner = $ widget -> owner ; $ refreshed [ $ requestId ] = [ 'content' => $ widgetObject -> generate ( ) ] ; break ; } if ( $ refreshed [ $ requestId ] ) { if ( $ stream ) { echo "data: " . json_encode ( [ 'type' => 'handleRequests' , 'data' => [ $ requestId => $ refreshed [ $ requestId ] ] , 'id' => round ( microtime ( true ) * 100 ) ] ) ; echo "\n\n" ; } else { $ nonStreamResult [ $ requestId ] = $ refreshed [ $ requestId ] ; } //echo str_repeat("\n\n",1024*4); } } if ( ! $ stream ) { echo json_encode ( [ 'requests' => $ nonStreamResult ] ) ; } ob_implicit_flush ( 0 ) ; ob_start ( ) ; Yii :: $ app -> end ( ) ; ob_end_clean ( ) ; }
[[@doctodo method_description:actionStream]].

@return [[@doctodo return_type:actionStream]] [[@doctodo return_description:actionStream]]
[[ @doctodo method_description : actionStream ]] .