Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added new inject method which can take an arbitrary object and does m…

…ethod and property injection on it
  • Loading branch information...
commit 1dc5b1b904c240383b2975000ca034718da7de40 1 parent 5b18e22
@rodnaph rodnaph authored
View
7 lib/BoxUK/Inject/Injector.class.php
@@ -55,5 +55,12 @@ public function getScope( $name );
* @param object $object
*/
public function checkScope( $object );
+
+ /**
+ * Do method and property injection on the specified object
+ *
+ * @param object $object
+ */
+ public function inject( $object );
}
View
19 lib/BoxUK/Inject/Standard.class.php
@@ -152,14 +152,25 @@ public function checkScope( $object ) {
*/
public function getNewClass( $className ) {
- $oClass = $this->hasInjectableConstructor( $className )
+ $object = $this->hasInjectableConstructor( $className )
? $this->getInstance( $className )
: new $className();
- $this->injectMethods( $oClass );
- $this->injectProperties( $oClass );
+ $this->inject( $object );
- return $oClass;
+ return $object;
+
+ }
+
+ /**
+ * Do method and property injection on the specified object
+ *
+ * @param object $object
+ */
+ public function inject( $object ) {
+
+ $this->injectMethods( $object );
+ $this->injectProperties( $object );
}
View
14 tests/php/BoxUK/Inject/StandardTest.php
@@ -162,6 +162,20 @@ public function testPrivatePropertiesCanBeInjected() {
$this->assertInstanceOf( 'BoxUK\Inject\StandardInjectorTest_TestClass3', $class->getPrivateProperty() );
}
+ public function testInjectMethodDoesMethodInjection() {
+ $inject = $this->getInstance();
+ $class = new StandardInjectorTest_TestModel1();
+ $inject->inject( $class );
+ $this->assertInstanceOf( 'BoxUK\Inject\StandardInjectorTest_TestClass3', $class->object );
+ }
+
+ public function testInjectMethodDoesPropertyInjection() {
+ $inject = $this->getInstance();
+ $class = new StandardInjectorTest_TestClass7();
+ $inject->inject( $class );
+ $this->assertInstanceOf( 'BoxUK\Inject\StandardInjectorTest_TestClass3', $class->publicProperty );
+ }
+
}
class StandardInjectorTest_TestClass {}
Please sign in to comment.
Something went wrong with that request. Please try again.