Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions: Drop support for Compat extender #1558

Closed
franzliedke opened this issue Aug 23, 2018 · 9 comments · Fixed by #2705
Closed

Extensions: Drop support for Compat extender #1558

franzliedke opened this issue Aug 23, 2018 · 9 comments · Fixed by #2705

Comments

@franzliedke
Copy link
Contributor

Since introducing extenders in beta.8, we've still supported returning closures with auto-injection from extension's bootstrapper files (extend.php, previously bootstrap.php).

This fallback, implemented through the Compat extender, which has been marked as deprecated as long as it exists, can be removed.

@franzliedke franzliedke added this to the 0.1 milestone Aug 23, 2018
@lukbukkit
Copy link
Contributor

Is it okay to work on this issue or do want to wait until the beta8 is released?

@franzliedke
Copy link
Contributor Author

@lukbukkit You are more than welcome to send a PR for this. However, we won't merge this until we have built extender classes for all known extension use-cases.

@franzliedke
Copy link
Contributor Author

While we are at this...

We have discussed whether we want to keep this extender under another name a couple times, but haven't reached a definite conclusion. IMO, we should not make this stuff too easy.

Reaching into the container and using all the objects therein should not be considered public API. So, new idea: Instead of allowing closures with type hinted parameters or a Compat extender, can we just force people with custom use cases to implement their own extenders? Internally, we would only deal with extenders (yay for simplicity) and externally, this would be a non-trivial, but reasonably easy barrier to entry, which is just what we want to prevent this from being overused while still allowing full flexibility.

@luceos @tobscure Thoughts?

@luceos
Copy link
Member

luceos commented Oct 3, 2018

How would "implementing their own extenders" work if you can't use anything to hook into the App.. Or I'm missing something. Simple extensions don't need much, but looking at some of the more complex ones, eg Bazaar or console, need to be able to hook into the full app.

@franzliedke
Copy link
Contributor Author

@luceos They would have to create a class that implements the ExtenderInterface: that's just one method, which immediately gives them access to the container. That is basically just as powerful (strictly speaking, even more powerful) than having the container do auto-injection on the current closures.

@luceos
Copy link
Member

luceos commented Oct 3, 2018

Right, somehow I assumed that everything has to be done using the extend.php file. But then again we're using autoloading 😴

@tobyzerner
Copy link
Contributor

tobyzerner commented Oct 3, 2018

That sounds good to me. I assume it would support anonymous classes? so you can do:

return [
    new Extend\Whatever,

    new class implements Extend\ExtenderInterface {
        public function extend(Container $container, Extension $extension = null)
        {
            // do your thang...
        }
    }
]

@luceos
Copy link
Member

luceos commented Mar 22, 2019

A few suggestions based on re-using extenders in extensions:

<?php

namespace Flagrow\Byobu\Extend;

use Flarum\Extend\ExtenderInterface;
use Flarum\Extension\Extension;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;

class Listen implements ExtenderInterface
{
    protected $listeners = [];

    public function extend(Container $container, Extension $extension = null)
    {
        /** @var Dispatcher $events */
        $events = $container->make(Dispatcher::class);

        foreach ($this->listeners as $listener) {
            $events->listen($listener[0], $listener[1]);
        }
    }

    public function on(string $event, $callable)
    {
        $this->listeners[] = [$event, $callable];

        return $this;
    }
}

@franzliedke
Copy link
Contributor Author

👍 for the list, except for the event listener one. That makes it feel like we "support" listening to any of the events that we use as implementation detail. I consider them 100% private, I want to have the freedom to change them without any SemVer constraints.

Since building your own extender is so easy, as Toby demonstrated, I think that's a legitimate approach.

(It means we need to make progress on covering all current use cases with official extenders, though. Ahem.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants