WyriHaximus / reactphp-child-process-pool

MIT License
40 stars 9 forks source link

Exception Given class doesn't implement ChildInterface #39

Closed tarasMatskovich closed 5 years ago

tarasMatskovich commented 5 years ago

Hello, when i use Flexible::createFromClass i have got error. - Given class doesn't implement ChildInterface. Here my code:

Flexible::createFromClass(NewTestChild::class, $loop, $options) ->then(function (PoolInterface $pool) { try { $pool->rpc(MessagesFactory::rpc('return', [ 'i' => 1, 'time' => time() ]))->then(function (Payload $payload) use ($pool) { echo $payload['i'], PHP_EOL; echo $payload['time'], PHP_EOL; }); } catch (\Exception $e) { var_dump($e->getMessage()); } }); $loop->run();

My NewTestChild looks like:

`<?php

namespace childs\child;

use React\EventLoop\LoopInterface; use WyriHaximus\React\ChildProcess\Messenger\ChildInterface; use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload; use WyriHaximus\React\ChildProcess\Messenger\Messenger;

class NewTestChild implements ChildInterface {

/**
 * @param Messenger     $messenger
 * @param LoopInterface $loop
 */
protected function __construct(Messenger $messenger, LoopInterface $loop)
{
    $messenger->registerRpc('return', function (Payload $payload) {
        return \React\Promise\resolve($payload);
    });
    $this->ran = true;
}

/**
 * @param Messenger     $messenger
 * @param LoopInterface $loop
 */
public static function create(Messenger $messenger, LoopInterface $loop)
{
    new static($messenger, $loop);
}

}`

I debuged this code and exception throws here: on line 52 if (!\is_subclass_of($class, 'WyriHaximus\React\ChildProcess\Messenger\ChildInterface')) { throw new \Exception('Given class doesn\'t implement ChildInterface'); }

But my class NewTestChild implements ChildInterface Maybe someone knows what the proble may be?

WyriHaximus commented 5 years ago

Hey, glad to see you resolved this already. Mind posting what was the issue so others in the future know what to look for?

tarasMatskovich commented 5 years ago

It was my mistake i forgot to specify autoload for classes in composer.json