RegistrationFactory.php 2.34 KB
<?php

namespace FootyRoom\Services\Registration;

use FootyRoom\Config;
use FootyRoom\Services\Registration\FacebookRegistration;
use FootyRoom\Services\Registration\Registration;
use FootyRoom\Repositories\IUserRepository;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Events\Dispatcher;

class RegistrationFactory
{
    /**
     * @var \FootyRoom\Repositories\UserRepository
     */
    protected $userRepo;

    /**
     * @var \FootyRoom\Services\Registration\ActivationKeyMailer
     */
    protected $activationKeyMailer;

    /**
     * @var \Illuminate\Contracts\Auth\Guard
     */
    protected $auth;

    /**
     * @var \FootyRoom\Config
     */
    protected $config;

    /**
     * @var \Illuminate\Contracts\Events\Dispatcher;
     */
    protected $events;

    /**
     * Constructor.
     *
     * @param \FootyRoom\Repositories\IUserRepository              $userRepo
     * @param \FootyRoom\Services\Registration\ActivationKeyMailer $activationKeyMailer
     * @param \Illuminate\Contracts\Auth\Guard                     $auth
     * @param \FootyRoom\Config                                    $config
     */
    public function __construct(
        IUserRepository $userRepo,
        ActivationKeyMailer $activationKeyMailer,
        Guard $auth,
        Config $config,
        Dispatcher $events
    ) {
        $this->userRepo = $userRepo;
        $this->activationKeyMailer = $activationKeyMailer;
        $this->auth = $auth;
        $this->config = $config;
        $this->events = $events;
    }

    /**
     * Creates specific registration depending on submitted user data.
     *
     * @param  array $userData User data that will be passed on to registration.
     *
     * @return \FootyRoom\Services\Registration\Registration|\FootyRoom\Services\Registration\FacebookRegistration
     */
    public function make($userData)
    {
        if (isset($userData['fbtoken'])) {
            return new FacebookRegistration(
                $userData,
                $this->userRepo,
                $this->activationKeyMailer,
                $this->auth,
                $this->config,
                $this->events
            );
        } else {
            return new Registration(
                $userData,
                $this->userRepo,
                $this->activationKeyMailer,
                $this->events
            );
        }
    }
}