-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2126750
commit c2128d6
Showing
5 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreait\Firebase\Database; | ||
|
||
use JsonSerializable; | ||
|
||
class RuleSet implements JsonSerializable | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $rules; | ||
|
||
private function __construct(array $rules) | ||
{ | ||
if (!array_key_exists('rules', $rules)) { | ||
$rules = ['rules' => $rules]; | ||
} | ||
|
||
$this->rules = $rules; | ||
} | ||
|
||
/** | ||
* The default rules require Authentication. They allow full read and write access | ||
* to authenticated users of your app. They are useful if you want data open to | ||
* all users of your app but don't want it open to the world. | ||
* | ||
* @see https://firebase.google.com/docs/database/security/quickstart#sample-rules | ||
* | ||
* @return self | ||
*/ | ||
public static function default(): self | ||
{ | ||
return new self([ | ||
'rules' => [ | ||
'.read' => 'auth != null', | ||
'.write' => 'auth != null', | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* During development, you can use the public rules in place of the default rules to set | ||
* your files publicly readable and writable. This can be useful for prototyping, | ||
* as you can get started without setting up Authentication. | ||
* | ||
* This level of access means anyone can read or write to your database. You should | ||
* configure more secure rules before launching your app. | ||
* | ||
* @see https://firebase.google.com/docs/database/security/quickstart#sample-rules | ||
* | ||
* @return self | ||
*/ | ||
public static function public(): self | ||
{ | ||
return new self([ | ||
'rules' => [ | ||
'.read' => true, | ||
'.write' => true, | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* Private rules disable read and write access to your database by users. With these rules, | ||
* you can only access the database through the Firebase console and an Admin SDK. | ||
* | ||
* @see https://firebase.google.com/docs/database/security/quickstart#sample-rules | ||
* | ||
* @return self | ||
*/ | ||
public static function private(): self | ||
{ | ||
return new self([ | ||
'rules' => [ | ||
'.read' => false, | ||
'.write' => false, | ||
], | ||
]); | ||
} | ||
|
||
public static function fromArray(array $rules): self | ||
{ | ||
return new self($rules); | ||
} | ||
|
||
public function getRules(): array | ||
{ | ||
return $this->rules; | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return $this->rules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters