Skip to content

Commit

Permalink
Add Laravel specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Feb 5, 2019
1 parent 9302478 commit d9d85ae
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
}
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^7.5",
"orchestra/testbench": "~3.0"
},
"extra": {
"laravel": {
"providers": [
"Mpociot\\ChuckNorrisJokes\\ChuckNorrisJokesServiceProvider"
],
"aliases": {
"ChuckNorris": "Mpociot\\ChuckNorrisJokes\\Facades\\ChuckNorris"
}
}
}
}
26 changes: 26 additions & 0 deletions src/ChuckNorrisJokesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Mpociot\ChuckNorrisJokes;

use Illuminate\Support\ServiceProvider;
use Mpociot\ChuckNorrisJokes\Console\ChuckNorrisJoke;
use Mpociot\ChuckNorrisJokes\JokeFactory;

class ChuckNorrisJokesServiceProvider extends ServiceProvider
{
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
ChuckNorrisJoke::class
]);
}
}

public function register()
{
$this->app->bind('chuck-norris', function() {
return new JokeFactory();
});
}
}
18 changes: 18 additions & 0 deletions src/Console/ChuckNorrisJoke.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Mpociot\ChuckNorrisJokes\Console;

use Illuminate\Console\Command;
use Mpociot\ChuckNorrisJokes\Facades\ChuckNorris;

class ChuckNorrisJoke extends Command
{
protected $signature = 'chuck-norris';

protected $description = 'Output a funny Chuck Norris joke.';

public function handle()
{
$this->info(ChuckNorris::getRandomJoke());
}
}
13 changes: 13 additions & 0 deletions src/Facades/ChuckNorris.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Mpociot\ChuckNorrisJokes\Facades;

use Illuminate\Support\Facades\Facade;

class ChuckNorris extends Facade
{
protected static function getFacadeAccessor()
{
return 'chuck-norris';
}
}

0 comments on commit d9d85ae

Please sign in to comment.