Issues (1)

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.php (1 issue)

Labels
Severity

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 declare(strict_types=1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 26.01.16 at 15:11
5
 */
6
namespace samsonframework\di;
7
use samsonframework\container\ContainerInterface;
8
use samsonframework\di\exception\ClassNotFoundException;
9
use samsonframework\di\exception\ContainerException;
10
11
/**
12
 * Dependency container.
13
 *
14
 * @author Vitaly Iegorov <[email protected]>
15
 */
16
class Container implements ContainerInterface
17
{
18
    /** @var array Collection of instantiated service instances */
19
    protected $serviceInstances = [];
20
    /** @var array[string] Collection of loaded services */
21
    protected $services = [];
22
    /** @var array[string] Collection of alias => class name for alias resolving */
23
    protected $aliases = [];
24
    /** @var array[string] Collection of class name dependencies trees */
25
    protected $dependencies = [];
26
    /** @var ContainerInterface[] Collection of delegated containers */
27
    protected $delegates = [];
28
    /** @var callable Dependency resolving function callable */
29
    protected $logicCallable;
30
    /** @var array Collection of scope => [alias => class_name] */
31
    protected $scopes = [];
32
    /**
33
     * Wrapper for calling dependency resolving function.
34
     *
35
     * @param string $dependency Dependency name
36
     *
37
     * @return mixed Created instance or null
38
     * @throws ContainerException
39
     */
40 5
    protected function logic($dependency)
41
    {
42 5
        if (!is_callable($this->logicCallable)) {
43 2
            throw new ContainerException('Logic function is not callable');
44
        }
45 4
        return call_user_func($this->logicCallable, $dependency);
46
    }
47
48
    /**
49
     * Get parameter
50
     *
51
     * @param $name
52
     */
53
    public function getParameter($name)
54
    {
55
        return $this->parameter($name);
0 ignored issues
show
The method parameter() does not exist on samsonframework\di\Container. Did you maybe mean getParameter()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     *
61
     * @throws \samsonframework\di\exception\ContainerException
62
     * @throws \samsonframework\di\exception\ClassNotFoundException
63
     */
64 5
    public function get($dependency)
65
    {
66
        // Get pointer from logic
67 5
        $module = $this->logic($dependency) ?? $this->getFromDelegate($dependency);
68 4
        if (null === $module) {
69 1
            throw new ClassNotFoundException($dependency);
70
        } else {
71 3
            return $module;
72
        }
73
    }
74
    /**
75
     * Try to find dependency in delegate container.
76
     *
77
     * @param string $dependency Dependency identifier
78
     *
79
     * @return mixed Delegate found dependency
80
     *
81
     * @throws \Interop\Container\Exception\ContainerException
82
     */
83 2
    protected function getFromDelegate(string $dependency)
84
    {
85
        // Try delegate lookup
86 2
        foreach ($this->delegates as $delegate) {
87
            try {
88 2
                return $delegate->get($dependency);
89 1
            } catch (ContainerException $e) {
90
                // Catch all delegated exceptions
91 1
            } catch (ClassNotFoundException $e) {
92
                // Catch all delegated exceptions
93
            }
94
        }
95 1
        return null;
96
    }
97
    /**
98
     * Implementing delegate lookup feature.
99
     * If current container cannot resolve entity dependency
100
     * resolving process is passed to delegated container.
101
     *
102
     * @param ContainerInterface $container Container for delegate lookup
103
     */
104 3
    public function delegate(ContainerInterface $container)
105
    {
106 3
        $this->delegates[] = $container;
107 3
    }
108
    /**
109
     * {@inheritdoc}
110
     */
111 2
    public function has($dependency) : bool
112
    {
113 2
        $found = array_key_exists($dependency, $this->dependencies)
114 2
            || in_array($dependency, $this->aliases, true);
115
        // Return true if found or try delegate containers
116 2
        return $found ?: $this->hasDelegate($dependency);
117
    }
118
    /**
119
     * Define if delegate containers have dependency.
120
     *
121
     * @param string $dependency Dependency identifier
122
     *
123
     * @return bool True if delegate containers have dependency
124
     */
125 2
    protected function hasDelegate(string $dependency) : bool
126
    {
127 2
        foreach ($this->delegates as $delegate) {
128 1
            if ($delegate->has($dependency)) {
129 1
                return true;
130
            }
131
        }
132 2
        return false;
133
    }
134
    /**
135
     * Set service dependency. Upon first creation of this class instance
136
     * it would be used everywhere where this dependency is needed.
137
     *
138
     * @param string $className  Fully qualified class name
139
     * @param array  $parameters Collection of parameters needed for dependency creation
140
     * @param string $alias      Dependency name
141
     *
142
     * @return ContainerInterface Chaining
143
     */
144 9
    public function service($className, array $parameters = [], string $alias = null) : ContainerInterface
145
    {
146 9
        $this->services[$className] = $className;
147 9
        return $this->set($className, $parameters, $alias);
148
    }
149
    /**
150
     * {@inheritdoc}
151
     */
152 9
    public function set($className, array $dependencies = [], string $alias = null) : ContainerInterface
153
    {
154
        // Create dependencies collection for class name
155 9
        if (!array_key_exists($className, $this->dependencies)) {
156 9
            $this->dependencies[$className] = [];
157
        }
158
159
        // Merge other class constructor parameters
160 9
        $this->dependencies[$className] = array_merge($this->dependencies[$className], $dependencies);
161
        // Store alias for this class name
162 9
        $this->aliases[$className] = $alias;
163 9
        return $this;
164
    }
165
    /**
166
     * {@inheritdoc}
167
     */
168 1
    public function getServices(string $filterScope = null) : array
169
    {
170 1
        $filtered = [];
171 1
        if ($filterScope !== null && array_key_exists($filterScope, $this->scopes)) {
172
            foreach ($this->scopes[$filterScope] as $alias => $className) {
173
                $filtered[] = $this->get($className);
174
            }
175
        }
176 1
        return $filtered;
177
    }
178
}