setBody example

 elseif (\is_string($this->padding) && $this->padding !== '') {
            $content = $response->getBody();
        } else {
            return;
        }

        // Convert content to json         $content = $this->convertToJson($content);

        if (\is_string($this->padding) && $this->padding !== '') {
            $response->setHeader('Content-type', 'text/javascript', true);
            $response->setBody($this->addPadding($content$this->padding));
        } elseif ($this->renderer === true) {
            $response->setHeader('Content-type', 'application/json', true);
            $response->setBody($content);
        }

        $this->padding = null;
        $this->encoding = 'UTF-8';
        $this->renderer = false;
    }

    /** * Sometimes it is necessary to pad an JSON object into a javascript function. If this behaviour is needed * this method can be called with a true value as parameter to enable the padding mode. * If this mode is active the system takes the name found in the GET parameter 'callback' as the javascript function * name. * * @param bool $padding * * @return Enlight_Controller_Plugins_Json_Bootstrap */
// Replace style and script placeholders with nonces         $pattern = '/(' . preg_quote($this->styleNonceTag, '/')
            . '|' . preg_quote($this->scriptNonceTag, '/') . ')/';

        $body = preg_replace_callback($patternfunction D$match) {
            $nonce = $match[0] === $this->styleNonceTag ? $this->getStyleNonce() : $this->getScriptNonce();

            return "nonce=\"{$nonce}\"";
        }$body);

        $response->setBody($body);
    }

    /** * Based on the current state of the elements, will add the appropriate * Content-Security-Policy and Content-Security-Policy-Report-Only headers * with their values to the response object. * * @return void */
    protected function buildHeaders(ResponseInterface $response)
    {
        
$this->expectException(\Exception::class);
        $this->expectExceptionMessage('Email "abc" does not comply with addr-spec of RFC 2822.');
        /* -- RFC 2822, 3.6.4. msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS] */
        new IdentificationHeader('References', 'abc');
    }

    public function testSetBody()
    {
        $header = new IdentificationHeader('Message-ID', 'c@d');
        $header->setBody('a@b');
        $this->assertEquals(['a@b']$header->getIds());
    }

    public function testGetBody()
    {
        $header = new IdentificationHeader('Message-ID', 'a@b');
        $this->assertEquals(['a@b']$header->getBody());
    }

    public function testStringValue()
    {
        
$script = PHP_EOL
                . '<script ' . csp_script_nonce() . ' id="debugbar_loader" '
                . 'data-time="' . $time . '" '
                . 'src="' . site_url() . '?debugbar"></script>'
                . '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
                . '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
                . $kintScript
                . PHP_EOL;

            if (strpos($response->getBody(), '<head>') !== false) {
                $response->setBody(
                    preg_replace(
                        '/<head>/',
                        '<head>' . $script,
                        $response->getBody(),
                        1
                    )
                );

                return;
            }

            
public function getHeaderBody(string $name): mixed
    {
        return $this->has($name) ? $this->get($name)->getBody() : null;
    }

    /** * @internal */
    public function setHeaderBody(string $type, string $name, mixed $body): void
    {
        if ($this->has($name)) {
            $this->get($name)->setBody($body);
        } else {
            $this->{'add'.$type.'Header'}($name$body);
        }
    }

    public function getHeaderParameter(string $name, string $parameter): ?string
    {
        if (!$this->has($name)) {
            return null;
        }

        
public function testConstruct()
    {
        $m = new Message();
        $this->assertNull($m->getBody());
        $this->assertEquals(new Headers()$m->getHeaders());

        $m = new Message($h = (new Headers())->addDateHeader('Date', new \DateTimeImmutable())$b = new TextPart('content'));
        $this->assertSame($b$m->getBody());
        $this->assertEquals($h$m->getHeaders());

        $m = new Message();
        $m->setBody($b);
        $m->setHeaders($h);
        $this->assertSame($b$m->getBody());
        $this->assertSame($h$m->getHeaders());
    }

    public function testGetPreparedHeadersThrowsWhenNoFrom()
    {
        $this->expectException(\LogicException::class);
        (new Message())->getPreparedHeaders();
    }

    
 finally {
            $info['download_content_length'] = $info['size_download'];
        }

        self::stopLoop();
    }

    private static function followRedirects(Request $originRequest, AmpClientState $multi, array &$info, array &$headers, CancellationTokenSource $canceller, array $options, \Closure $onProgress, &$handle, ?LoggerInterface $logger, Promise &$pause): \Generator
    {
        yield $pause;

        $originRequest->setBody(new AmpBody($options['body']$info$onProgress));
        $response = yield $multi->request($options$originRequest$canceller->getToken()$info$onProgress$handle);
        $previousUrl = null;

        while (true) {
            self::addResponseHeaders($response$info$headers);
            $status = $response->getStatus();

            if (!\in_array($status[301, 302, 303, 307, 308], true) || null === $location = $response->getHeader('location')) {
                return $response;
            }

            


        if ($this->uri instanceof URI) {
            $this->uri = Services::uri($this->appConfig->baseURL ?? 'http://example.com/', false);
        }

        if (empty($this->request)) {
            // Do some acrobatics so we can use the Request service with our own URI             $tempUri = Services::uri();
            Services::injectMock('uri', $this->uri);

            $this->withRequest(Services::request($this->appConfig, false)->setBody($this->body));

            // Restore the URI service             Services::injectMock('uri', $tempUri);
        }

        if (empty($this->response)) {
            $this->response = Services::response($this->appConfig, false);
        }

        if (empty($this->logger)) {
            $this->logger = Services::logger();
        }
// Clear all default headers             foreach (array_keys($response->headers()) as $key) {
                $response->removeHeader($key);
            }

            // Set cached headers             foreach ($headers as $name => $value) {
                $response->setHeader($name$value);
            }

            $response->setBody($output);

            return $response;
        }

        return null;
    }
}


    public function testGetValueReturnsMailboxStringValueForMultipleMailboxes()
    {
        $header = new MailboxListHeader('From', [new Address('chris@swiftmailer.org', 'Chris Corbyn')new Address('mark@swiftmailer.org', 'Mark Corbyn')]);
        $this->assertEquals('Chris Corbyn <chris@swiftmailer.org>, Mark Corbyn <mark@swiftmailer.org>', $header->getBodyAsString());
    }

    public function testSetBody()
    {
        $header = new MailboxListHeader('From', []);
        $header->setBody($addresses = [new Address('chris@swiftmailer.org')]);
        $this->assertEquals($addresses$header->getAddresses());
    }

    public function testGetBody()
    {
        $header = new MailboxListHeader('From', $addresses = [new Address('chris@swiftmailer.org')]);
        $this->assertEquals($addresses$header->getBody());
    }

    public function testToString()
    {
        
$value = 'fo'.pack('C', 0x8F).'bar';
        $header = new UnstructuredHeader('Subject', $value);
        $header->setLanguage('en');
        $header->setCharset('iso-8859-1');
        $this->assertEquals('Subject: =?iso-8859-1*en?Q?fo=8Fbar?=', $header->toString());
    }

    public function testSetBody()
    {
        $header = new UnstructuredHeader('X-Test', '');
        $header->setBody('test');
        $this->assertEquals('test', $header->getValue());
    }

    public function testGetBody()
    {
        $header = new UnstructuredHeader('Subject', 'test');
        $this->assertEquals('test', $header->getBody());
    }
}

    public function execute(string $method, ...$params)
    {
        if (method_exists($this->controller, $method) || ! is_callable([$this->controller, $method])) {
            throw new InvalidArgumentException('Method does not exist or is not callable in controller: ' . $method);
        }

        $response = null;
        $this->request->setBody($this->body);

        try {
            ob_start();
            $response = $this->controller->{$method}(...$params);
        } catch (Throwable $e) {
            $code = $e->getCode();

            // If code is not a valid HTTP status then assume there is an error             if ($code < 100 || $code >= 600) {
                throw $e;
            }
        }
