mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Run PHP-CS-FIXER to make sure
code is consisted with PSR-1 + PSR-2
This commit is contained in:
1 parent
c9d3448571
commit
35680bbae9
37 files changed
+928
-753
No files matched your search
+54
-31
@@ -45,38 +45,44 @@ class Database
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* Set Adapter
|
||||
* Set Adapter.
|
||||
*
|
||||
* @param Adapter $adapter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAdapter(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Namespace
|
||||
* Set Namespace.
|
||||
*
|
||||
* Set namespace to divide different scope of data sets
|
||||
*
|
||||
* @param $namespace
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->adapter->setNamespace($namespace);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Namespace
|
||||
* Get Namespace.
|
||||
*
|
||||
* Get namespace of current set scope
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getNamespace()
|
||||
@@ -85,9 +91,10 @@ class Database
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Namespace
|
||||
* Create Namespace.
|
||||
*
|
||||
* @param int $namespace
|
||||
*
|
||||
* @param int $namespace
|
||||
* @return bool
|
||||
*/
|
||||
public function createNamespace($namespace)
|
||||
@@ -96,9 +103,10 @@ class Database
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Namespace
|
||||
* Delete Namespace.
|
||||
*
|
||||
* @param int $namespace
|
||||
*
|
||||
* @param int $namespace
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteNamespace($namespace)
|
||||
@@ -108,6 +116,7 @@ class Database
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return Document[]|Document
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
@@ -127,15 +136,15 @@ class Database
|
||||
|
||||
$results = $this->adapter->getCollection($options);
|
||||
|
||||
foreach($results as &$node) {
|
||||
foreach ($results as &$node) {
|
||||
$node = new Document($node);
|
||||
}
|
||||
|
||||
if($options['first']) {
|
||||
if ($options['first']) {
|
||||
$results = reset($results);
|
||||
}
|
||||
|
||||
if($options['last']) {
|
||||
if ($options['last']) {
|
||||
$results = end($results);
|
||||
}
|
||||
|
||||
@@ -143,21 +152,21 @@ class Database
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
* @param bool $mock is mocked data allowed?
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function getDocument($id, $mock = true)
|
||||
{
|
||||
if(is_null($id)) {
|
||||
if (is_null($id)) {
|
||||
return new Document([]);
|
||||
}
|
||||
|
||||
$document = new Document((isset($this->mocks[$id]) && $mock) ? $this->mocks[$id] : $this->adapter->getDocument($id));
|
||||
$validator = new Authorization($document, 'read');
|
||||
$document = new Document((isset($this->mocks[$id]) && $mock) ? $this->mocks[$id] : $this->adapter->getDocument($id));
|
||||
$validator = new Authorization($document, 'read');
|
||||
|
||||
|
||||
if(!$validator->isValid($document->getPermissions())) { // Check if user has read access to this document
|
||||
if (!$validator->isValid($document->getPermissions())) { // Check if user has read access to this document
|
||||
return new Document([]);
|
||||
}
|
||||
|
||||
@@ -166,7 +175,9 @@ class Database
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Document|bool
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
* @throws StructureException
|
||||
*/
|
||||
@@ -174,15 +185,15 @@ class Database
|
||||
{
|
||||
$document = new Document($data);
|
||||
|
||||
$validator = new Authorization($document, 'write');
|
||||
$validator = new Authorization($document, 'write');
|
||||
|
||||
if(!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
if (!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
throw new AuthorizationException($validator->getDescription());
|
||||
}
|
||||
|
||||
$validator = new Structure($this);
|
||||
|
||||
if(!$validator->isValid($document)) {
|
||||
if (!$validator->isValid($document)) {
|
||||
throw new StructureException($validator->getDescription()); // var_dump($validator->getDescription()); return false;
|
||||
}
|
||||
|
||||
@@ -191,12 +202,14 @@ class Database
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Document|false
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateDocument(array $data)
|
||||
{
|
||||
if(!isset($data['$uid'])) {
|
||||
if (!isset($data['$uid'])) {
|
||||
throw new Exception('Must define $uid attribute');
|
||||
}
|
||||
|
||||
@@ -206,21 +219,21 @@ class Database
|
||||
$data['$uid'] = $document->getUid();
|
||||
$data['$collection'] = $document->getCollection();
|
||||
|
||||
$validator = new Authorization($document, 'write');
|
||||
$validator = new Authorization($document, 'write');
|
||||
|
||||
if(!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
if (!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
throw new AuthorizationException($validator->getDescription()); // var_dump($validator->getDescription()); return false;
|
||||
}
|
||||
|
||||
$new = new Document($data);
|
||||
|
||||
if(!$validator->isValid($new->getPermissions())) { // Check if user has write access to this document
|
||||
if (!$validator->isValid($new->getPermissions())) { // Check if user has write access to this document
|
||||
throw new AuthorizationException($validator->getDescription()); // var_dump($validator->getDescription()); return false;
|
||||
}
|
||||
|
||||
$validator = new Structure($this);
|
||||
|
||||
if(!$validator->isValid($new)) { // Make sure updated structure still apply collection rules (if any)
|
||||
if (!$validator->isValid($new)) { // Make sure updated structure still apply collection rules (if any)
|
||||
throw new StructureException($validator->getDescription()); // var_dump($validator->getDescription()); return false;
|
||||
}
|
||||
|
||||
@@ -229,16 +242,18 @@ class Database
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Document|false
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function deleteDocument($id)
|
||||
{
|
||||
$document = $this->getDocument($id);
|
||||
|
||||
$validator = new Authorization($document, 'write');
|
||||
$validator = new Authorization($document, 'write');
|
||||
|
||||
if(!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
if (!$validator->isValid($document->getPermissions())) { // Check if user has write access to this document
|
||||
throw new AuthorizationException($validator->getDescription());
|
||||
}
|
||||
|
||||
@@ -265,6 +280,7 @@ class Database
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount(array $options)
|
||||
@@ -281,31 +297,38 @@ class Database
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setMock($key, $value) {
|
||||
public function setMock($key, $value)
|
||||
{
|
||||
$this->mocks[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mocks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setMocks(array $mocks) {
|
||||
public function setMocks(array $mocks)
|
||||
{
|
||||
$this->mocks = $mocks;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMocks() {
|
||||
public function getMocks()
|
||||
{
|
||||
return $this->mocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Last Modified
|
||||
* Get Last Modified.
|
||||
*
|
||||
* Return unix timestamp of last time a node queried in current session has been changed
|
||||
*
|
||||
@@ -315,4 +338,4 @@ class Database
|
||||
{
|
||||
return $this->adapter->lastModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user