File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ class ClassType extends Nette\Object
65
65
*/
66
66
public static function from ($ from )
67
67
{
68
- $ from = $ from instanceof \ReflectionClass ? $ from : new \ ReflectionClass ( $ from );
68
+ $ from = new \ ReflectionClass ( $ from instanceof \ReflectionClass ? $ from-> getName () : $ from );
69
69
if (PHP_VERSION_ID >= 70000 && $ from ->isAnonymous ()) {
70
70
$ class = new static ('anonymous ' );
71
71
} else {
@@ -81,12 +81,12 @@ public static function from($from)
81
81
$ class ->implements = array_diff ($ class ->implements , $ from ->getParentClass ()->getInterfaceNames ());
82
82
}
83
83
foreach ($ from ->getProperties () as $ prop ) {
84
- if ($ prop ->getDeclaringClass () == $ from) { // intentionally ==
84
+ if ($ prop ->getDeclaringClass ()-> getName () === $ from-> getName ()) {
85
85
$ class ->properties [$ prop ->getName ()] = Property::from ($ prop );
86
86
}
87
87
}
88
88
foreach ($ from ->getMethods () as $ method ) {
89
- if ($ method ->getDeclaringClass () == $ from) { // intentionally ==
89
+ if ($ method ->getDeclaringClass ()-> getName () === $ from-> getName ()) {
90
90
$ class ->methods [$ method ->getName ()] = Method::from ($ method )->setNamespace ($ class ->namespace );
91
91
}
92
92
}
Original file line number Diff line number Diff line change @@ -57,4 +57,10 @@ class Class2 extends Class1 implements Interface2
57
57
{
58
58
}
59
59
60
- }
60
+ }
61
+
62
+ class Class3
63
+ {
64
+ public $prop1;
65
+
66
+ }
Original file line number Diff line number Diff line change 7
7
namespace Abc ;
8
8
9
9
use Nette \PhpGenerator \ClassType ;
10
- use ReflectionClass ;
11
10
use Tester \Assert ;
12
11
13
12
@@ -62,10 +61,17 @@ class Class2 extends Class1 implements Interface2
62
61
{}
63
62
}
64
63
64
+ class Class3
65
+ {
66
+ public $ prop1 ;
67
+ }
65
68
66
69
$ res [] = ClassType::from ('Abc\Interface1 ' );
67
70
$ res [] = ClassType::from ('Abc\Interface2 ' );
68
71
$ res [] = ClassType::from ('Abc\Class1 ' );
69
- $ res [] = ClassType::from (new ReflectionClass ('Abc\Class2 ' ));
72
+ $ res [] = ClassType::from (new \ReflectionClass ('Abc\Class2 ' ));
73
+ $ obj = new Class3 ;
74
+ $ obj ->prop2 = 1 ;
75
+ $ res [] = ClassType::from (new \ReflectionObject ($ obj ));
70
76
71
77
Assert::matchFile (__DIR__ . '/ClassType.from.expect ' , implode ("\n" , $ res ));
You can’t perform that action at this time.
0 commit comments