|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright 2016 Johannes M. Schmitt <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace JMS\Serializer\Handler; |
|
20
|
|
|
|
|
21
|
|
|
use JMS\Serializer\Context; |
|
22
|
|
|
use JMS\Serializer\GraphNavigator; |
|
23
|
|
|
use JMS\Serializer\Metadata\StaticPropertyMetadata; |
|
24
|
|
|
use JMS\Serializer\VisitorInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @author Asmir Mustafic <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class StdClassHandler implements SubscribingHandlerInterface |
|
30
|
|
|
{ |
|
31
|
362 |
|
public static function getSubscribingMethods() |
|
32
|
|
|
{ |
|
33
|
362 |
|
$methods = array(); |
|
34
|
362 |
|
$formats = array('json', 'xml', 'yml'); |
|
35
|
|
|
|
|
36
|
362 |
|
foreach ($formats as $format) { |
|
37
|
362 |
|
$methods[] = array( |
|
38
|
362 |
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
|
39
|
362 |
|
'type' => 'stdClass', |
|
40
|
362 |
|
'format' => $format, |
|
41
|
362 |
|
'method' => 'serializeStdClass', |
|
42
|
|
|
); |
|
43
|
362 |
|
} |
|
44
|
|
|
|
|
45
|
362 |
|
return $methods; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
6 |
|
public function serializeStdClass(VisitorInterface $visitor, \stdClass $stdClass, array $type, Context $context) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
6 |
|
$classMetadata = $context->getMetadataFactory()->getMetadataForClass('stdClass'); |
|
51
|
6 |
|
$visitor->startVisitingObject($classMetadata, $stdClass, array('name' => 'stdClass'), $context); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
6 |
|
foreach ((array)$stdClass as $name => $value) { |
|
54
|
4 |
|
$metadata = new StaticPropertyMetadata('stdClass', $name, $value); |
|
55
|
4 |
|
$visitor->visitProperty($metadata, $value, $context); |
|
56
|
6 |
|
} |
|
57
|
|
|
|
|
58
|
6 |
|
return $visitor->endVisitingObject($classMetadata, $stdClass, array('name' => 'stdClass'), $context); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.