1+ --TEST--
2+ #41 constructor should accept object
3+ --FILE--
4+ <?php
5+ // @@protoc_insertion_point(namespace:.TestMessage)
6+
7+ /**
8+ * Generated by the protocol buffer compiler. DO NOT EDIT!
9+ * source: x.proto
10+ *
11+ * -*- magic methods -*-
12+ *
13+ * @method array getUsers()
14+ * @method void appendUsers(TestUser $value)
15+ */
16+ class TestMessage extends ProtocolBuffersMessage
17+ {
18+ // @@protoc_insertion_point(traits:.TestMessage)
19+
20+ /**
21+ * @var array $users
22+ * @tag 1
23+ * @label optional
24+ * @type ProtocolBuffers::TYPE_MESSAGE
25+ * @see TestUser
26+ **/
27+ protected $ users ;
28+
29+
30+ // @@protoc_insertion_point(properties_scope:.TestMessage)
31+
32+ // @@protoc_insertion_point(class_scope:.TestMessage)
33+
34+ /**
35+ * get descriptor for protocol buffers
36+ *
37+ * @return ProtocolBuffersDescriptor
38+ */
39+ public static function getDescriptor ()
40+ {
41+ static $ descriptor ;
42+
43+ if (!isset ($ descriptor )) {
44+ $ desc = new ProtocolBuffersDescriptorBuilder ();
45+ $ desc ->addField (1 , new ProtocolBuffersFieldDescriptor (array (
46+ "type " => ProtocolBuffers::TYPE_MESSAGE ,
47+ "name " => "users " ,
48+ "required " => false ,
49+ "optional " => false ,
50+ "repeated " => true ,
51+ "packable " => false ,
52+ "default " => null ,
53+ "message " => 'TestUser ' ,
54+ )));
55+ // @@protoc_insertion_point(builder_scope:.TestMessage)
56+
57+ $ descriptor = $ desc ->build ();
58+ }
59+ return $ descriptor ;
60+ }
61+
62+ }
63+
64+ // @@protoc_insertion_point(namespace:.TestUser)
65+
66+ /**
67+ * Generated by the protocol buffer compiler. DO NOT EDIT!
68+ * source: x.proto
69+ *
70+ * -*- magic methods -*-
71+ *
72+ * @method string getId()
73+ * @method void setId(string $value)
74+ */
75+ class TestUser extends ProtocolBuffersMessage
76+ {
77+ // @@protoc_insertion_point(traits:.TestUser)
78+
79+ /**
80+ * @var string $id
81+ * @tag 1
82+ * @label required
83+ * @type ProtocolBuffers::TYPE_INT64
84+ **/
85+ protected $ id ;
86+
87+
88+ // @@protoc_insertion_point(properties_scope:.TestUser)
89+
90+ // @@protoc_insertion_point(class_scope:.TestUser)
91+
92+ /**
93+ * get descriptor for protocol buffers
94+ *
95+ * @return ProtocolBuffersDescriptor
96+ */
97+ public static function getDescriptor ()
98+ {
99+ static $ descriptor ;
100+
101+ if (!isset ($ descriptor )) {
102+ $ desc = new ProtocolBuffersDescriptorBuilder ();
103+ $ desc ->addField (1 , new ProtocolBuffersFieldDescriptor (array (
104+ "type " => ProtocolBuffers::TYPE_INT64 ,
105+ "name " => "id " ,
106+ "required " => true ,
107+ "optional " => false ,
108+ "repeated " => false ,
109+ "packable " => false ,
110+ "default " => null ,
111+ )));
112+ // @@protoc_insertion_point(builder_scope:.TestUser)
113+
114+ $ descriptor = $ desc ->build ();
115+ }
116+ return $ descriptor ;
117+ }
118+
119+ }
120+
121+ $ bar = new TestMessage (array ('users ' => array (
122+ new TestUser (array ('id ' => 1 )),
123+ new TestUser (array ('id ' => 2 )),
124+ new TestUser (array ('id ' => 3 ))
125+ )));
126+
127+ foreach ($ bar ->getUsers () as $ user ) {
128+ echo $ user ->getId () . PHP_EOL ;
129+ }
130+
131+ $ bar = new TestMessage (array ('users ' => array (
132+ array ('id ' => 1 ),
133+ array ('id ' => 2 ),
134+ array ('id ' => 3 ),
135+ )));
136+
137+ foreach ($ bar ->getUsers () as $ user ) {
138+ echo $ user ->getId () . PHP_EOL ;
139+ }
140+
141+ $ u1 = new TestUser (array ('id ' => 1 ));
142+ $ u2 = new TestUser (array ('id ' => 2 ));
143+ $ u3 = new TestUser (array ('id ' => 3 ));
144+ $ users = array ($ u1 , $ u2 , $ u3 );
145+
146+ $ bar = new TestMessage (array ('users ' => $ users ));
147+ foreach ($ bar ->getUsers () as $ user ) {
148+ echo $ user ->getId () . PHP_EOL ;
149+ }
150+
151+ --EXPECT --
152+ 1
153+ 2
154+ 3
155+ 1
156+ 2
157+ 3
158+ 1
159+ 2
160+ 3
0 commit comments