Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

SeoBundle/Controller/RobotsController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\SeoBundle\Controller;
4
5
use Symfony\Component\Routing\Annotation\Route;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class RobotsController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
11
{
12
    /**
13
     * Generates the robots.txt content when available in the database and falls back to normal robots.txt if exists
14
     *
15
     * @Route(path="/robots.txt", name="KunstmaanSeoBundle_robots", defaults={"_format": "txt"})
16
     * @Template(template="@KunstmaanSeo/Admin/Robots/index.html.twig")
17
     *
18
     * @param Request $request
19
     *
20
     * @return array
21
     */
22
    public function indexAction(Request $request)
23
    {
24
        $entity = $this->getDoctrine()->getRepository('KunstmaanSeoBundle:Robots')->findOneBy(array());
25
        $robots = $this->getParameter('robots_default');
26
27
        if ($entity && $entity->getRobotsTxt()) {
28
            $robots = $entity->getRobotsTxt();
29
        } else {
30
            $file = $request->getBasePath() . 'robots.txt';
31
            if (file_exists($file)) {
32
                $robots = file_get_contents($file);
33
            }
34
        }
35
36
        return array('robots' => $robots);
37
    }
38
}
39