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

Error Using the Facade #2

Closed
vinkla opened this issue Feb 14, 2015 · 47 comments
Closed

Error Using the Facade #2

vinkla opened this issue Feb 14, 2015 · 47 comments
Assignees
Labels

Comments

@vinkla
Copy link
Contributor

vinkla commented Feb 14, 2015

The error below has been reported by @alexandredes and @mottihoresh. This error occurs when using the Facade. As I've learned, using dependency injection it works.

call_user_func_array() expects parameter 1 to be a valid callback

I've tried this in my local setup, using Homestead, with both the Facade and dependency injection without any problems. The events gets registered in the console at http://pusher.com. Example code below.

<?php namespace App\Http\Controllers;

use Vinkla\Pusher\Facades\Pusher;

class PushController extends Controller {

    public function index()
    {
        dd(Pusher::trigger('my-channel', 'my-event', ['message' => 'A']));
    }

}

unnamed

If someone else experience this, please report it here. If you have a solution, please share it!

@hmaurer
Copy link

hmaurer commented Feb 20, 2015

Same problem here. No fix idea as of yet :/

@simderoemer
Copy link

Same issue.

@actuallymab
Copy link

It occurs on my project too.

@yhalabi
Copy link

yhalabi commented Feb 28, 2015

Same here

@vinkla
Copy link
Contributor Author

vinkla commented Mar 2, 2015

I think this is because how the Pusher library is built. The Pusher package currently autoloads everything in their lib directory. The Pusher class and Pusher facade might collide and overwrite each other.

I've have discussed a PSR-4 update to the library in pusher/pusher-http-php#25. They are about to release a new package that is more up to date with PHP. Maybe we can hold out until then and release Laravel Pusher 2.0 when it is ready.

@Kryptonit3-zz
Copy link

Any idea on when this will be fixed? Or what we can temporarily edit to make it work?

@mottihoresh
Copy link

I was having more issues it today. I am not too familiar with the way ServiceProviders work in Laravel, so i just created a very basic service injector

https://gist.github.com/mottihoresh/394e12ea802b41b5ef65

the only thing you need to do is to add pusher-php-server to your composer file.

@vinkla
Copy link
Contributor Author

vinkla commented Mar 9, 2015

@mottihoresh @Kryptonit3 Have you tried using it as in our dependency injection example instead of using the facade?

@vinkla
Copy link
Contributor Author

vinkla commented Mar 15, 2015

For reference how to use it with dependency injection you can check out this RealTimeStatusHandler class by @StyleCI.

@TimothyLoyer
Copy link

I tried using the facade and then DI and get the same error (maybe since the PusherManager also ends up using the facade?).

[2015-03-17 20:21:43] local.ERROR: exception 'ErrorException' with message 'call_user_func_array() expects parameter 1 to be a valid callback, class 'Vinkla\Pusher\Facades\Pusher' does not have a method 'trigger'' in /home/vagrant/Code/l5-acme-api/vendor/graham-campbell/manager/src/AbstractManager.php:234

@vinkla
Copy link
Contributor Author

vinkla commented Mar 17, 2015

@TimothyLoyer I think its because how the Pusher library is built, it currently return the Pusher class globally. They are about to release a namespaced version soon.

@GrahamCampbell do you have any idea?

@TimothyLoyer
Copy link

Maybe having your facade named "Pusher" is causing an issue- might be why the L4 package used "pusherer".

@vinkla
Copy link
Contributor Author

vinkla commented Mar 17, 2015

@TimothyLoyer Yes, I think so too. Maybe we can hold out on this until they release the new version https://github.com/pusher/pusher-http-php/tree/new-lib

@TimothyLoyer
Copy link

I just renamed the facade (and continued using DI, but I imagine that the facade also works now with its new name). The area of issue is in PusherFactory, where you have use Pusher; it is pulling in the your facade rather than the Pusher library.

@vinkla
Copy link
Contributor Author

vinkla commented Mar 17, 2015

The facades in Laravel are globally registered so its quite hard to work around. Did it work renaming it?

@TimothyLoyer
Copy link

Yes, and you are right about the Pusher php library- all those classes are in the global namespace (ugly!) so that forces you into working around its namespaced classes. You'll want to double check all those classnames to be sure you don't have any overlap. Though thinking about it, facades are really all that would have an issue.

vinkla added a commit that referenced this issue Mar 17, 2015
@vinkla
Copy link
Contributor Author

vinkla commented Mar 17, 2015

@TimothyLoyer Yeah, you can still use the PusherManager without any problems. I've added this issue to the README to clear this up for future users.

@TimothyLoyer
Copy link

I tweeted Pusher about namespacing their composer package and got a pretty quick response from @leggetter. "We’ve got a new-lib branch which is an completely re-written lib. v3.0 will be the last non-namespaces major release." More info here: http://j.mp/1MKUTt3 - Looks like they are moving to a 4.0 branch.

@leggetter
Copy link

👍

@jadjoubran
Copy link

