2
2
3
3
namespace Office365 \PHP \Client \Runtime ;
4
4
5
-
5
+ use Office365 \PHP \Client \Runtime \OData \JsonLightFormat ;
6
+ use Office365 \PHP \Client \Runtime \OData \ODataFormat ;
7
+ use Office365 \PHP \Client \Runtime \OData \ODataMetadataLevel ;
6
8
use Office365 \PHP \Client \Runtime \OData \ODataPathBuilder ;
7
9
8
10
/**
@@ -28,7 +30,7 @@ class ClientObject implements IEntityType
28
30
/**
29
31
* @var array
30
32
*/
31
- private $ properties = array () ;
33
+ private $ properties = null ;
32
34
33
35
34
36
/**
@@ -42,8 +44,6 @@ class ClientObject implements IEntityType
42
44
protected $ parentCollection ;
43
45
44
46
45
-
46
-
47
47
/**
48
48
* ClientObject constructor.
49
49
* @param ClientRuntimeContext $ctx
@@ -53,6 +53,7 @@ public function __construct(ClientRuntimeContext $ctx, ResourcePath $resourcePat
53
53
{
54
54
$ this ->context = $ ctx ;
55
55
$ this ->resourcePath = $ resourcePath ;
56
+ $ this ->properties = array ();
56
57
}
57
58
58
59
@@ -134,21 +135,22 @@ public function getTypeName()
134
135
}
135
136
136
137
/**
137
- * @param int $flag
138
+ *
139
+ * @param ODataFormat $format
138
140
* @return array
139
141
*/
140
- function getProperties ( $ flag = SCHEMA_ALL_PROPERTIES )
142
+ function toJson ( ODataFormat $ format )
141
143
{
142
- if ($ flag === SCHEMA_ALL_PROPERTIES )
143
- return $ this ->properties ;
144
- //exclude non serializable properties
145
- $ result = array ();
144
+ $ payload = array ();
146
145
foreach ( $ this ->properties as $ key =>$ value ) {
147
146
$ metadata = $ this ->propertiesMetadata [$ key ];
148
- if (($ metadata !== null && $ metadata ["Serializable " ] == true ))
149
- $ result [$ key ] = $ value ;
147
+ if (($ metadata !== null && $ metadata ["Serializable " ] === true ))
148
+ $ payload [$ key ] = $ value ;
150
149
}
151
- return $ result ;
150
+ if ($ format instanceof JsonLightFormat && $ format ->MetadataLevel == ODataMetadataLevel::Verbose) {
151
+ $ format ->ensureMetadataAnnotation ($ this , $ payload );
152
+ }
153
+ return $ payload ;
152
154
}
153
155
154
156
@@ -159,7 +161,7 @@ function getProperties($flag=SCHEMA_ALL_PROPERTIES)
159
161
*/
160
162
public function isPropertyAvailable ($ name )
161
163
{
162
- return isset ($ this ->properties [$ name ]) && ! isset ( $ this -> properties [ $ name ]-> __deferred ) ;
164
+ return isset ($ this ->properties [$ name ]);
163
165
}
164
166
165
167
@@ -168,9 +170,7 @@ public function isPropertyAvailable($name)
168
170
* @return bool
169
171
*/
170
172
public function getServerObjectIsNull (){
171
- if (!is_null ($ this ->resourcePath ))
172
- return $ this ->resourcePath ->ServerObjectIsNull ;
173
- return true ;
173
+ return is_null ($ this ->properties );
174
174
}
175
175
176
176
@@ -188,12 +188,11 @@ public function getProperty($name)
188
188
* A preferred way of setting the client object property
189
189
* @param string $name
190
190
* @param mixed $value
191
- * @param bool $persistChanges
191
+ * @param bool $serializable
192
192
*/
193
- public function setProperty ($ name , $ value , $ persistChanges = true )
193
+ public function setProperty ($ name , $ value , $ serializable = true )
194
194
{
195
- $ this ->propertiesMetadata [$ name ] = array ("Serializable " => $ persistChanges );
196
-
195
+ $ this ->propertiesMetadata [$ name ] = array ("Serializable " => $ serializable );
197
196
//save property
198
197
$ this ->{$ name } = $ value ;
199
198
0 commit comments