-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Model API after Google's Firestore PHP library (free docs!)
BREAKING CHANGE: new API
- Loading branch information
1 parent
e10c2b7
commit b6b5b7f
Showing
8 changed files
with
115 additions
and
737 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,99 @@ | ||
<?php | ||
|
||
namespace Morrislaptop\Firestore; | ||
|
||
use Psr\Http\Message\UriInterface; | ||
use Kreait\Firebase\Exception\ApiException; | ||
use Kreait\Firebase\Database\Reference\Validator; | ||
use Kreait\Firebase\Exception\OutOfRangeException; | ||
use Kreait\Firebase\Exception\InvalidArgumentException; | ||
|
||
/** | ||
* A Reference represents a specific location in your database and can be used | ||
* for reading or writing data to that database location. | ||
* | ||
* @see https://firebase.google.com/docs/reference/js/firebase.database.Reference | ||
*/ | ||
class CollectionReference | ||
{ | ||
/** | ||
* @var UriInterface | ||
*/ | ||
private $uri; | ||
|
||
/** | ||
* @var ApiClient | ||
*/ | ||
private $apiClient; | ||
|
||
/** | ||
* @var Validator | ||
*/ | ||
private $validator; | ||
|
||
protected $valueMapper; | ||
|
||
/** | ||
* Creates a new Reference instance for the given URI which is accessed by | ||
* the given API client and validated by the Validator (obviously). | ||
* | ||
* @param UriInterface $uri | ||
* @param ApiClient $apiClient | ||
* @param Validator|null $validator | ||
* | ||
* @throws InvalidArgumentException if the reference URI is invalid | ||
*/ | ||
public function __construct(UriInterface $uri, ApiClient $apiClient, Validator $validator = null, ValueMapper $valueMapper = null) | ||
{ | ||
$this->validator = $validator ?? new Validator(); | ||
$this->validator->validateUri($uri); | ||
|
||
$this->valueMapper = $valueMapper ?? new ValueMapper(null, false); | ||
|
||
$this->uri = $uri; | ||
$this->apiClient = $apiClient; | ||
$this->valueMapper = $valueMapper; | ||
} | ||
|
||
/** | ||
* Gets a Reference for the location at the specified relative path. | ||
* | ||
* The relative path can either be a simple child name (for example, "ada") | ||
* or a deeper slash-separated path (for example, "ada/name/first"). | ||
* | ||
* @see https://firebase.google.com/docs/reference/js/firebase.database.Reference#child | ||
* | ||
* @param string $path | ||
* | ||
* @throws InvalidArgumentException if the path is invalid | ||
* | ||
* @return Reference | ||
*/ | ||
public function document(string $path): DocumentReference | ||
{ | ||
$childPath = sprintf('%s/%s', trim($this->uri->getPath(), '/'), trim($path, '/')); | ||
|
||
try { | ||
return new DocumentReference($this->uri->withPath($childPath), $this->apiClient, $this->validator, $this->valueMapper); | ||
} catch (\InvalidArgumentException $e) { | ||
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
} | ||
|
||
/** | ||
* Remove the data at this database location. | ||
* | ||
* Any data at child locations will also be deleted. | ||
* | ||
* @see https://firebase.google.com/docs/reference/js/firebase.database.Reference#remove | ||
* | ||
* @throws ApiException if the API reported an error | ||
* | ||
* @return Reference A new instance for the now empty Reference | ||
*/ | ||
public function remove(): self | ||
{ | ||
throw new \BadMethodCallException('Not implemented'); | ||
} | ||
|
||
} |
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
Oops, something went wrong.