Issues (25)

Security Analysis    no request data  

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.

src/Container/ServicesContainer.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
 * Created by PhpStorm.
4
 * User: Ricardo Fiorani
5
 * Date: 31/08/2015
6
 * Time: 21:06.
7
 */
8
namespace RicardoFiorani\Container;
9
10
use RicardoFiorani\Adapter\CallableServiceAdapterFactoryInterface;
11
use RicardoFiorani\Exception\DuplicatedServiceNameException;
12
use RicardoFiorani\Renderer\EmbedRendererInterface;
13
14
class ServicesContainer
15
{
16
    /**
17
     * @var array
18
     */
19
    private $services = array();
20
21
    /**
22
     * @var array
23
     */
24
    private $patterns = array();
25
26
    /**
27
     * @var array
28
     */
29
    private $factories = array();
30
31
    /**
32
     * @var array
33
     */
34
    private $instantiatedFactories = array();
35
36
    /**
37
     * @var EmbedRendererInterface
38
     */
39
    private $renderer;
40
41
    /**
42
     * @var string
43
     */
44
    private $rendererName;
45
46
    /**
47
     * ServicesContainer constructor.
48
     *
49
     * @param array $config
50
     */
51
    public function __construct(array $config = array())
52
    {
53
        if (false == empty($config)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
54
            $this->registerFromConfig($config);
55
        }
56
    }
57
58
    /**
59
     * Loads de default config file.
60
     *
61
     * @param array $config
62
     *
63
     * @throws DuplicatedServiceNameException
64
     */
65
    private function registerFromConfig(array $config)
66
    {
67
        foreach ($config['services'] as $serviceName => $serviceConfig) {
68
            $this->registerService($serviceName, $serviceConfig['patterns'], $serviceConfig['factory']);
69
        }
70
        $this->setRenderer($config['renderer']['name'], $config['renderer']['factory']);
71
    }
72
73
    /**
74
     * Register a Service.
75
     *
76
     * @param string          $serviceName
77
     * @param array           $regex
78
     * @param string|callable $factory
79
     *
80
     * @throws DuplicatedServiceNameException
81
     */
82
    public function registerService($serviceName, array $regex, $factory)
83
    {
84
        if ($this->hasService($serviceName)) {
85
            throw new DuplicatedServiceNameException();
86
        }
87
88
        $this->services[] = $serviceName;
89
        $this->patterns[$serviceName] = $regex;
90
        $this->factories[$serviceName] = $factory;
91
    }
92
93
    /**
94
     * @param string $rendererName
95
     * @param string $rendererFactory
96
     */
97
    public function setRenderer($rendererName, $rendererFactory)
98
    {
99
        $this->rendererName = $rendererName;
100
        $factory = new $rendererFactory();
101
        $this->renderer = $factory();
102
    }
103
104
    /**
105
     * @return EmbedRendererInterface
106
     */
107
    public function getRenderer()
108
    {
109
        return $this->renderer;
110
    }
111
112
    /**
113
     * @return array
114
     */
115
    public function getServiceNameList()
116
    {
117
        return $this->services;
118
    }
119
120
    /**
121
     * @param string $serviceName
122
     *
123
     * @return bool
124
     */
125
    public function hasService($serviceName)
126
    {
127
        return in_array($serviceName, $this->services);
128
    }
129
130
    /**
131
     * @return array
132
     */
133
    public function getServices()
134
    {
135
        return $this->services;
136
    }
137
138
    /**
139
     * @return array
140
     */
141
    public function getPatterns()
142
    {
143
        return $this->patterns;
144
    }
145
146
    /**
147
     * @param string $serviceName
148
     *
149
     * @return CallableServiceAdapterFactoryInterface
150
     */
151
    public function getFactory($serviceName)
152
    {
153
        $factory = new $this->factories[$serviceName]();
154
        if (isset($this->instantiatedFactories[$serviceName])) {
155
            return $this->instantiatedFactories[$serviceName];
156
        }
157
158
        return $this->instantiatedFactories[$serviceName] = $factory;
159
    }
160
}
161