aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php')
-rw-r--r--vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php209
1 files changed, 108 insertions, 101 deletions
diff --git a/vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php b/vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php
index eb0df888b..350ecb145 100644
--- a/vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php
+++ b/vendor/sabre/dav/lib/DAVACL/PrincipalBackend/PDO.php
@@ -1,13 +1,15 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\DAVACL\PrincipalBackend;
use Sabre\DAV;
use Sabre\DAV\MkCol;
-use Sabre\HTTP\URLUtil;
+use Sabre\Uri;
/**
- * PDO principal backend
+ * PDO principal backend.
*
*
* This backend assumes all principals are in a single collection. The default collection
@@ -17,44 +19,43 @@ use Sabre\HTTP\URLUtil;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class PDO extends AbstractBackend implements CreatePrincipalSupport {
-
+class PDO extends AbstractBackend implements CreatePrincipalSupport
+{
/**
- * PDO table name for 'principals'
+ * PDO table name for 'principals'.
*
* @var string
*/
public $tableName = 'principals';
/**
- * PDO table name for 'group members'
+ * PDO table name for 'group members'.
*
* @var string
*/
public $groupMembersTableName = 'groupmembers';
/**
- * pdo
+ * pdo.
*
* @var PDO
*/
protected $pdo;
/**
- * A list of additional fields to support
+ * A list of additional fields to support.
*
* @var array
*/
protected $fieldMap = [
-
- /**
+ /*
* This property can be used to display the users' real name.
*/
'{DAV:}displayname' => [
'dbField' => 'displayname',
],
- /**
+ /*
* This is the users' primary email-address.
*/
'{http://sabredav.org/ns}email-address' => [
@@ -67,10 +68,9 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
*
* @param \PDO $pdo
*/
- function __construct(\PDO $pdo) {
-
+ public function __construct(\PDO $pdo)
+ {
$this->pdo = $pdo;
-
}
/**
@@ -87,10 +87,11 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
* you have an email address, use this property.
*
* @param string $prefixPath
+ *
* @return array
*/
- function getPrincipalsByPrefix($prefixPath) {
-
+ public function getPrincipalsByPrefix($prefixPath)
+ {
$fields = [
'uri',
];
@@ -98,15 +99,16 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
- $result = $this->pdo->query('SELECT ' . implode(',', $fields) . ' FROM ' . $this->tableName);
+ $result = $this->pdo->query('SELECT '.implode(',', $fields).' FROM '.$this->tableName);
$principals = [];
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
-
// Checking if the principal is in the prefix
- list($rowPrefix) = URLUtil::splitPath($row['uri']);
- if ($rowPrefix !== $prefixPath) continue;
+ list($rowPrefix) = Uri\split($row['uri']);
+ if ($rowPrefix !== $prefixPath) {
+ continue;
+ }
$principal = [
'uri' => $row['uri'],
@@ -117,11 +119,9 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
}
}
$principals[] = $principal;
-
}
return $principals;
-
}
/**
@@ -130,10 +130,11 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
* getPrincipalsByPrefix.
*
* @param string $path
+ *
* @return array
*/
- function getPrincipalByPath($path) {
-
+ public function getPrincipalByPath($path)
+ {
$fields = [
'id',
'uri',
@@ -142,14 +143,16 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
- $stmt = $this->pdo->prepare('SELECT ' . implode(',', $fields) . ' FROM ' . $this->tableName . ' WHERE uri = ?');
+ $stmt = $this->pdo->prepare('SELECT '.implode(',', $fields).' FROM '.$this->tableName.' WHERE uri = ?');
$stmt->execute([$path]);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
- if (!$row) return;
+ if (!$row) {
+ return;
+ }
$principal = [
- 'id' => $row['id'],
+ 'id' => $row['id'],
'uri' => $row['uri'],
];
foreach ($this->fieldMap as $key => $value) {
@@ -157,8 +160,8 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
$principal[$key] = $row[$value['dbField']];
}
}
- return $principal;
+ return $principal;
}
/**
@@ -173,41 +176,36 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
*
* Read the PropPatch documentation for more info and examples.
*
- * @param string $path
+ * @param string $path
* @param DAV\PropPatch $propPatch
*/
- function updatePrincipal($path, DAV\PropPatch $propPatch) {
-
- $propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
-
- $query = "UPDATE " . $this->tableName . " SET ";
+ public function updatePrincipal($path, DAV\PropPatch $propPatch)
+ {
+ $propPatch->handle(array_keys($this->fieldMap), function ($properties) use ($path) {
+ $query = 'UPDATE '.$this->tableName.' SET ';
$first = true;
$values = [];
foreach ($properties as $key => $value) {
-
$dbField = $this->fieldMap[$key]['dbField'];
if (!$first) {
$query .= ', ';
}
$first = false;
- $query .= $dbField . ' = :' . $dbField;
+ $query .= $dbField.' = :'.$dbField;
$values[$dbField] = $value;
-
}
- $query .= " WHERE uri = :uri";
+ $query .= ' WHERE uri = :uri';
$values['uri'] = $path;
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
return true;
-
});
-
}
/**
@@ -235,48 +233,52 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
* from working.
*
* @param string $prefixPath
- * @param array $searchProperties
+ * @param array $searchProperties
* @param string $test
+ *
* @return array
*/
- function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
- if (count($searchProperties) == 0) return []; //No criteria
+ public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
+ {
+ if (0 == count($searchProperties)) {
+ return [];
+ } //No criteria
- $query = 'SELECT uri FROM ' . $this->tableName . ' WHERE ';
+ $query = 'SELECT uri FROM '.$this->tableName.' WHERE ';
$values = [];
foreach ($searchProperties as $property => $value) {
switch ($property) {
- case '{DAV:}displayname' :
- $column = "displayname";
+ case '{DAV:}displayname':
+ $column = 'displayname';
break;
- case '{http://sabredav.org/ns}email-address' :
- $column = "email";
+ case '{http://sabredav.org/ns}email-address':
+ $column = 'email';
break;
- default :
+ default:
// Unsupported property
return [];
}
- if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " OR " : " AND ");
- $query .= 'lower(' . $column . ') LIKE lower(?)';
- $values[] = '%' . $value . '%';
-
+ if (count($values) > 0) {
+ $query .= (0 == strcmp($test, 'anyof') ? ' OR ' : ' AND ');
+ }
+ $query .= 'lower('.$column.') LIKE lower(?)';
+ $values[] = '%'.$value.'%';
}
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
$principals = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
-
// Checking if the principal is in the prefix
- list($rowPrefix) = URLUtil::splitPath($row['uri']);
- if ($rowPrefix !== $prefixPath) continue;
+ list($rowPrefix) = Uri\split($row['uri']);
+ if ($rowPrefix !== $prefixPath) {
+ continue;
+ }
$principals[] = $row['uri'];
-
}
return $principals;
-
}
/**
@@ -294,26 +296,32 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
*
* @param string $uri
* @param string $principalPrefix
+ *
* @return string
*/
- function findByUri($uri, $principalPrefix) {
+ public function findByUri($uri, $principalPrefix)
+ {
$value = null;
$scheme = null;
- list($scheme, $value) = explode(":", $uri, 2);
- if (empty($value)) return null;
+ list($scheme, $value) = explode(':', $uri, 2);
+ if (empty($value)) {
+ return null;
+ }
$uri = null;
- switch ($scheme){
- case "mailto":
- $query = 'SELECT uri FROM ' . $this->tableName . ' WHERE lower(email)=lower(?)';
+ switch ($scheme) {
+ case 'mailto':
+ $query = 'SELECT uri FROM '.$this->tableName.' WHERE lower(email)=lower(?)';
$stmt = $this->pdo->prepare($query);
$stmt->execute([$value]);
-
+
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
// Checking if the principal is in the prefix
- list($rowPrefix) = URLUtil::splitPath($row['uri']);
- if ($rowPrefix !== $principalPrefix) continue;
-
+ list($rowPrefix) = Uri\split($row['uri']);
+ if ($rowPrefix !== $principalPrefix) {
+ continue;
+ }
+
$uri = $row['uri'];
break; //Stop on first match
}
@@ -322,51 +330,56 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
//unsupported uri scheme
return null;
}
+
return $uri;
}
/**
- * Returns the list of members for a group-principal
+ * Returns the list of members for a group-principal.
*
* @param string $principal
+ *
* @return array
*/
- function getGroupMemberSet($principal) {
-
+ public function getGroupMemberSet($principal)
+ {
$principal = $this->getPrincipalByPath($principal);
- if (!$principal) throw new DAV\Exception('Principal not found');
-
- $stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM ' . $this->groupMembersTableName . ' AS groupmembers LEFT JOIN ' . $this->tableName . ' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
+ if (!$principal) {
+ throw new DAV\Exception('Principal not found');
+ }
+ $stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM '.$this->groupMembersTableName.' AS groupmembers LEFT JOIN '.$this->tableName.' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
$stmt->execute([$principal['id']]);
$result = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row['uri'];
}
- return $result;
+ return $result;
}
/**
- * Returns the list of groups a principal is a member of
+ * Returns the list of groups a principal is a member of.
*
* @param string $principal
+ *
* @return array
*/
- function getGroupMembership($principal) {
-
+ public function getGroupMembership($principal)
+ {
$principal = $this->getPrincipalByPath($principal);
- if (!$principal) throw new DAV\Exception('Principal not found');
-
- $stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM ' . $this->groupMembersTableName . ' AS groupmembers LEFT JOIN ' . $this->tableName . ' AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?');
+ if (!$principal) {
+ throw new DAV\Exception('Principal not found');
+ }
+ $stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM '.$this->groupMembersTableName.' AS groupmembers LEFT JOIN '.$this->tableName.' AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?');
$stmt->execute([$principal['id']]);
$result = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row['uri'];
}
- return $result;
+ return $result;
}
/**
@@ -375,13 +388,12 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
* The principals should be passed as a list of uri's.
*
* @param string $principal
- * @param array $members
- * @return void
+ * @param array $members
*/
- function setGroupMemberSet($principal, array $members) {
-
+ public function setGroupMemberSet($principal, array $members)
+ {
// Grabbing the list of principal id's.
- $stmt = $this->pdo->prepare('SELECT id, uri FROM ' . $this->tableName . ' WHERE uri IN (? ' . str_repeat(', ? ', count($members)) . ');');
+ $stmt = $this->pdo->prepare('SELECT id, uri FROM '.$this->tableName.' WHERE uri IN (? '.str_repeat(', ? ', count($members)).');');
$stmt->execute(array_merge([$principal], $members));
$memberIds = [];
@@ -394,19 +406,17 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
$memberIds[] = $row['id'];
}
}
- if (!$principalId) throw new DAV\Exception('Principal not found');
-
+ if (!$principalId) {
+ throw new DAV\Exception('Principal not found');
+ }
// Wiping out old members
- $stmt = $this->pdo->prepare('DELETE FROM ' . $this->groupMembersTableName . ' WHERE principal_id = ?;');
+ $stmt = $this->pdo->prepare('DELETE FROM '.$this->groupMembersTableName.' WHERE principal_id = ?;');
$stmt->execute([$principalId]);
foreach ($memberIds as $memberId) {
-
- $stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
+ $stmt = $this->pdo->prepare('INSERT INTO '.$this->groupMembersTableName.' (principal_id, member_id) VALUES (?, ?);');
$stmt->execute([$principalId, $memberId]);
-
}
-
}
/**
@@ -417,15 +427,12 @@ class PDO extends AbstractBackend implements CreatePrincipalSupport {
* of the principal.
*
* @param string $path
- * @param MkCol $mkCol
- * @return void
+ * @param MkCol $mkCol
*/
- function createPrincipal($path, MkCol $mkCol) {
-
- $stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
+ public function createPrincipal($path, MkCol $mkCol)
+ {
+ $stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (uri) VALUES (?)');
$stmt->execute([$path]);
$this->updatePrincipal($path, $mkCol);
-
}
-
}