public function onKernelResponse(FilterResponseEvent $event) { if (!$this->enabled) { return; } $isNoindex = $this->xRobotsTag->isNoindex(); $isNofollow = $this->xRobotsTag->isNofollow(); if (!$this->xRobotsTag->isExplicitlySet()) { $requiredUserRoles = $this->getRequiredUserRolesForRequest($event->getRequest()); foreach ($requiredUserRoles as $requiredUserRole) { if ($this->xRobotsTag->isNoindexForUserRole($requiredUserRole) || $this->xRobotsTag->isNofollowForUserRole($requiredUserRole)) { $isNoindex = $this->xRobotsTag->isNoindexForUserRole($requiredUserRole); $isNofollow = $this->xRobotsTag->isNofollowForUserRole($requiredUserRole); break; } } } $tags = []; if ($isNoindex) { $tags[] = 'noindex'; } if ($isNofollow) { $tags[] = 'nofollow'; } if (count($tags)) { $event->getResponse()->headers->set('X-Robots-Tag', implode(',', $tags)); } }
public function testSetterAndGetter() { $xRobotsTag = new XRobotsTag(); $xRobotsTag->setNoindex(true); $this->assertTrue($xRobotsTag->isNoindex()); $this->assertFalse($xRobotsTag->isNofollow()); $xRobotsTag->setNofollow(true); $this->assertTrue($xRobotsTag->isNoindex()); $this->assertTrue($xRobotsTag->isNofollow()); $xRobotsTag->setNofollow(false); $this->assertTrue($xRobotsTag->isNoindex()); $this->assertFalse($xRobotsTag->isNofollow()); $xRobotsTag->setNoindex(false); $this->assertFalse($xRobotsTag->isNoindex()); $this->assertFalse($xRobotsTag->isNofollow()); }