Created
January 27, 2015 16:57
-
-
Save jwalton512/008fd19e31351ae187c3 to your computer and use it in GitHub Desktop.
snake_case and camelCase in L5 Dispatcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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