diff options
author | Joas Schilling <coding@schilljs.com> | 2017-03-17 12:23:04 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-07-20 17:34:16 +0300 |
commit | 564b2f974f25c7a382f6f0ce4cd8c274d914bc4d (patch) | |
tree | 3a7cf957a13618d7c8ee895812828529275f3818 /lib/private | |
parent | a78b13da82bafa281d273f9889f1611d17f3c0f5 (diff) |
Use DI
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Group/Manager.php | 24 | ||||
-rw-r--r-- | lib/private/Server.php | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 30fde1ad193..2481ebf1736 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -37,7 +37,10 @@ namespace OC\Group; use OC\Hooks\PublicEmitter; use OCP\GroupInterface; +use OCP\IGroup; use OCP\IGroupManager; +use OCP\ILogger; +use OCP\IUser; /** * Class Manager @@ -78,11 +81,16 @@ class Manager extends PublicEmitter implements IGroupManager { /** @var \OC\SubAdmin */ private $subAdmin = null; + /** @var ILogger */ + private $logger; + /** * @param \OC\User\Manager $userManager + * @param ILogger $logger */ - public function __construct(\OC\User\Manager $userManager) { + public function __construct(\OC\User\Manager $userManager, ILogger $logger) { $this->userManager = $userManager; + $this->logger = $logger; $cachedGroups = & $this->cachedGroups; $cachedUserGroups = & $this->cachedUserGroups; $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { @@ -176,7 +184,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @return bool */ public function groupExists($gid) { - return !is_null($this->get($gid)); + return $this->get($gid) instanceof IGroup; } /** @@ -184,7 +192,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @return \OC\Group\Group */ public function createGroup($gid) { - if ($gid === '' || is_null($gid)) { + if ($gid === '' || $gid === null) { return false; } else if ($group = $this->get($gid)) { return $group; @@ -214,10 +222,10 @@ class Manager extends PublicEmitter implements IGroupManager { $groupIds = $backend->getGroups($search, $limit, $offset); foreach ($groupIds as $groupId) { $aGroup = $this->get($groupId); - if (!is_null($aGroup)) { + if ($aGroup instanceof IGroup) { $groups[$groupId] = $aGroup; } else { - \OC::$server->getLogger()->debug('Group "' . $groupId . '" was returned by search but not found through direct access', array('app' => 'core')); + $this->logger->debug('Group "' . $groupId . '" was returned by search but not found through direct access', ['app' => 'core']); } } if (!is_null($limit) and $limit <= 0) { @@ -232,7 +240,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @return \OC\Group\Group[] */ public function getUserGroups($user) { - if (is_null($user)) { + if (!$user instanceof IUser) { return []; } return $this->getUserIdGroups($user->getUID()); @@ -252,10 +260,10 @@ class Manager extends PublicEmitter implements IGroupManager { if (is_array($groupIds)) { foreach ($groupIds as $groupId) { $aGroup = $this->get($groupId); - if (!is_null($aGroup)) { + if ($aGroup instanceof IGroup) { $groups[$groupId] = $aGroup; } else { - \OC::$server->getLogger()->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', array('app' => 'core')); + $this->logger->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', ['app' => 'core']); } } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 0e9b2605efb..ffb34d70eb9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -223,7 +223,7 @@ class Server extends ServerContainer implements IServerContainer { return new \OC\User\Manager($config); }); $this->registerService('GroupManager', function (Server $c) { - $groupManager = new \OC\Group\Manager($this->getUserManager()); + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); }); |