I can't seem to get it work with dependency injection as well.
Can you show an example how it works?
Should I remove the facade entry from config/app.php for it to work?

@vinkla
Copy link
Contributor Author

vinkla commented Apr 5, 2015

@jadjoubran please see #2 (comment). Yes, you could try to remove the facade from config/app.php.

@CoeusCC
Copy link

CoeusCC commented Jun 4, 2015

For the time being, I've just renamed my facade to LaravelPusher to great success. In my controller I call use LaravelPusher; then I can use

public function pusher()
{
    $messages = '{"name":"Joe","message":"Hello world!"}';

    LaravelPusher::trigger('test_channel', 'my_event', ['message' => $messages]);
}

in my function. My alias then has to become 'LaravelPusher' => 'Vinkla\Pusher\Facades\Pusher',.

As mentioned above, it's because the class and facade clash for the namespace.

@kunalthool
Copy link

Thanks CoeusCC that works like a charm.

@Kryptonit3-zz
Copy link

here is a simple package - https://github.com/Kryptonit3/Pusher

@zoranlorkovic
Copy link

+1

@GrahamCampbell
Copy link
Contributor

Just have use Vinkla\Pusher\Facades\Pusher as PusherFacade;. Then you're done...

@stephanedemotte
Copy link

any update ?

@GrahamCampbell
Copy link
Contributor

any update ?

There is no bug in this library.

@GrahamCampbell
Copy link
Contributor

Go pester the actual pusher library to sort it out.

@sheyooo
Copy link

sheyooo commented Feb 3, 2016

solution is here not to put the facade class in app.php and use the dependency injection with the service provider alone in the app.php file.....

@rulatir
Copy link

rulatir commented Feb 3, 2016

sheyooo - exact incantation please?

@sheyooo
Copy link

sheyooo commented Feb 3, 2016

@rulatir https://github.com/vinkla/pusher#installation
follow the instructions this way

Installation

Require this package, with Composer, in the root directory of your project.

composer require vinkla/pusher

Add the service provider to config/app.php in the providers array.

Vinkla\Pusher\PusherServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'Pusher' => Vinkla\Pusher\Facades\Pusher::class //IGNORE THIS

If you prefer to use dependency injection over facades like me, then you can inject the manager:

use Vinkla\Pusher\PusherManager;

class Foo
{
    protected $pusher;

    public function __construct(PusherManager $pusher)
    {
        $this->pusher = $pusher;
    }

    public function bar()
    {
        $this->pusher->trigger('my-channel', 'my-event', ['message' => $message]);
    }
}

@rulatir
Copy link

rulatir commented Feb 5, 2016

Thanks sheyooo, I just ended up writing a super simple facade by hand, one that directly wraps the Pusher class. I removed vinkla/pusher altogether.

@vinkla
Copy link
Contributor Author

vinkla commented Feb 5, 2016

@rulatir You can actually use the Pusher class with this package. That is why we bind the Pusher class to the connection. Please see PusherServiceProvider.php.

@Malki
Copy link

Malki commented Feb 8, 2016

Using @GrahamCampbell suggestion solved the issue

@mhdafiq
Copy link

mhdafiq commented Sep 26, 2016

I still don't know how this work. Tried all of the method.
Someone please guide me.

@vinkla
Copy link
Contributor Author

vinkla commented Sep 26, 2016

@mhdafiq try #2 (comment)

@mhdafiq
Copy link

mhdafiq commented Sep 26, 2016

@vinkla i already tried that but still cannot trigger from server.

when i
dd($this->pusher->trigger('test_channel', 'my_event', ['message' => 'hello world']));
the value return false.

@vinkla
Copy link
Contributor Author

vinkla commented Jun 20, 2017

@jameshfisher @luismfonseca are there any updates on the new version of the pusher/pusher-php-server package? When will Pusher release the new namespaced version?

@luismfonseca
Copy link

@GrahamCampbell @vinkla so I understand correctly, I can just add namespace Pusher; to the library, would this solve this problem?

Future users of the library would always need to do use Pusher\Pusher; right?

@vinkla
Copy link
Contributor Author

vinkla commented Jun 22, 2017

Yes, but you need to release it as a new major version. It is a breaking change. Shouldn't be a problem though since integers are cheap.

@vinkla
Copy link
Contributor Author

vinkla commented Jun 22, 2017

@luismfonseca let me know if there is anything I can help with. Please let me know before you push the new version. Then I can help you test it out.

@luismfonseca
Copy link

Btw, I've released the new php version!

@vinkla
Copy link
Contributor Author

vinkla commented Jul 10, 2017

@luismfonseca great! I'll release a new version of this package with the Laravel 5.5 support release.

@normanaranez
Copy link

ca we use facade now?

@vinkla
Copy link
Contributor Author

vinkla commented Jul 12, 2017

I'll release a new version soon.

@vinkla
Copy link
Contributor Author

vinkla commented Jul 13, 2017

Fixed in 25a88e4.

@vinkla vinkla closed this as completed Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests