Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-378

Create interfaces for driver classes

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.0-alpha2
    • Component/s: None
    • None

      Manager, Server, and Cursor would benefit from having interfaces, both for unit testing in PHPLIB and other wrappers being able to decorate these classes. A common Executor interface (with the three Server execute methods) could be extended by the Manager and Server interfaces.

      Additional classes that users cannot construct (e.g. WriteResult) might also benefit.

      Proposal:

      <?php
      
      namespace MongoDB\Driver;
      
      /* Final classes without interfaces:
       *
       * - BulkWrite (builder object)
       * - Command (value object)
       * - Query (value object)
       * - CursorId (value object)
       * - ReadConcern (value object)
       * - ReadPreference (value object)
       * - WriteConcern (value object)
       */
      
      interface CursorInterface extends \Traversable
      {
          function getId(): CursorId;
          function getServer(): ServerInterface;
          function isDead(): boolean;
          function setTypeMap(array $typeMap);
          function toArray(): array;
      }
      
      interface WriteConcernErrorInterface
      {
          function getCode(): integer;
          function getInfo(); // array or object
          function getMessage(): string;
      }
      
      interface WriteErrorInterface
      {
          function getCode(): integer;
          function getIndex(): integer;
          function getInfo(); // array or object
          function getMessage(): string;
      }
      
      interface WriteResultInterface
      {
          function getDeletedCount(): ?integer;
          function getInsertedCount(): ?integer;
          function getMatchedCount(): ?integer;
          function getModifiedCount(): ?integer;
          function getServer(): ServerInterface;
          function getUpsertedCount(): ?integer;
          function getUpsertedIds(): array; // map of index => ID
          function getWriteConcernError(): WriteConcernErrorInterface;
          function getWriteErrors(): array; // WriteErrorInterface[];
          function isAcknowledged(): boolean;
      }
      
      interface ExecutorInterface
      {
          function executeBulkWrite(string $ns, BulkWrite $bulkWrite, ?WriteConcern $wc = null): WriteResultInterface;
          function executeCommand(string $db, Command $cmd, ?ReadPreference $rp = null): CursorInterface;
          function executeQuery(string $ns, Query $query, ?ReadPreference $rp = null): CursorInterface;
      }
      
      interface ServerInterface extends ExecutorInterface
      {
          function getHost(): string;
          function getInfo(): array;
          function getLatency(): integer;
          function getPort(): integer;
          function getTags(): array; // string[]
          function getType(): integer;
          function isArbiter(): boolean;
          function isHidden(): boolean;
          function isSecondary(): boolean;
          function isPassive(): boolean;
          function isPrimary(): boolean;
      }
      
      interface ManagerInterface extends ExecutorInterface
      {
          function getReadConcern(): ReadConcern;
          function getReadPreference(): ReadPreference;
          function getServers(): array; // ServerInterface[]
          function getWriteConcern(): WriteConcern;
          function selectServer(ReadPreference $rp);
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: