-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed AsyncTransformer to work with collections instead of records.
Added collection types for async collections.
- Loading branch information
Showing
13 changed files
with
247 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use Amp\Iterator; | ||
|
||
class AsyncFilteredRecords extends AsyncRecordCollection | ||
{ | ||
private $filter; | ||
|
||
public function __construct(Iterator $records, AsyncRecordCollection $previousCollection, callable $filter) | ||
{ | ||
parent::__construct($records, $previousCollection); | ||
|
||
$this->filter = $filter; | ||
} | ||
|
||
public function getFilter(): callable | ||
{ | ||
return $this->filter; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use Amp\Iterator; | ||
use ScriptFUSION\Porter\Specification\AsyncImportSpecification; | ||
|
||
class AsyncPorterRecords extends AsyncRecordCollection | ||
{ | ||
private $specification; | ||
|
||
public function __construct(Iterator $records, AsyncImportSpecification $specification) | ||
{ | ||
parent::__construct($records, $records); | ||
|
||
$this->specification = $specification; | ||
} | ||
|
||
public function getSpecification(): AsyncImportSpecification | ||
{ | ||
return $this->specification; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use Amp\Iterator; | ||
use ScriptFUSION\Porter\Provider\Resource\AsyncResource; | ||
|
||
class AsyncProviderRecords extends AsyncRecordCollection | ||
{ | ||
private $resource; | ||
|
||
public function __construct(Iterator $records, AsyncResource $resource) | ||
{ | ||
parent::__construct($records); | ||
|
||
$this->resource = $resource; | ||
} | ||
|
||
public function getResource(): AsyncResource | ||
{ | ||
return $this->resource; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use Amp\Iterator; | ||
use Amp\Promise; | ||
|
||
abstract class AsyncRecordCollection implements Iterator | ||
{ | ||
private $records; | ||
|
||
private $previousCollection; | ||
|
||
public function __construct(Iterator $records, self $previousCollection = null) | ||
{ | ||
$this->records = $records; | ||
$this->previousCollection = $previousCollection; | ||
} | ||
|
||
public function advance(): Promise | ||
{ | ||
return $this->records->advance(); | ||
} | ||
|
||
public function getCurrent(): array | ||
{ | ||
return $this->records->getCurrent(); | ||
} | ||
|
||
public function getPreviousCollection(): ?AsyncRecordCollection | ||
{ | ||
return $this->previousCollection; | ||
} | ||
|
||
public function findFirstCollection(): ?AsyncRecordCollection | ||
{ | ||
do { | ||
$previous = $nextPrevious ?? $this->getPreviousCollection(); | ||
} while ($previous && $nextPrevious = $previous->getPreviousCollection()); | ||
|
||
return $previous ?: $this; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use ScriptFUSION\Porter\Specification\AsyncImportSpecification; | ||
|
||
class CountableAsyncPorterRecords extends AsyncPorterRecords implements \Countable | ||
{ | ||
use CountableRecordsTrait; | ||
|
||
public function __construct(AsyncRecordCollection $records, int $count, AsyncImportSpecification $specification) | ||
{ | ||
parent::__construct($records, $specification); | ||
|
||
$this->setCount($count); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Porter\Collection; | ||
|
||
use Amp\Iterator; | ||
use ScriptFUSION\Porter\Provider\Resource\AsyncResource; | ||
|
||
class CountableAsyncProviderRecords extends AsyncProviderRecords implements \Countable | ||
{ | ||
use CountableRecordsTrait; | ||
|
||
public function __construct(Iterator $records, int $count, AsyncResource $resource) | ||
{ | ||
parent::__construct($records, $resource); | ||
|
||
$this->setCount($count); | ||
} | ||
} |
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
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.