Skip to content

Instantly share code, notes, and snippets.

@jwalton512
Created January 27, 2015 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwalton512/008fd19e31351ae187c3 to your computer and use it in GitHub Desktop.
Save jwalton512/008fd19e31351ae187c3 to your computer and use it in GitHub Desktop.
snake_case and camelCase in L5 Dispatcher
<?php namespace App\Providers;
use App\Bus\Dispatcher;
use Illuminate\Support\ServiceProvider;
class BusServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* @param Dispatcher $dispatcher
*/
public function boot(Dispatcher $dispatcher)
{
$dispatcher->mapUsing(function($command)
{
return Dispatcher::simpleMapping(
$command, 'App\Commands', 'App\Handlers\Commands'
);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('App\Bus\Dispatcher', function($app)
{
return new Dispatcher($app, function() use ($app)
{
return $app['Illuminate\Contracts\Queue\Queue'];
});
});
$this->app->alias(
'App\Bus\Dispatcher', 'Illuminate\Contracts\Bus\Dispatcher'
);
$this->app->alias(
'App\Bus\Dispatcher', 'Illuminate\Contracts\Bus\QueueingDispatcher'
);
}
}
<?php namespace App\Bus;
use ArrayAccess;
use Illuminate\Bus\Dispatcher as BaseDispatcher;
use ReflectionParameter;
class Dispatcher extends BaseDispatcher {
protected function extractValueFromSource(ArrayAccess $source, ReflectionParameter $parameter)
{
$name = $parameter->name;
return array_get($source, $parameter->name, array_get($source, snake_case($name)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment