| 568 |
568 |
$subject->expects( $this->once() ) |
| 569 |
569 |
->method( $methodName ); |
| 570 |
570 |
|
| 571 |
|
- $session = $this->createSession(); |
| 572 |
|
- $session->expects( $this->once() ) |
|
571 |
+ $context = $this->createContext(); |
|
572 |
+ $context->expects( $this->once() ) |
| 573 |
573 |
->method( 'getClass' ) |
| 574 |
574 |
->with( $this->equalTo( __CLASS__ ) ) |
| 575 |
575 |
->will( $this->returnValue( $subject ) ); |
| 576 |
576 |
|
| 577 |
|
- return new ReflectionClassProxy( $session, __CLASS__ ); |
|
577 |
+ return new ReflectionClassProxy( $context, __CLASS__ ); |
| 578 |
578 |
} |
| 579 |
579 |
} |
| 78 |
78 |
} |
| 79 |
79 |
|
| 80 |
80 |
/** |
| 81 |
|
- * testGetClassReturnsClassInstanceOfPreviousRegisteredClass |
|
81 |
+ * testGetClassReferenceReturnsClassInstanceOfPreviousRegisteredClass |
| 82 |
82 |
* |
| 83 |
83 |
* @return void |
| 84 |
84 |
* @covers \pdepend\reflection\ReflectionClassProxyContext |
| 85 |
85 |
* @group reflection |
| 86 |
86 |
* @group unittest |
| 87 |
87 |
*/ |
| 88 |
|
- public function testGetClassReturnsClassInstanceOfPreviousRegisteredClass() |
|
88 |
+ public function testGetClassReferenceReturnsClassInstanceOfPreviousRegisteredClass() |
| 89 |
89 |
{ |
| 90 |
90 |
$class = new \ReflectionClass( __CLASS__ ); |
| 91 |
91 |
|
| 92 |
92 |
$context = new ReflectionClassProxyContext( $this->createSession() ); |
| 93 |
|
- $context->registerClass( $class ); |
|
93 |
+ $context->addClass( $class ); |
| 94 |
94 |
|
| 95 |
95 |
$this->assertSame( $class, $context->getClassReference( __CLASS__ ) ); |
| 96 |
96 |
} |
|
97 |
+ |
|
98 |
+ /** |
|
99 |
+ * testGetClassReferenceHandlesClassNamesCaseInsensitive |
|
100 |
+ * |
|
101 |
+ * @return void |
|
102 |
+ * @covers \pdepend\reflection\ReflectionClassProxyContext |
|
103 |
+ * @group reflection |
|
104 |
+ * @group unittest |
|
105 |
+ */ |
|
106 |
+ public function testGetClassReferenceHandlesClassNamesCaseInsensitive() |
|
107 |
+ { |
|
108 |
+ $class = new \ReflectionClass( __CLASS__ ); |
|
109 |
+ |
|
110 |
+ $context = new ReflectionClassProxyContext( $this->createSession() ); |
|
111 |
+ $context->addClass( $class ); |
|
112 |
+ |
|
113 |
+ $this->assertSame( $class, $context->getClassReference( strtoupper( __CLASS__ ) ) ); |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ /** |
|
117 |
+ * testGetClassReturnsClassInstanceOfPreviousRegisteredClass |
|
118 |
+ * |
|
119 |
+ * @return void |
|
120 |
+ * @covers \pdepend\reflection\ReflectionClassProxyContext |
|
121 |
+ * @group reflection |
|
122 |
+ * @group unittest |
|
123 |
+ */ |
|
124 |
+ public function testGetClassReturnsClassInstanceOfPreviousRegisteredClass() |
|
125 |
+ { |
|
126 |
+ $class = new \ReflectionClass( __CLASS__ ); |
|
127 |
+ |
|
128 |
+ $context = new ReflectionClassProxyContext( $this->createSession() ); |
|
129 |
+ $context->addClass( $class ); |
|
130 |
+ |
|
131 |
+ $this->assertSame( $class, $context->getClass( __CLASS__ ) ); |
|
132 |
+ } |
|
133 |
+ |
|
134 |
+ /** |
|
135 |
+ * testGetClassReferenceHandlesClassNamesCaseInsensitive |
|
136 |
+ * |
|
137 |
+ * @return void |
|
138 |
+ * @covers \pdepend\reflection\ReflectionClassProxyContext |
|
139 |
+ * @group reflection |
|
140 |
+ * @group unittest |
|
141 |
+ */ |
|
142 |
+ public function testGetClassHandlesClassNamesCaseInsensitive() |
|
143 |
+ { |
|
144 |
+ $class = new \ReflectionClass( __CLASS__ ); |
|
145 |
+ |
|
146 |
+ $session = $this->createSession(); |
|
147 |
+ $session->expects( $this->never() ) |
|
148 |
+ ->method( 'getClass' ); |
|
149 |
+ |
|
150 |
+ $context = new ReflectionClassProxyContext( $session ); |
|
151 |
+ $context->addClass( $class ); |
|
152 |
+ |
|
153 |
+ $context->getClass( strtoupper( __CLASS__ ) ); |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ /** |
|
157 |
+ * testGetClassDelegatesToSessionWhenMatchingClassExists |
|
158 |
+ * |
|
159 |
+ * @return void |
|
160 |
+ * @covers \pdepend\reflection\ReflectionClassProxyContext |
|
161 |
+ * @group reflection |
|
162 |
+ * @group unittest |
|
163 |
+ */ |
|
164 |
+ public function testGetClassDelegatesToSessionWhenMatchingClassExists() |
|
165 |
+ { |
|
166 |
+ $session = $this->createSession(); |
|
167 |
+ $session->expects( $this->once() ) |
|
168 |
+ ->method( 'getClass' ) |
|
169 |
+ ->with( $this->equalTo( __CLASS__ ) ); |
|
170 |
+ |
|
171 |
+ $context = new ReflectionClassProxyContext( $session ); |
|
172 |
+ $context->getClass( __CLASS__ ); |
|
173 |
+ } |
| 97 |
174 |
} |
| 76 |
76 |
function getClassReference( $className ); |
| 77 |
77 |
|
| 78 |
78 |
/** |
|
79 |
+ * Returns a previous registered <b>\ReflectionClass</b> instance that |
|
80 |
+ * matches the given class name. Or throws a reflection exception when no |
|
81 |
+ * matching class exists. |
|
82 |
+ * |
|
83 |
+ * @param string $className Full qualified name of the request class. |
|
84 |
+ * |
|
85 |
+ * @return \ReflectionClass |
|
86 |
+ * @throws \ReflectionException When no matching class or interface for the |
|
87 |
+ * given name exists. |
|
88 |
+ */ |
|
89 |
+ function getClass( $className ); |
|
90 |
+ |
|
91 |
+ /** |
| 79 |
92 |
* This method can/should be called by the parser whenever the source of a |
| 80 |
93 |
* class or interface has been completed. |
| 81 |
94 |
* |
| 97 |
97 |
public static function createDefaultSession( SourceResolver $resolver ) |
| 98 |
98 |
{ |
| 99 |
99 |
$session = new ReflectionSession(); |
|
100 |
+ |
| 100 |
101 |
$session->addClassFactory( new factories\InternalReflectionClassFactory() ); |
| 101 |
|
- $session->addClassFactory( new factories\StaticReflectionClassFactory( new ReflectionClassProxyContext( $session ), $resolver ) ); |
|
102 |
+ $session->addClassFactory( |
|
103 |
+ new factories\StaticReflectionClassFactory( |
|
104 |
+ new ReflectionClassProxyContext( $session ), |
|
105 |
+ $resolver |
|
106 |
+ ) |
|
107 |
+ ); |
| 102 |
108 |
$session->addClassFactory( new factories\NullReflectionClassFactory() ); |
| 103 |
109 |
|
| 104 |
110 |
return $session; |
| 91 |
93 |
/** |
| 92 |
94 |
* Constructs a new class/interface proxy. |
| 93 |
95 |
* |
| 94 |
|
- * @param \pdepend\reflection\ReflectionSession $session The currently |
| 95 |
|
- * used reflection session instance that is used during the actual |
|
96 |
+ * @param \pdepend\reflection\interfaces\ParserContext $context The currently |
|
97 |
+ * used parser context instance that is used during the actual |
| 96 |
98 |
* parsing process. |
| 97 |
|
- * @param string $name Qualified name |
|
99 |
+ * @param string $name Qualified name |
| 98 |
100 |
* of the class/interface that is proxied by the current proxy object. |
| 99 |
101 |
*/ |
| 100 |
|
- public function __construct( ReflectionSession $session, $name ) |
|
102 |
+ public function __construct( ParserContext $context, $name ) |
| 101 |
103 |
{ |
| 102 |
|
- $this->_setSession( $session ); |
|
104 |
+ $this->_setContext( $context ); |
| 103 |
105 |
$this->_setName( $name ); |
| 104 |
106 |
} |
| 105 |
107 |
|
| 106 |
108 |
/** |
| 107 |
|
- * Sets the currently used reflection session instance. |
|
109 |
+ * Sets the currently used parser context instance. |
| 108 |
110 |
* |
| 109 |
|
- * @param \pdepend\reflection\ReflectionSession $session The currently |
| 110 |
|
- * used reflection session instance that is used during the actual |
|
111 |
+ * @param \pdepend\reflection\ReflectionSession $context The currently |
|
112 |
+ * used parser context instance that is used during the actual |
| 111 |
113 |
* parsing process. |
| 112 |
114 |
* |
| 113 |
115 |
* @return void |
| 114 |
116 |
*/ |
| 115 |
|
- private function _setSession( ReflectionSession $session ) |
|
117 |
+ private function _setContext( ParserContext $context ) |
| 116 |
118 |
{ |
| 117 |
|
- $this->_session = $session; |
|
119 |
+ $this->_context = $context; |
| 118 |
120 |
} |
| 119 |
121 |
|
| 120 |
122 |
/** |
| 99 |
103 |
*/ |
| 100 |
104 |
public function getClassReference( $className ) |
| 101 |
105 |
{ |
| 102 |
|
- if ( isset( $this->_classes[$className] ) ) |
|
106 |
+ if ( $this->_classCache->has( $className ) ) |
| 103 |
107 |
{ |
| 104 |
|
- return $this->_classes[$className]; |
|
108 |
+ return $this->_classCache->restore( $className ); |
| 105 |
109 |
} |
| 106 |
|
- return new ReflectionClassProxy( $this->_session, $className ); |
|
110 |
+ return new ReflectionClassProxy( $this, $className ); |
| 107 |
111 |
} |
| 108 |
112 |
|
| 109 |
113 |
/** |
|
114 |
+ * Returns a previous registered <b>\ReflectionClass</b> instance that |
|
115 |
+ * matches the given class name. Or throws a reflection exception when no |
|
116 |
+ * matching class exists. |
|
117 |
+ * |
|
118 |
+ * @param string $className Full qualified name of the request class. |
|
119 |
+ * |
|
120 |
+ * @return \ReflectionClass |
|
121 |
+ * @throws \ReflectionException When no matching class or interface for the |
|
122 |
+ * given name exists. |
|
123 |
+ */ |
|
124 |
+ public function getClass( $className ) |
|
125 |
+ { |
|
126 |
+ if ( $this->_classCache->has( $className ) ) |
|
127 |
+ { |
|
128 |
+ return $this->_classCache->restore( $className ); |
|
129 |
+ } |
|
130 |
+ return $this->_session->getClass( $className ); |
|
131 |
+ } |
|
132 |
+ |
|
133 |
+ /** |
| 110 |
134 |
* This method can/should be called by the parser whenever the source of a |
| 111 |
135 |
* class or interface has been completed. |
| 112 |
136 |
* |