Skip to content

Commit a26cad7

Browse files
committed
keep base class in this repo
1 parent b97ff20 commit a26cad7

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

resources/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// submodule
1111
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
1212
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
13-
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/PosixGroup.php";
1413

1514
// load libs
1615
require_once __DIR__ . "/lib/UnityLDAP.php";
@@ -25,6 +24,7 @@
2524
require_once __DIR__ . "/lib/UnityWebhook.php";
2625
require_once __DIR__ . "/lib/UnityGithub.php";
2726
require_once __DIR__ . "/lib/utils.php";
27+
require_once __DIR__ . "/lib/PosixGroup.php";
2828
require_once __DIR__ . "/lib/exceptions/NoDieException.php";
2929
require_once __DIR__ . "/lib/exceptions/SSOException.php";
3030
require_once __DIR__ . "/lib/exceptions/ArrayKeyException.php";

resources/lib/PosixGroup.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib;
4+
5+
use PHPOpenLDAPer\LDAPEntry;
6+
use \Exception;
7+
8+
class PosixGroup
9+
{
10+
private LDAPEntry $entry;
11+
private string $gid;
12+
13+
public function __construct(LDAPEntry $entry, string $gid)
14+
{
15+
$this->gid = $gid;
16+
$this->entry = $entry;
17+
}
18+
19+
public function getDN(): string
20+
{
21+
return $this->entry->getDN();
22+
}
23+
24+
public function equals(PosixGroup $other_group): bool
25+
{
26+
if (!is_a($other_group, self::class)) {
27+
throw new Exception(
28+
"Unable to check equality because the parameter is not a " .
29+
self::class .
30+
" object",
31+
);
32+
}
33+
return $this->getDN() == $other_group->getDN();
34+
}
35+
36+
public function __toString(): string
37+
{
38+
return $this->gid;
39+
}
40+
41+
public function exists(): bool
42+
{
43+
return $this->entry->exists();
44+
}
45+
46+
public function getMemberUIDs(): array
47+
{
48+
$members = $this->entry->getAttribute("memberuid");
49+
sort($members);
50+
return $members;
51+
}
52+
53+
public function addMemberUID(string $uid): void
54+
{
55+
$this->entry->appendAttribute("memberuid", $uid);
56+
$this->entry->write();
57+
}
58+
59+
public function removeMemberUID(string $uid): void
60+
{
61+
$this->entry->removeAttributeEntryByValue("memberuid", $uid);
62+
$this->entry->write();
63+
}
64+
65+
public function mermberUIDExists(string $uid): bool
66+
{
67+
return in_array($uid, $this->getMemberUIDs());
68+
}
69+
}

resources/lib/UnityGroup.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use PHPOpenLDAPer\LDAPEntry;
55

66
use Exception;
7-
use PHPOpenLDAPer\PosixGroup;
87

98
/**
109
* Class that represents a single PI group in the Unity Cluster.

resources/lib/UnityOrg.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace UnityWebPortal\lib;
44
use PHPOpenLDAPer\LDAPEntry;
5-
use PHPOpenLDAPer\PosixGroup;
65

76
class UnityOrg extends PosixGroup
87
{

resources/lib/phpopenldaper

test/phpunit-bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// submodule
33
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
44
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
5-
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/PosixGroup.php";
65

76
require_once __DIR__ . "/../resources/lib/UnityLDAP.php";
87
require_once __DIR__ . "/../resources/lib/UnityUser.php";
@@ -16,6 +15,7 @@
1615
require_once __DIR__ . "/../resources/lib/UnityWebhook.php";
1716
require_once __DIR__ . "/../resources/lib/UnityGithub.php";
1817
require_once __DIR__ . "/../resources/lib/utils.php";
18+
require_once __DIR__ . "/../resources/lib/PosixGroup.php";
1919
require_once __DIR__ . "/../resources/lib/exceptions/NoDieException.php";
2020
require_once __DIR__ . "/../resources/lib/exceptions/SSOException.php";
2121
require_once __DIR__ . "/../resources/lib/exceptions/ArrayKeyException.php";

0 commit comments

Comments
 (0)