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

Prohibit passing LogSubscriber to Manager::addSubscriber()

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.17.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Revised Description

      Throw if a LogSubscriber is passed to MongoDB\Driver\Manager::addSubscriber(), since client-scoped log subscription is not currently possible in libmongoc. If this changes down the line, we can relax this restriction and add support. Until then, we'll rely on an exception to inform users that a subscriber implementation will have no effect.

      This issue originally proposed throwing if any unsupported implementation is passed to an addSubscriber() function; however, there's little benefit in doing so given that there are no restrictions on extending the Subscriber interface. Limiting the exception to a LogSubscriber seems sufficient.

      Original Description

      Considering throwing in MongoDB\Driver\Manager::addSubscriber() and MongoDB\Driver\Monitoring\addSubscriber() if an object is passed that implements Subscriber but not one of the more specific interfaces actually handled by the driver. The function currently NOPs when adding a subscriber that is already registered, but will happily register a Subscriber implementation thrown at it (e.g. userland implementation). Throwing would alert users to the fact that they're passing an object that won't be used.

      One possible side effect of this change (however minor) is that addSubscriber() would no longer increment the ref count on an unsupported object.

      There should be no reason to apply this check to removeSubscriber(), since the existing NOP behavior there is unlikely to mislead users.


      This came up in PHPC-2180, as we're considering using the existing add/removeSubscriber methods to work with loggers.

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

              Created:
              Updated:
              Resolved: