LocalProxy::__getClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * \AppserverIo\RemoteMethodInvocation\LocalProxy
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/rmi
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\RemoteMethodInvocation;
22
23
use AppserverIo\Psr\EnterpriseBeans\BeanContextInterface;
24
use AppserverIo\Psr\EnterpriseBeans\Description\SessionBeanDescriptorInterface;
25
use AppserverIo\Psr\EnterpriseBeans\Description\StatefulSessionBeanDescriptorInterface;
26
27
/**
28
 * Local proxy implementation.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io/rmi
34
 * @link      http://www.appserver.io
35
 */
36
class LocalProxy implements RemoteObjectInterface
37
{
38
39
    /**
40
     * The bean manager instance.
41
     *
42
     * @var \AppserverIo\Psr\EnterpriseBeans\BeanContextInterface
43
     */
44
    protected $beanManager;
45
46
    /**
47
     * The session bean descriptor.
48
     *
49
     * @var \AppserverIo\Psr\EnterpriseBeans\Description\SessionBeanDescriptorInterface
50
     */
51
    protected $sessionBeanDescriptor;
52
53
    /**
54
     * The session been that has to be proxied.
55
     *
56
     * @var object
57
     */
58
    protected $sessionBean;
59
60
    /**
61
     * The actual session ID.
62
     *
63
     * @var string
64
     */
65
    protected $sessionId;
66
67
    /**
68
     * Initialize the local proxy.
69
     *
70
     * @param \AppserverIo\Psr\EnterpriseBeans\BeanContextInterface                       $beanManager           The bean manager instance
71
     * @param \AppserverIo\Psr\EnterpriseBeans\Description\SessionBeanDescriptorInterface $sessionBeanDescriptor The session bean descriptor
72
     * @param object                                                                      $sessionBean           The session been that has to be proxied
73
     * @param string                                                                      $sessionId             The actual session ID
74
     */
75 4
    public function __construct(
76
        BeanContextInterface $beanManager,
77
        SessionBeanDescriptorInterface $sessionBeanDescriptor,
78
        $sessionBean,
79
        $sessionId
80
    ) {
81 4
        $this->beanManager = $beanManager;
82 4
        $this->sessionBeanDescriptor = $sessionBeanDescriptor;
83 4
        $this->sessionBean = $sessionBean;
84 4
        $this->sessionId = $sessionId;
85 4
    }
86
87
    /**
88
     * Sets the session with the connection instance.
89
     *
90
     * @param \AppserverIo\RemoteMethodInvocation\SessionInterface $session The session instance to use
91
     *
92
     * @return \AppserverIo\RemoteMethodInvocation\RemoteObjectInterface The instance itself
93
     */
94 1
    public function __setSession(SessionInterface $session)
95
    {
96 1
        throw new \Exception(sprintf('Method %s must NOT be invoked on a local proxy', __METHOD__));
97
    }
98
99
    /**
100
     * Returns the session instance.
101
     *
102
     * @return \AppserverIo\RemoteMethodInvocation\SessionInterface The session instance
103
     */
104 1
    public function __getSession()
105
    {
106 1
        throw new \Exception(sprintf('Method %s must NOT be invoked on a local proxy', __METHOD__));
107
    }
108
109
    /**
110
     * The name of the original object.
111
     *
112
     * @return string The name of the original object
113
     */
114 1
    public function __getClassName()
115
    {
116 1
        return get_class($this->sessionBean);
117
    }
118
119
    /**
120
     * Invokes the local execution of the passed remote method.
121
     *
122
     * @param string $method The local method to call
123
     * @param array  $params The parameters for the method call
124
     *
125
     * @return mixed The result of the local method call
126
     */
127 1
    public function __call($method, $params)
128
    {
129
130
        // invoke the method on the session bean
131 1
        $response = call_user_func_array(array($this->sessionBean, $method), $params);
132
133
        // initialize the flag to mark the instance to be re-attached
134 1
        $attach = true;
135
136
        // query if we've stateful session bean
137 1
        if ($this->sessionBeanDescriptor instanceof StatefulSessionBeanDescriptorInterface) {
138
            // remove the SFSB instance if a remove method has been called
139
            if ($this->sessionBeanDescriptor->isRemoveMethod($methodName)) {
0 ignored issues
show
Bug introduced by
The variable $methodName does not exist. Did you mean $method?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
140
                $this->beanManager->removeStatefulSessionBean($sessionId, $this->sessionBeanDescriptor->getClassName());
0 ignored issues
show
Bug introduced by
The variable $sessionId does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The method removeStatefulSessionBean() does not seem to exist on object<AppserverIo\Psr\E...s\BeanContextInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
141
                $attach = false;
142
            }
143
        }
144
145
        // re-attach the bean instance if necessary
146 1
        if ($attach === true && $this->sessionId) {
147 1
            $this->beanManager->attach($this->sessionBean, $this->sessionId);
0 ignored issues
show
Bug introduced by
The method attach() does not seem to exist on object<AppserverIo\Psr\E...s\BeanContextInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148 1
        }
149
150
        // return the remote method call result
151 1
        return $response;
152
    }
153
}
154