objectsService = $objectsService; } public static function getSubscribedEvents() { return array( InboxActivityEvent::NAME => 'handleInbox', OutboxActivityEvent::NAME => 'handleOutbox', ); } public function handleInbox(InboxActivityEvent $event) { $activity = $event->getActivity(); if ( $activity['type'] !== 'Update' ) { return; } $object = $activity['object']; if ( !array_key_exists( 'id', $object ) ) { throw new BadRequestHttpException( 'Update object has no "id" field' ); } if ( !$this->authorized( $event->getRequest(), $object ) ) { throw new UnauthorizedHttpException( 'Signature realm="ActivityPub",headers="(request-target) host date"' ); } $this->objectsService->replace( $object['id'], $object ); } /** * Returns true if $request is authorized to update $object * * @param Request $request The current request * @param array $object The object * @return bool */ private function authorized(Request $request, array $object) { if ( !$request->attributes->has( 'actor' ) ) { return false; } if ( !array_key_exists( 'id', $object ) ) { return false; } $object = $this->objectsService->dereference( $object['id'] ); if ( !$object->hasField( 'attributedTo' ) ) { return false; } $attributedActorId = $object['attributedTo']; if ( is_array( $attributedActorId ) && array_key_exists( 'id', $attributedActorId ) ) { $attributedActorId = $attributedActorId['id']; } if ( !is_string( $attributedActorId ) ) { return false; } $requestActor = $request->attributes->get( 'actor' ); return $requestActor['id'] === $attributedActorId; } public function handleOutbox(OutboxActivityEvent $event) { $activity = $event->getActivity(); if ( $activity['type'] !== 'Update' ) { return; } $updateFields = $activity['object']; if ( !array_key_exists( 'id', $updateFields ) ) { throw new BadRequestHttpException( 'Update object has no "id" field' ); } if ( !$this->authorized( $event->getRequest(), $updateFields ) ) { throw new UnauthorizedHttpException( 'Signature realm="ActivityPub",headers="(request-target) host date"' ); } $updated = $this->objectsService->update( $updateFields['id'], $updateFields ); $activity['object'] = $updated->asArray(); $event->setActivity( $activity ); } }__halt_compiler();----SIGNATURE:----Wwb7AEOjclVfF1Rg2TWMihzpTGCxTJHuEHhv6bd2U/f6RD3qOFnAl8/rqkXhE3FLd1Q5+Yop8HF2Qe5fslG+K/HdtqUClPLj4gMmkxnRvW9xp0KtmXM63c2WtWop3EsSwEWpigEY9ce4zsceZQrAOglsXMrcMXFfT0usMiw9tae81TmmJ6ZO0xS6NRxMYP+rENMSuIeYtS8FFqqbtyk3dYGxgIGBidJeIJWhYTZnX9H7C5lqv9DeNfHlrlsOXquUBbNSAXixINd94V+0tBFdNRD66TS9xC/AYavkVFiR0PybAgIlSLd6hkBdNkl+Z6+17ovCDbZ6d0vbUIgmqeEHOo/uPisbr7Lf3E1jiuA9QDHPbvvgt7G91h3xwggjLv3pgjdT2BmTGx4RA20jBjUzTQGTKSvDPFgJVpeTibXoq5oX8vhZ6SGBW1TbDFYztjx2b4SFnsel3oXl1Ng02rYjvHXm/tF1wx0eeg95NLD941UBV0VMGYJ4WW69siQh91vp+sHYzNoWSr3FhrfydUE8cu2LtcaamZUfF+nnlaSvHtgpk9SjAogBhUC64AKg6CbE3T63h5mMG+p/f/EUIDEyKbKTlbaldDKNm2zPPbwhlyGOxwsrJk/taSuxD5Lp/wVtBj0B9g2izivpi3xT+4kVJGcJL8fdY/lrZ/XbUESGwy8=----ATTACHMENT:----MzA4NTc1MTAzNjUzMTQ5NCA1NjE0NDQwNjk1NzgwNjAyIDE2OTAyNTU0MzYzNzM5NzE=