szurubooru/src/Services/UserService.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2014-08-31 09:03:11 +02:00
<?php
namespace Szurubooru\Services;
class UserService
{
private $userDao;
2014-08-31 14:07:46 +02:00
private $config;
2014-08-31 09:03:11 +02:00
2014-08-31 14:07:46 +02:00
public function __construct(
\Szurubooru\Dao\UserDao $userDao,
\Szurubooru\Config $config)
2014-08-31 09:03:11 +02:00
{
$this->userDao = $userDao;
2014-08-31 14:07:46 +02:00
$this->config = $config;
2014-08-31 09:03:11 +02:00
}
public function getById($userId)
{
return $this->userDao->getById($userId);
}
public function getByName($userName)
{
return $this->userDao->getByName($userName);
}
public function save($user)
{
return $this->userDao->save($user);
}
2014-08-31 14:07:46 +02:00
public function validateUserName($userName)
{
if (!$userName)
throw new \DomainException('User name cannot be empty.');
$minUserNameLength = intval($this->config->users->minUserNameLength);
$maxUserNameLength = intval($this->config->users->maxserNameLength);
if (strlen($userName) < $minUserNameLength)
throw new \DomainException('User name must have at least ' . $minUserNameLength . ' character(s).');
if (strlen($userName) < $maxUserNameLength)
throw new \DomainException('User name must have at most ' . $minUserNameLength . ' character(s).');
}
public function getAnonymousUser()
{
$user = new \Szurubooru\Entities\User();
$user->name = 'Anonymous user';
$user->accessRank = \Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS;
}
2014-08-31 09:03:11 +02:00
}