Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using a service layer w/ the repository pattern - www.slashnode.com
<?php
/* UserRepository.php */
namespace Acme\Repositories;
class UserRepository extends AbstractRepository implements UserRepositoryInterface
{
// etc...
}
/* UserManager.php */
namespace Acme\Services;
use Acme\Repositories\UserRepository;
use Illuminate\Events\Dispatcher as EventDispatcher;
class UserManager
{
protected $userRepository;
protected $eventDispatcher;
public function __construct(UserRepository $userRepository, EventDispatcher $eventDispatcher)
{
$this->userRepository = $userRepository;
$this->eventDispatcher = $eventDispatcher;
}
public function register($data)
{
// create the user
$user = $this->userRepository->create($data);
if (!$user) return false;
// fire a domain event before returning the user
$this->eventDispatcher->fire('user.registered', $user);
return $user;
}
/** etc... **/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.