getRawBody example

$db = $this->get('db');
        $select = $db->select()
                     ->from('s_core_auth')
                     ->where('username LIKE ?', $identity['username']);

        $user = $db->query($select)->fetchObject();
        if (!empty($user->roleID)) {
            $user->role = $this->get(ModelManager::class)->find(Role::class$user->roleID);
        }
        $auth->getStorage()->write($user);

        $rawBody = $request->getRawBody();

        try {
            if ($rawBody != '') {
                $input = Zend_Json::decode($rawBody);
            } else {
                $input = null;
            }
        } catch (Zend_Json_Exception $e) {
            $response->setStatusCode(Response::HTTP_BAD_REQUEST);

            $request->setControllerName('error');
            
'timeout' => 3,
                ]);

                if ($cacheId) {
                    $client->setHeaders('x-shopware-invalidates', $cacheId);
                }

                $response = $client->request('BAN');
                if ($response->getStatus() < 200 || $response->getStatus() >= 300) {
                    $this->get('corelogger')->error(
                        'Reverse proxy returned invalid status code',
                        ['response' => $response->getRawBody(), 'code' => $response->getStatus()]
                    );
                }
            } catch (Exception $e) {
                $this->get('corelogger')->error($e->getMessage()['exception' => $e]);
                $success = false;
            }
        }

        return $success;
    }

    

    public function onPreDispatch(Enlight_Event_EventArgs $args)
    {
        /** @var Enlight_Controller_Action $subject */
        $subject = $args->get('subject');
        $request = $subject->Request();

        // Parses the json input data, if the content type is correct         $contentType = $request->getHeader('Content-Type');
        $input = $request->getRawBody();
        if (
            $this->parseInput === true
            && \is_string($contentType)
            && str_starts_with($contentType, 'application/json')
            && \is_string($input)
        ) {
            if ($input !== '') {
                $input = Zend_Json::decode($input);
            } else {
                $input = null;
            }

            
return $str;
    }

    /** * Get the entire response as string * * @param string $br Line breaks (eg. "\n", "\r\n", "<br />") * @return string */
    public function asString($br = "\n")
    {
        return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
    }

    /** * Implements magic __toString() * * @return string */
    public function __toString()
    {
        return $this->asString();
    }

    
Home | Imprint | This part of the site doesn't use cookies.