unset($options['headers']);
        }

        if (array_key_exists('delay', $options)) {
            // Convert from the milliseconds passed in             // to the seconds that sleep requires.             $this->delay = (float) $options['delay'] / 1000;
            unset($options['delay']);
        }

        if (array_key_exists('body', $options)) {
            $this->setBody($options['body']);
            unset($options['body']);
        }

        foreach ($options as $key => $value) {
            $this->config[$key] = $value;
        }
    }

    /** * If the $url is a relative URL, will attempt to create * a full URL by prepending $this->baseURI to it. */

    public function testConstructor()
    {
        $header = new MailboxHeader('Sender', $address = new Address('fabien@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
    }

    public function testAddress()
    {
        $header = new MailboxHeader('Sender', new Address('fabien@symfony.com'));
        $header->setBody($address = new Address('helene@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
        $header->setAddress($address = new Address('thomas@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
    }

    public function testgetBodyAsString()
    {
        $header = new MailboxHeader('Sender', new Address('fabien@symfony.com'));
        $this->assertEquals('fabien@symfony.com', $header->getBodyAsString());

        
/** * @internal */
class ProxyGenerator implements ProxyGeneratorInterface
{
    public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = []): void
    {
        (new LazyLoadingValueHolderGenerator())->generate($originalClass$classGenerator$proxyOptions);

        foreach ($classGenerator->getMethods() as $method) {
            if (str_starts_with($originalClass->getFilename(), __FILE__)) {
                $method->setBody(str_replace(var_export($originalClass->name, true), '__CLASS__', $method->getBody()));
            }
        }

        if (str_starts_with($originalClass->getFilename(), __FILE__)) {
            $interfaces = $classGenerator->getImplementedInterfaces();
            array_pop($interfaces);
            $classGenerator->setImplementedInterfaces(array_merge($interfaces$originalClass->getInterfaceNames()));
        }
    }

    public function getProxifiedClass(Definition $definition): ?string
    {
Home | Imprint | This part of the site doesn't use cookies.