Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
webbingbrasil/core-module / Commands / Installers / Scripts / ConfigureUserProvider.php
Size: Mime:
<?php
/**
 * Created by PhpStorm.
 * User: danilo
 * Date: 18/12/15
 * Time: 10:58
 */
namespace Modules\Core\Commands\Installers\Scripts;

use Illuminate\Console\Command;
use Illuminate\Foundation\Application;
use Modules\Core\Commands\Installers\SetupScript;

class ConfigureUserProvider implements SetupScript
{
    /**
     * @var array
     */
    protected $drivers = [
        'Default'
    ];

    /**
     * @var
     */
    private $application;

    /**
     * @param Application $application
     */
    public function __construct(Application $application)
    {
        $this->application = $application;
    }

    /**
     * Fire the install script
     * @param  Command $command
     * @return mixed
     */
    public function fire(Command $command)
    {
        $command->blockMessage('User Module', 'Starting the User Module setup...', 'comment');

        $this->askForUserDriver($command);
    }

    public function askForUserDriver(Command $command)
    {
        if (count($this->drivers) == 1) {
            $selectedDriver = $this->drivers[0];
            $driverConfigured = $this->configure($selectedDriver, $command);
            return $driverConfigured;
        }

        do {
            $selectedDriver = $command->choice('Select a Driver for User Module', $this->drivers, 0);
            $driverConfigured = $this->configure($selectedDriver, $command);
            if (!$driverConfigured) {
                $command->error('Try another Driver for User Module');
            }
        } while (!$driverConfigured);

        return $driverConfigured;
    }

    /**
     * @param $driverName
     * @param $command
     * @return mixed
     */
    protected function configure($driverName, $command)
    {
        $driver = $this->factory($driverName);
        $driver->driver = $driverName;

        return $driver->fire($command);
    }

    /**
     * @param $driver
     * @return mixed
     */
    protected function factory($driver)
    {
        $class = __NAMESPACE__ . "\\UserProviders\\{$driver}Installer";

        return $this->application->make($class);
    }
}