Hi, all!

I'm going to respond to a couple different posts in this thread at
once, quoting the bits I want to respond to.

On 2017-01-13 Nicolas Grekas wrote:
>
> the exception part is really where things start to look like a zoo. Because 
> we have many animals there in the "Exception" namespace, and mapping them to 
> PSR11's NotFoundExceptionInterface is going to be non trivial and never 
> perfect I'd say.
>
> If you read the thread, you'll see that this sentence "Exceptions directly 
> thrown by the container" is unclear for now - what does "directly" mean?

It means exceptions that the container throws itself, vs. an exception thrown
elsewhere, such as by a factory it invokes, or PHP itself (for type errors).

The container will generally only need to throw exceptions directly for a
handful of issues:

- If a dependent service is missing.
- Naming conflicts (unlikely, but can happen).
- Inability to resolve an argument; as an example, in reflection-based
  containers, when encountering required arguments without typing or with scalar
  typehints.

Essentially, these are a form of RuntimeException; you're attempting to create a
service, but cannot, due to problems in container configuration.

> > the NotFoundExceptionInterface triggered by the inner get call SHOULD NOT 
> > bubble out.
>
> Fortunately enough, this is only a "SHOULD NOT", so we can do as we want and 
> still be compliant. Because I agree with Larry here, the wording is so 
> abstract that in practice it hardly helps. What does missing mean? Eg does a 
> brokenly configured first level service qualify as such?
> Reasoning from the inside of the container, you may say no.
> But reasoning from the outside, the user might expect a yes, so that eg a 
> chained-container can continue with the next container in the chain (provided 
> NotFoundExceptionInterface VS ContainerExceptionInterface could be the 
> trigger to decide if the chain should break or continue? what is it for 
> otherwise? doesn't that concept duplicate the "has()" method?)

This sounds like using exceptions for control flow, which is often a
questionable design choice.

I agree with Nicolas here, however, in that I'd likely allow the
NotFoundExceptionInterface to bubble out in this case, not for control flow, but
to make it clear to the end user that a dependency is missing from the
container.

> > "Don't standardize an *exception interface* for a known error case because 
> > *nobody* can think of a reason you'd catch that"
>
> Larry just gave one: better error handling.
> Error handling is one of the very well done part of PSR-6 - far better that 
> eg how Doctrine Cache behaves. (eg when caching unserialisable objects, PSR-6 
> tells what to do).
> Excellent error handling is a *strong* argument to me and a requirement for a 
> standard to me.

I agree... except that no concrete examples have been provided of when such an
exception should be thrown, nor when it would be useful to catch it. If you take
the above example I note of having a factory raise a
`NotFoundExceptionInterface` instance in the case that a dependency it requires
is missing, there's no need for an additional exception.

Turning now to these:

On 2017-01-13 Larry Garfield wrote:
>
> That is, with that [delegate lookup] removed, what's left to standardize?  
> get() and has() are barely an specification.

and:

On 2017-01-13 Fabien Potencier wrote:
>
> Of course, having a specification with just a get() and a has() methods makes 
> it really easy to implement; and in fact, doing so in Symfony is trivial (see 
> https://github.com/symfony/symfony/pull/21265).
>
> But is it really enough for interoperability? I doubt it.

Máté note an example where he composed a ContainerInterface in a router, and how
that allowed him to have a container-agnostic router. Nicolas dismissed this,
saying that because it does not use `has()`, it could very well have simply used
a callable.

I'm going to provide another example. It's similar to Máté's: the Expressive
routing and dispatch system.

We *do* use `has()`; if that returns false, we're able then to raise an
application exception indicating that the middleware to which the request routed
is invalid and/or missing. Otherwise, we pull it using `get()`, and, if that
operation raises an exception, we can report something completely different.

However, container-interop provided an important piece outside of the defined
methods, and *even despite the lack of a configuration specification*. How?

Factories.

We can write factories that only hint on container-interop. We are then able to
provide common configuration that we then adapt to each container type we
currently support. This work was trivial, but allows developers to select the
container that best suits their purposes. It even allows them to select
something different — e.g., Disco — and adapt the configuration for their own
needs.

But the factories work the same *regardless of the container used*.

This allowed us to make the design decision that the application and router only
care about a ContainerInterface.

So, yes, the standard as it is currently *does* provide interoperability. It's
not a nebulous thing at all; I and many others *have already built on it*;
that's why there's been a working group. It's already field-tested. Whether or
not each of you ultimately feel it's a fit for your own projects is your own
choice, but I don't think you can make a blanket declaration that it's worthless
when others have been actively building with it for quite some time now.

Finally, to each of those commenting JUST TODAY: I get it, we're all busy.
However, this is the SECOND review period we've had, and you've waited until
literally the last day of that to raise objections. Please, all of us, try to be
more diligent; these are conversations we should have had weeks or months ago,
not this late in the process.

-- 
Matthew Weier O'Phinney
[email protected]
https://mwop.net/

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/CAJp_myU3gytjNzQboUJ%3Dev8SSvDrqJu_1eM6wY0RkTF8ND0iTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to