Getting current entry element via plugin in Craft 3 without a hook Is it possible to query the current entry or category element via a Craft 3 plugin/module?

In the 2.6 era, I would use a hook. The Craft 3 iteration of a hook looks something like this:

$currentElement;

Craft::$app-&gt;getView()-&gt;hook('someHook', function(array &amp;$context) {
  if (isset($context['entry'])) {
    $currentElement = $context['entry'];
  } else if (isset($context['category'])) {
    $currentElement = $context['category'];
  }
});


With an accompanying Twig snippet in the template:

{% hook 'someHook' %}


I'm wondering if there is a cleaner practice to accomplish the same goal? I find relying on Twig snippet reduces the flexibility of my plugin. 

I've noticed the SEOMatic plugin is able to append entry specific data without any hooks in the template. I can't figure out how, but it gives me hope.
Check out Craft::$app-&gt;getElements()-&gt;getElementByUri() -- or you might also use Craft::$app-&gt;getUrlManager()-&gt;getMatchedElement() depending on your use case.


Your friendly neighborhood SEOmatic author :)