Response example



namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class ProfilerController
{
    public function indexAction()
    {
        return new Response('Hello');
    }
}
public function onPostDispatch(Enlight_Controller_ActionEventArgs $args): void
    {
        $controller = $args->getSubject();
        $controller->View()->assign('httpCacheEnabled', $this->httpCacheEnabled);

        if (!$this->cookieRemovalActive) {
            return;
        }

        if ($this->httpCacheEnabled) {
            $controller->Response()->headers->set(
                CookieRemoveHandler::COOKIE_CONFIG_KEY,
                json_encode([
                    'cookieNoteMode' => $this->config->get('cookie_note_mode'),
                    'showCookieNote' => $this->config->get('show_cookie_note'),
                ], JSON_THROW_ON_ERROR)
            );
        }

        $allowCookie = $controller->Request()->cookies->getInt('allowCookie');
        if ($this->config->get('cookie_note_mode') !== self::COOKIE_MODE_TECHNICAL) {
            if ($allowCookie === 1) {
                


    public function getArguments(Request $request, callable $controller, \ReflectionFunctionAbstract $reflector = null): array
    {
        return [$request];
    }

    public function callController(Request $request)
    {
        $this->called = true;

        $response = new Response(array_shift($this->bodies)array_shift($this->statuses)array_shift($this->headers));

        return $response;
    }

    public function hasBeenCalled()
    {
        return $this->called;
    }

    public function reset()
    {
        
public function postAction(): void
    {
        $category = $this->resource->create($this->Request()->getPost());

        $location = $this->apiBaseUrl . 'properties/' . $category->getId();
        $data = [
            'id' => $category->getId(),
            'location' => $location,
        ];

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }

    /** * Update Property * * PUT /api/properties/{id} */
    public function putAction(): void
    {
        $id = $this->Request()->getParam('id');
        $params = $this->Request()->getPost();

        
$client->request('GET', '/logout');

        $this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
    }

    private function callInRequestContext(KernelBrowser $client, callable $callable): void
    {
        /** @var EventDispatcherInterface $eventDispatcher */
        $eventDispatcher = static::getContainer()->get(EventDispatcherInterface::class);
        $wrappedCallable = function DRequestEvent $event) use (&$callable) {
            $callable();
            $event->setResponse(new Response(''));
            $event->stopPropagation();
        };

        $eventDispatcher->addListener(KernelEvents::REQUEST, $wrappedCallable);
        try {
            $client->request('GET', '/'.uniqid('', true));
        } finally {
            $eventDispatcher->removeListener(KernelEvents::REQUEST, $wrappedCallable);
        }
    }
}
$kernel = $this->kernel = new ConcreteMicroKernel('test', false);
        $kernel->boot();

        self::assertSame('$ecret', $kernel->getContainer()->getParameter('kernel.secret'));
    }

    public function testAnonymousMicroKernel()
    {
        $kernel = $this->kernel = new class('anonymous_kernel') extends MinimalKernel {
            public function helloAction(): Response
            {
                return new Response('Hello World!');
            }

            protected function configureContainer(ContainerConfigurator $c): void
            {
                $c->extension('framework', [
                    'annotations' => false,
                    'http_method_override' => false,
                    'handle_all_throwables' => true,
                    'php_errors' => ['log' => true],
                    'router' => ['utf8' => true],
                ]);
                

    protected $session;

    /** * Pre dispatch method */
    public function preDispatch()
    {
        $this->module = Shopware()->Modules()->Basket();
        $this->session = Shopware()->Session();
        $this->Response()->setHeader('x-robots-tag', 'noindex');
    }

    public function infoAction()
    {
        $view = $this->View();

        $view->assign('userInfo', $this->get('shopware_account.store_front_greeting_service')->fetch());
        $view->assign('sBasketQuantity', isset($this->session->sBasketQuantity) ? $this->session->sBasketQuantity : 0);
        $view->assign('sBasketAmount', isset($this->session->sBasketAmount) ? $this->session->sBasketAmount : 0);
        $view->assign('sNotesQuantity', isset($this->session->sNotesQuantity) ? $this->session->sNotesQuantity : $this->module->sCountNotes());
        $view->assign('sUserLoggedIn', !empty(Shopware()->Session()->get('sUserId')));
        
class SecurityController implements ServiceSubscriberInterface
{
    private ContainerInterface $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function profileAction()
    {
        return new Response('Welcome '.$this->container->get('security.token_storage')->getToken()->getUserIdentifier().'!');
    }

    public static function getSubscribedServices(): array
    {
        return [
            'security.token_storage' => TokenStorageInterface::class,
        ];
    }
}
class Shopware_Controllers_Backend_Cron extends Enlight_Controller_Action implements CSRFWhitelistAware
{
    public function init()
    {
        Shopware()->Plugins()->Backend()->Auth()->setNoAuth();
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
    }

    public function indexAction()
    {
        if (!Shopware()->Plugins()->Core()->Cron()->authorizeCronAction($this->Request())) {
            $this->Response()
                ->clearHeaders()
                ->setStatusCode(Response::HTTP_FORBIDDEN)
                ->appendBody('Forbidden');

            return;
        }

        /** @var Enlight_Components_Cron_Manager $cronManager */
        $cronManager = Shopware()->Container()->get('cron');

        set_time_limit(0);
        
$location = $this->apiBaseUrl . 'users/' . $user->getId();
        $data = [
            'id' => $user->getId(),
            'location' => $location,
        ];
        if (isset($passwordPlain)) {
            $data['password'] = $passwordPlain;
        }

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }

    /** * Update user * * PUT /api/users/{id} */
    public function putAction(): void
    {
        $id = (int) $this->Request()->getParam('id');

        
namespace Symfony\Component\BrowserKit\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\Exception\JsonException;
use Symfony\Component\BrowserKit\Response;

class ResponseTest extends TestCase
{
    public function testGetUri()
    {
        $response = new Response('foo');
        $this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
    }

    public function testGetStatusCode()
    {
        $response = new Response('foo', 304);
        $this->assertEquals('304', $response->getStatusCode(), '->getStatusCode() returns the status of the response');
    }

    public function testGetHeaders()
    {
        
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
use Symfony\Component\HttpKernel\Kernel;

class ConfigDataCollectorTest extends TestCase
{
    public function testCollect()
    {
        $kernel = new KernelForTest('test', true);
        $c = new ConfigDataCollector();
        $c->setKernel($kernel);
        $c->collect(new Request()new Response());

        $this->assertSame('test', $c->getEnv());
        $this->assertTrue($c->isDebug());
        $this->assertSame('config', $c->getName());
        $this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION);
        $this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION);
        $this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture());
        $this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
        $this->assertSame(date_default_timezone_get()$c->getPhpTimezone());
        $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
        $this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts());
        
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;

class LazyLoadingFragmentHandlerTest extends TestCase
{
    public function testRender()
    {
        $renderer = $this->createMock(FragmentRendererInterface::class);
        $renderer->expects($this->once())->method('getName')->willReturn('foo');
        $renderer->expects($this->any())->method('render')->willReturn(new Response());

        $requestStack = $this->createMock(RequestStack::class);
        $requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));

        $container = $this->createMock(ContainerInterface::class);
        $container->expects($this->once())->method('has')->with('foo')->willReturn(true);
        $container->expects($this->once())->method('get')->willReturn($renderer);

        $handler = new LazyLoadingFragmentHandler($container$requestStack, false);

        $handler->render('/foo', 'foo');

        
class ExceptionDataCollectorTest extends TestCase
{
    public function testCollect()
    {
        $e = new \Exception('foo', 500);
        $c = new ExceptionDataCollector();
        $flattened = FlattenException::createWithDataRepresentation($e);
        $trace = $flattened->getTrace();

        $this->assertFalse($c->hasException());

        $c->collect(new Request()new Response()$e);

        $this->assertTrue($c->hasException());
        $this->assertEquals($flattened$c->getException());
        $this->assertSame('foo', $c->getMessage());
        $this->assertSame(500, $c->getCode());
        $this->assertSame('exception', $c->getName());
        $this->assertSame($trace$c->getTrace());
    }

    public function testCollectWithoutException()
    {
        

  protected function handleException(\Exception $e$request$type) {
    if ($this->shouldRedirectToInstaller($e$this->container ? $this->container->get('database') : NULL)) {
      return new RedirectResponse($request->getBasePath() . '/core/install.php', 302, ['Cache-Control' => 'no-cache']);
    }

    if ($e instanceof HttpExceptionInterface) {
      $response = new Response($e->getMessage()$e->getStatusCode());
      $response->headers->add($e->getHeaders());
      return $response;
    }

    throw $e;
  }

  /** * Returns module data on the filesystem. * * @param $module * The name of the module. * * @return \Drupal\Core\Extension\Extension|bool * Returns an Extension object if the module is found, FALSE otherwise. */
Home | Imprint | This part of the site doesn't use cookies.