PluginProbe
ActivityPub / 9.2.2
ActivityPub v9.2.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / transformer / class-json.php

class-json.php in ActivityPub 9.2.2, at includes/transformer/class-json.php

46 lines 899 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * String Transformer Class file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Transformer;
9
10 use Activitypub\Activity\Activity;
11 use Activitypub\Activity\Actor;
12 use Activitypub\Activity\Base_Object;
13
14 use function Activitypub\is_activity;
15 use function Activitypub\is_actor;
16
17 /**
18 * String Transformer Class file.
19 */
20 class Json extends Activity_Object {
21
22 /**
23 * JSON constructor.
24 *
25 * @param string|array $item The item that should be transformed.
26 */
27 public function __construct( $item ) {
28 if ( \is_string( $item ) ) {
29 $item = \json_decode( $item, true );
30 }
31
32 // Check if the item is an Activity or an Object.
33 if ( is_activity( $item ) ) {
34 $class = Activity::class;
35 } elseif ( is_actor( $item ) ) {
36 $class = Actor::class;
37 } else {
38 $class = Base_Object::class;
39 }
40
41 $object = $class::init_from_array( $item );
42
43 parent::__construct( $object );
44 }
45 }
46