Skip to content
New issue

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

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

Already on GitHub? # to your account

Can't seem to get this working w/ the latest version of Silex. #22

Open
exts opened this issue Nov 21, 2016 · 4 comments
Open

Can't seem to get this working w/ the latest version of Silex. #22

exts opened this issue Nov 21, 2016 · 4 comments

Comments

@exts
Copy link

exts commented Nov 21, 2016

Created a generic test class and tried to let PHP-DI do it's thing and it just errors out:

example code:

$container = include __DIR__ . '/container.php';

$app = new DI\Bridge\Silex\Application($container);
$app['debug'] = true;

$app->get('/', [\TMI\Test::class, 'example']);

return $app;

Error:

InvalidArgumentException in ControllerResolver.php line 54:
Controller for URI "/" is not callable: Cannot call example on TMI\Test because it is not a class nor a valid container entry
in ControllerResolver.php line 54
at ControllerResolver->getController(object(Request)) in HttpKernel.php line 136
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 496
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index.php line 4
@mnapoli
Copy link
Member

mnapoli commented Nov 22, 2016

Hi, is TMI\Test a class?

@exts
Copy link
Author

exts commented Nov 22, 2016

Yeah, was just a simple class eg.:

namespace TMI;

class Test
{
    public function example()
    {
        return 'example';
    }
}

Was testing autowiring, just doesn't seem to work.

@mnapoli
Copy link
Member

mnapoli commented Nov 22, 2016

Was is configured with Composer? Can you try by embedding it in the whole script just to be sure? Like this:

$container = include __DIR__ . '/container.php';

$app = new DI\Bridge\Silex\Application($container);
$app['debug'] = true;

class Test
{
    public function example()
    {
        return 'example';
    }
}

$app->get('/', [Test::class, 'example']);

return $app;

It should work so really I'm shooting in the dark trying to understand ;)

@exts
Copy link
Author

exts commented Nov 22, 2016

Yeah it was setup w/ PSR-4 autoload setting. When I get a chance today I'll double check my setup and post it.

Just to confirm I'm using silex 2.0.x + php-di silex bridge 2.0.0-beta1

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants