8000 Revert "[HttpFoundation] Add a new method Request::addLink()" · symfony/symfony@c376a36 · GitHub
[go: up one dir, main page]

Skip to content

Commit c376a36

Browse files
committed
Revert "[HttpFoundation] Add a new method Request::addLink()"
This reverts commit e5be0ec.
1 parent 334fb25 commit c376a36

File tree

7 files changed

+40
-36
lines changed

7 files changed

+40
-36
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.2.0
55
-----
66

7+
* Added a `Symfony\Bundle\FrameworkBundle\Controller\AbstractController::addLink()` method to add Link headers to the current response
78
* Allowed configuring taggable cache pools via a new `framework.cache.pools.tags` option (bool|service-id)
89
* Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service
910
* Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Controller;
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
15+
use Fig\Link\GenericLinkProvider;
16+
use Fig\Link\Link;
1517
use Psr\Container\ContainerInterface;
1618
use Symfony\Component\Form\Extension\Core\Type\FormType;
1719
use Symfony\Component\Form\FormBuilderInterface;
1820
use Symfony\Component\Form\FormInterface;
1921
use Symfony\Component\HttpFoundation\BinaryFileResponse;
2022
use Symfony\Component\HttpFoundation\JsonResponse;
2123
use Symfony\Component\HttpFoundation\RedirectResponse;
24+
use Symfony\Component\HttpFoundation\Request;
2225
use Symfony\Component\HttpFoundation\Response;
2326
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
2427
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -27,6 +30,7 @@
2730
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2831
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2932
use Symfony\Component\Security\Csrf\CsrfToken;
33+
use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener;
3034

3135
/**
3236
* Common features needed in controllers.
@@ -398,4 +402,21 @@ protected function dispatchMessage($message)
398402

399403
return $this->container->get('message_bus')->dispatch($message);
400404
}
405+
406+
/**
407+
* Adds a Link HTTP header to the current response.
408+
*
409+
* @see https://tools.ietf.org/html/rfc5988
410+
*
411+
* @final
412+
*/
413+
protected function addLink(Request $request, Link $link)
414+
{
415+
if (!class_exists(AddLinkHeaderListener::class)) {
416+
throw new \LogicException('You can not use the "addLink" method if the WebLink component is not available. Try running "composer require symfony/weblink".');
417+
}
418+
419+
$linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
420+
$request->attributes->set('_links', $linkProvider->withLink($link));
421+
}
401422
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

14+
use Fig\Link\Link;
1415
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
1516
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1617
use Symfony\Component\DependencyInjection\Container;
@@ -528,6 +529,21 @@ public function testGetDoctrine()
528529

529530
$this->assertEquals($doctrine, $controller->getDoctrine());
530531
}
532+
533+
public function testAddLink()
534+
{
535+
$request = new Request();
536+
$link1 = new Link('mercure', 'https://demo.mercure.rocks');
537+
$link2 = new Link('self', 'https://example.com/foo');
538+
539+
$controller = $this->createController();
540+
$controller->addLink($request, $link1);
541+
$controller->addLink($request, $link2);
542+
543+
$links = $request->attributes->get('_links')->getLinks();
544+
$this->assertContains($link1, $links);
545+
$this->assertContains($link2, $links);
546+
}
531547
}
532548

533549
trait TestControllerTrait
@@ -552,5 +568,6 @@ trait TestControllerTrait
552568
createForm as public;
553569
createFormBuilder as public;
554570
getDoctrine as public;
571+
addLink as public;
555572
}
556573
}

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ CHANGELOG
44
4.2.0
55
-----
66

7-
* added a `Request::addLink()` method to add Link headers to the current response
87
* added `getAcceptableFormats()` for reading acceptable formats based on Accept header
98
* the default value of the "$secure" and "$samesite" arguments of Cookie's constructor
109
will respectively change from "false" to "null" and from "null" to "lax" in Symfony

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111

1212
namespace Symfony\Component\HttpFoundation;
1313

14-
use Fig\Link\GenericLinkProvider;
15-
use Fig\Link\Link;
1614
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
1715
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1816
use Symfony\Component\HttpFoundation\Session\SessionInterface;
19-
use Symfony\Component\WebLink\HttpHeaderSerializer;
2017

2118
/**
2219
* Request represents an HTTP request.
@@ -1698,21 +1695,6 @@ public function isXmlHttpRequest()
16981695
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
16991696
}
17001697

1701-
/**
1702-
* Adds a Link HTTP header to the corresponding response, using the WebLink component.
1703-
*
1704-
* @see https://tools.ietf.org/html/rfc5988
1705-
*/
1706-
public function addLink(Link $link)
1707-
{
1708-
if (!class_exists(HttpHeaderSerializer::class)) {
1709-
throw new \LogicException('You can not use the "addLink" method if the WebLink component is not available. Try running "composer require symfony/weblink".');
1710-
}
1711-
1712-
$linkProvider = $this->attributes->get('_links', new GenericLinkProvider());
1713-
$this->attributes->set('_links', $linkProvider->withLink($link));
1714-
}
1715-
17161698
/*
17171699
* The following methods are derived from code of the Zend Framework (1.10dev - 2010-01-24)
17181700
*

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

14-
use Fig\Link\Link;
1514
use PHPUnit\Framework\TestCase;
1615
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1716
use Symfony\Component\HttpFoundation\Request;
@@ -2213,20 +2212,6 @@ public function testTrustedPort()
22132212

22142213
$this->assertSame(443, $request->getPort());
22152214
}
2216-
2217-
public function testAddLink()
2218-
{
2219-
$request = new Request();
2220-
$link1 = new Link('mercure', 'https://demo.mercure.rocks');
2221-
$link2 = new Link('self', 'https://example.com/foo');
2222-
2223-
$request->addLink($link1);
2224-
$request->addLink($link2);
2225-
2226-
$links = $request->attributes->get('_links')->getLinks();
2227-
$this->assertContains($link1, $links);
2228-
$this->assertContains($link2, $links);
2229-
}
22302215
}
22312216

22322217
class RequestContentProxy extends Request

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
},
2222
"require-dev": {
2323
"predis/predis": "~1.0",
24-
"symfony/expression-language": "~3.4|~4.0",
25-
"symfony/web-link": "~3.4|~4.0"
24+
"symfony/expression-language": "~3.4|~4.0"
2625
},
2726
"autoload": {
2827
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },

0 commit comments

Comments
 (0)
0