I know this looks like a dupllicate of Inject Silex $app in my custom class and others, but I couldn't get it working from their solutions.
I define my service like this:
$app['user.repo'] = function () {
return new MyApp\Repository\User();
};
My class looks like this:
<?php
namespace MyApp\Repository;
use Silex\Application;
class User {
public function findAll(Application $app) {
$users = $app['db']->fetchAll('SELECT * FROM user');
return $users;
}
}
And I use the service like this:
$users = $app['user.repo']->findAll($app);
How can I do this same thing without putting $app
in all my methods?