diff --git a/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php b/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php index c409d4e8d0..160d4753fb 100644 --- a/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php +++ b/plugins/ActivityStreamsTwo/ActivityStreamsTwo.php @@ -24,7 +24,7 @@ class ActivityStreamsTwo extends Plugin /** * @param string $route - * @param array $accept + * @param array $accept_header * @param array $vars * @param null|TypeResponse $response * @@ -32,9 +32,9 @@ class ActivityStreamsTwo extends Plugin * * @return bool */ - public function onRouteInFormat(string $route, array $accept, array $vars, ?TypeResponse &$response = null): bool + public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?TypeResponse &$response = null): bool { - if (empty(array_intersect($this->accept, $accept))) { + if (empty(array_intersect($this->accept, $accept_header))) { return Event::next; } switch ($route) { @@ -53,15 +53,14 @@ class ActivityStreamsTwo extends Plugin * @param $r RouteLoader the router that was initialized. * * @return bool - * - * public function onAddRoute(RouteLoader $r): bool - * { - * $r->connect( - * 'note_view', - * '/note/{id<\d+>}', - * [NoteResponse::class, 'handle'], - * options: ['accept' => $this->accept] - * ); - * return Event::next; - * }*/ -} \ No newline at end of file + */ + public function onAddRoute(RouteLoader $r): bool + { + $r->connect('note_view_as2', + '/note/{id<\d+>}', + [NoteResponse::class, 'handle'], + options: ['accept' => $this->accept] + ); + return Event::next; + } +} diff --git a/plugins/ActivityStreamsTwo/Util/Type/ValidatorTools.php b/plugins/ActivityStreamsTwo/Util/Type/ValidatorTools.php index 17371fa392..8cc16a2800 100644 --- a/plugins/ActivityStreamsTwo/Util/Type/ValidatorTools.php +++ b/plugins/ActivityStreamsTwo/Util/Type/ValidatorTools.php @@ -147,31 +147,33 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getLinkOrNamedObjectValidator(): callable { - return static function ($item): bool { - if (is_string($item)) { - return Util::validateUrl($item); - } - - if (is_array($item)) { - $item = Util::arrayToType($item); - } - - if (is_object($item)) { - Util::hasProperties($item, ['type'], true); - - // Validate Link type - if ($item->type === 'Link') { - return Util::validateLink($item); + return + /** The implementation lambda */ + static function ($item): bool { + if (is_string($item)) { + return Util::validateUrl($item); } - // Validate Object type - Util::hasProperties($item, ['name'], true); + if (is_array($item)) { + $item = Util::arrayToType($item); + } - return is_string($item->name); - } + if (is_object($item)) { + Util::hasProperties($item, ['type'], true); - return false; - }; + // Validate Link type + if ($item->type === 'Link') { + return Util::validateLink($item); + } + + // Validate Object type + Util::hasProperties($item, ['name'], true); + + return is_string($item->name); + } + + return false; + }; } /** @@ -181,22 +183,24 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getLinkOrUrlObjectValidator(): callable { - return static function ($item): bool { - if (is_array($item)) { - $item = Util::arrayToType($item); - } + return + /** The implementation lambda */ + static function ($item): bool { + if (is_array($item)) { + $item = Util::arrayToType($item); + } - if (is_object($item) + if (is_object($item) && Util::isLinkOrUrlObject($item)) { - return true; - } + return true; + } - if (Util::validateUrl($item)) { - return true; - } + if (Util::validateUrl($item)) { + return true; + } - return false; - }; + return false; + }; } /** @@ -207,25 +211,27 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getAttachmentValidator(): callable { - return static function ($item): bool { - if (is_array($item)) { - $item = Util::arrayToType($item); - } + return + /** The implementation lambda */ + static function ($item): bool { + if (is_array($item)) { + $item = Util::arrayToType($item); + } - if (is_object($item)) { - if (Util::isLinkOrUrlObject($item)) { + if (is_object($item)) { + if (Util::isLinkOrUrlObject($item)) { + return true; + } + + return $item instanceof ObjectType; + } + + if (Util::validateUrl($item)) { return true; } - return $item instanceof ObjectType; - } - - if (Util::validateUrl($item)) { - return true; - } - - return false; - }; + return false; + }; } /** @@ -233,20 +239,22 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getQuestionAnswerValidator(): callable { - return static function ($item): bool { - if (is_array($item)) { - $item = Util::arrayToType($item); - } + return + /** The implementation lambda */ + static function ($item): bool { + if (is_array($item)) { + $item = Util::arrayToType($item); + } - if (!is_object($item)) { - return false; - } + if (!is_object($item)) { + return false; + } - Util::hasProperties($item, ['type', 'name'], true); + Util::hasProperties($item, ['type', 'name'], true); - return $item->type === 'Note' + return $item->type === 'Note' && is_scalar($item->name); - }; + }; } /** @@ -254,21 +262,23 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getCollectionItemsValidator(): callable { - return static function ($item): bool { - if (is_string($item)) { - return Util::validateUrl($item); - } + return + /** The implementation lambda */ + static function ($item): bool { + if (is_string($item)) { + return Util::validateUrl($item); + } - if (is_array($item)) { - $item = Util::arrayToType($item); - } + if (is_array($item)) { + $item = Util::arrayToType($item); + } - if (!is_object($item)) { - return false; - } + if (!is_object($item)) { + return false; + } - return Util::hasProperties($item, ['type'], true); - }; + return Util::hasProperties($item, ['type'], true); + }; } /** @@ -276,24 +286,26 @@ abstract class ValidatorTools implements ValidatorInterface */ protected function getCollectionActorsValidator(): callable { - return static function ($item): bool { - if (is_string($item)) { - return Util::validateUrl($item); - } + return + /** The implementation lambda */ + static function ($item): bool { + if (is_string($item)) { + return Util::validateUrl($item); + } - if (is_array($item)) { - $item = Util::arrayToType($item); - } + if (is_array($item)) { + $item = Util::arrayToType($item); + } - if (!is_object($item)) { - return false; - } - // id must be filled - if ($item instanceof AbstractActor) { - return !is_null($item->id); - } + if (!is_object($item)) { + return false; + } + // id must be filled + if ($item instanceof AbstractActor) { + return !is_null($item->id); + } - return Util::validateLink($item); - }; + return Util::validateLink($item); + }; } } diff --git a/src/Core/Controller.php b/src/Core/Controller.php index 4bd9281673..f5f08994a6 100644 --- a/src/Core/Controller.php +++ b/src/Core/Controller.php @@ -47,7 +47,7 @@ use Symfony\Component\HttpKernel\KernelEvents; class Controller extends AbstractController implements EventSubscriberInterface { - private array $vars = []; + private array $vars = []; protected ?Request $request = null; public function __construct(RequestStack $requestStack) @@ -117,9 +117,9 @@ class Controller extends AbstractController implements EventSubscriberInterface break; default: $potential_response = null; - if (Event::handle('RouteInFormat', [ - 'route' => $this->vars['controller'][1], - 'accept' => $accept, + if (Event::handle('ControllerResponseInFormat', [ + 'route' => $request->get('_route'), + 'accept_header' => $accept, 'vars' => $this->vars, 'response' => &$potential_response, ])) {