Issues (89)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Twig/Extension/Page.php (15 issues)

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 DoS\ResourceBundle\Twig\Extension;
4
5
use DoS\ResourceBundle\Templating\PageBuilder;
6
use Sonata\SeoBundle\Twig\Extension\SeoExtension;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\HttpFoundation\RequestStack;
9
use Symfony\Component\Routing\RouterInterface;
10
11
class Page extends \Twig_Extension
12
{
13
    /**
14
     * @var PageBuilder
15
     */
16
    private $pageBuilder;
17
18
    /**
19
     * @var RouterInterface
20
     */
21
    private $router;
22
23
    /**
24
     * @var RequestStack
25
     */
26
    private $request;
27
28
    /**
29
     * @var SeoExtension
30
     */
31
    private $seoExtension;
32
33
    public function __construct(PageBuilder $pageBuilder, SeoExtension $seoExtension = null)
34
    {
35
        $this->pageBuilder = $pageBuilder;
36
        $this->seoExtension = $seoExtension;
37
    }
38
39
    /**
40
     * @param ContainerInterface $container
41
     */
42
    public function setContainer(ContainerInterface $container)
43
    {
44
        $this->router = $container->get('router');
45
        $this->request = $container->get('request_stack');
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function getFunctions()
52
    {
53
        return array_merge(array(
54
            new \Twig_SimpleFunction('ui_page', array($this, 'getUiFile')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
55
            new \Twig_SimpleFunction('ui_page_is', array($this, 'isPageId')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
56
            new \Twig_SimpleFunction('ui_page_get', array($this, 'getPageOption')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
57
            new \Twig_SimpleFunction('ui_page_options', array($this, 'setPageOptions')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
58
            new \Twig_SimpleFunction('ui_page_actions', array($this, 'getUiPageActions')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
59
            new \Twig_SimpleFunction('ui_page_self', array($this, 'getUiPageSelf')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
60
            new \Twig_SimpleFunction('ui_css_if', array($this, 'getCssIfMatchRoute')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
61
        ), $this->seoExtension ? array(
62
            new \Twig_SimpleFunction('ui_seo_title', array($this->seoExtension, 'getTitle'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
63
            new \Twig_SimpleFunction('ui_seo_metadatas', array($this->seoExtension, 'getMetadatas'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
64
            new \Twig_SimpleFunction('ui_seo_html_attributes', array($this->seoExtension, 'getHtmlAttributes'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
65
            new \Twig_SimpleFunction('ui_seo_head_attributes', array($this->seoExtension, 'getHeadAttributes'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
66
            new \Twig_SimpleFunction('ui_seo_link_canonical', array($this->seoExtension, 'getLinkCanonical'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
67
            new \Twig_SimpleFunction('ui_seo_lang_alternates', array($this->seoExtension, 'getLangAlternates'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
68
            new \Twig_SimpleFunction('ui_seo_oembed_links', array($this->seoExtension, 'getOembedLinks'), array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
69
        ) : array());
70
    }
71
72
    /**
73
     * @param $file
74
     * @param \Twig_Template|null $scope
75
     *
76
     * @return string
77
     */
78
    public function getUiFile($file, \Twig_Template $scope = null)
79
    {
80
        if ($scope) {
81
            return $this->getUiPageSelf($scope, $file);
82
        }
83
84
        return sprintf('ui:%s.html.twig', $file);
85
    }
86
87
    /**
88
     * @param \Twig_Template $scope
89
     * @param null|string    $name
90
     *
91
     * @return mixed|string
92
     */
93
    public function getUiPageActions(\Twig_Template $scope, $name = null)
94
    {
95
        $file = $scope->getTemplateName();
96
        $pattern = '/ui\:(.*):(.*)\.html\.twig/';
97
98
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
99
            $file = preg_replace($pattern, sprintf('ui:$1/Actions:%s.html.twig', $name), $file);
100
        } else {
101
            $file = preg_replace($pattern, 'ui:$1/Actions:${2}.html.twig', $file);
102
        }
103
104
        return $file;
105
    }
106
107
    /**
108
     * @param \Twig_Template $scope
109
     * @param string         $name
110
     *
111
     * @return mixed
112
     */
113
    public function getUiPageSelf(\Twig_Template $scope, $name)
114
    {
115
        $file = $scope->getTemplateName();
116
        $pattern = '/ui\:(.*):(.*)\.html\.twig/';
117
118
        return preg_replace($pattern, sprintf('ui:$1:%s.html.twig', $name), $file);
119
    }
120
121
    /**
122
     * @param array $options
123
     */
124
    public function setPageOptions(array $options = array())
125
    {
126
        $this->pageBuilder->setOptions($options);
127
    }
128
129
    /**
130
     * @param string $option
131
     * @param string $printOut
132
     * @param null   $default
133
     *
134
     * @return string
135
     */
136
    public function getPageOption($option, $printOut = '%s', $default = null)
137
    {
138
        return $this->pageBuilder->get($option, $printOut, $default);
139
    }
140
141
    /**
142
     * @param $id
143
     *
144
     * @return bool
145
     */
146
    public function isPageId($id)
147
    {
148
        return $this->pageBuilder->getOption('id') === $id;
149
    }
150
151
    /**
152
     * @param string|bool $check
153
     * @param string      $css
154
     *
155
     * @return null|string
156
     */
157
    public function getCssIfMatchRoute($check, $css = 'active')
158
    {
159
        if (is_string($check)) {
160
            $matcher = $this->router->match($this->request->getCurrentRequest()->getPathInfo());
161
            $check = $matcher['_route'] === $check;
162
        }
163
164
        return $check ? $css : null;
165
    }
166
167
    /**
168
     * @inheritdoc
169
     */
170
    public function getName()
171
    {
172
        return 'ui_page';
173
    }
174
}
175