Skip to content

Commit

Permalink
Bind wizard, cache to service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ycs77 committed Jun 15, 2019
1 parent 570f8dc commit 5f21fbe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ycs77\LaravelWizard;

use Illuminate\Foundation\Application;
use Illuminate\Support\Manager;
use Ycs77\LaravelWizard\Wizard;

Expand All @@ -28,7 +29,7 @@ class CacheManager extends Manager
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function __construct(Wizard $wizard, $app)
public function __construct(Wizard $wizard, Application $app)
{
$this->app = $app;
$this->wizard = $wizard;
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Controllers/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class WizardController extends Controller
*/
public function __construct(Wizard $wizard)
{
$this->wizard = $wizard->make($this->wizardName, $this->steps, $this->wizardOptions);
$this->wizard = $wizard;
$this->wizard->load($this->wizardName, $this->steps, $this->wizardOptions);
}

/**
Expand Down
15 changes: 7 additions & 8 deletions src/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public function __construct(Application $app)
}

/**
* Make a new wizard.
* Load the wizard dependencies.
*
* @param string $name
* @param mixed $steps
* @param array $options
* @return self
*/
public function make($name, $steps, $options = [])
public function load($name, $steps, $options = [])
{
$this->setCache();
$this->setStepRepo();
Expand All @@ -76,8 +76,6 @@ public function make($name, $steps, $options = [])
$this->stepRepo->make($steps);

$this->setOptions($options);

return $this;
}

/**
Expand Down Expand Up @@ -157,12 +155,12 @@ public function cache()
/**
* Set the wizard cache instance.
*
* @param \Ycs77\LaravelWizard\Contracts\CacheStore|null
* @param \Ycs77\LaravelWizard\Contracts\CacheStore|null $cache
* @return self
*/
public function setCache($cache = null)
{
$this->cache = $cache ?? new CacheManager($this, $this->app);
$this->cache = $cache ?? $this->app['wizard.cache'];
return $this;
}

Expand All @@ -179,7 +177,7 @@ public function stepRepo()
/**
* Set the step repository instance.
*
* @param \Ycs77\LaravelWizard\StepRepository|null
* @param \Ycs77\LaravelWizard\StepRepository|null $stepRepo
* @return self
*/
public function setStepRepo($stepRepo = null)
Expand All @@ -201,9 +199,10 @@ public function options()
/**
* Get the wizard option.
*
* @param string $key
* @return mixed
*/
public function option($key)
public function option(string $key)
{
return $this->options[$key] ?? null;
}
Expand Down
17 changes: 16 additions & 1 deletion src/WizardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@
class WizardServiceProvider extends ServiceProvider
{
/**
* Register services.
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('wizard', function ($app) {
return new Wizard($app);
});

$this->app->singleton('wizard.cache', function ($app) {
return new CacheManager($app['wizard'], $app);
});

$this->app->singleton('wizard.cache.store', function ($app) {
return $app['wizard.cache']->driver();
});

$this->app->alias('wizard', Wizard::class);
$this->app->alias('wizard.cache', CacheManager::class);

$this->mergeConfigFrom(__DIR__ . '/../config/wizard.php', 'wizard');
}

Expand Down

0 comments on commit 5f21fbe

Please sign in to comment.