I have a project that uses the Sentinel bundle for Laravel.
A while ago, I asked a question about extending a model provided in the bundle. The answer I accepted worked, but it required editing the bundle's code in the vendor folder.
Since then, I've run a composer update
command and the change I applied was overwritten (no surprise there).
I know a bit more about how laravel works now so I was able to trace back the end point where the bundle's services are referenced by my app. In my config/app.php
file I have the service provider reference:
'Sentinel\SentinelServiceProvider',
The SentinelServiceProvider
service has a register
method that registers the RepoServiceProvider
which is the class I need to override.
My plan is to create two new files: ExtendedSentinelServiceProvider.php
and ExtendedRepoServiceProvider.php
.
In the ExtendedRepoServiceProvider.php
file, I could replace the class being used for the User Repository binding with my custom User class:
// Bind the User Repository
$app->bind('Sentinel\Repo\User\UserInterface', function($app)
{
return new ExtendedSentryUser( // This is my custom model that I want the ExtendedRepoServiceProvider to use
$app['sentry']
);
});
In the ExtendedSentinelServiceProvider.php
file, I would replace the existing RepoServiceProvider
class reference with my newly modified ExtendedRepoServiceProvider
class:
public function register()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Sentry', 'Cartalyst\Sentry\Facades\Laravel\Sentry');
$repoProvider = new ExtendedRepoServiceProvider($this->app); // This would be my new ExtendedRepoServiceProvider class
$repoProvider->register();
$formServiceProvider = new FormServiceProvider($this->app);
$formServiceProvider->register();
}
And then I would replace the service provider reference in my config/app.php
file with the new ExtendedSentinelServiceProvider
class:
'providers' => array(
...
'Sentinel\ExtendedSentinelServiceProvider',
...
),
My question is, would this make sense as a way of being able to store my modifications in my app directory rather than modifying the vendor code? Is this going to be a problem when it comes to name spacing? Is there a better way of doing this??
Any help would be greatly appreciated.