MongoCommandCursor.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. */
  15. use Alcaeus\MongoDbAdapter\AbstractCursor;
  16. use Alcaeus\MongoDbAdapter\TypeConverter;
  17. class MongoCommandCursor extends AbstractCursor implements MongoCursorInterface
  18. {
  19. /**
  20. * @var array
  21. */
  22. private $command;
  23. /**
  24. * MongoCommandCursor constructor.
  25. * @param MongoClient $connection
  26. * @param string $ns
  27. * @param array $command
  28. */
  29. public function __construct(MongoClient $connection, $ns, array $command = [])
  30. {
  31. parent::__construct($connection, $ns);
  32. $this->command = $command;
  33. }
  34. /**
  35. * @param MongoClient $connection
  36. * @param string $hash
  37. * @param array $document
  38. * @return MongoCommandCursor
  39. */
  40. public static function createFromDocument(MongoClient $connection, $hash, array $document)
  41. {
  42. throw new \Exception('Not implemented');
  43. }
  44. /**
  45. * @return \MongoDB\Driver\Cursor
  46. */
  47. protected function ensureCursor()
  48. {
  49. if ($this->cursor === null) {
  50. $this->cursor = $this->db->command(TypeConverter::convertLegacyArrayToObject($this->command), $this->getOptions());
  51. }
  52. return $this->cursor;
  53. }
  54. /**
  55. * @return array
  56. */
  57. protected function getCursorInfo()
  58. {
  59. return [
  60. 'ns' => $this->ns,
  61. 'limit' => 0,
  62. 'batchSize' => $this->batchSize,
  63. 'skip' => 0,
  64. 'flags' => 0,
  65. 'query' => $this->command,
  66. 'fields' => null,
  67. ];
  68. }
  69. }