[Lunr.Locator] Core: add PSR-11 support

Review Request #827 — Created April 26, 2022 and submitted

smillernl
Lunr.Locator
feature/core/psr-11
lunr
Core: add PSR-11 support


  • 0
  • 0
  • 17
  • 1
  • 18
Description From Last Updated
pprkut
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     

    var_export() can produce multi-line output. I'm not sure that's what we want to use here.

    Conceptually we already have a backtrace attached to the exception, we should be able to read or at least discern the value from that.

  3. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     

    Failed to locate object for identifier '$id'! seems a bit nicer

  4. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     

    We can be more strict here I think. We're allowed to add the string typehint in child classes, we just can't remove it.

    Same for the get() method.

  5. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     
     
     
     

    No ContainerException here? Seems inconsistent

  6. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     
     
     
     

    I'm not sure we need the redirect. locate() is a protected method, so we can just inline it here. The only thing I'm not sure about is how potential strict typing would affect get_parameters().

  7. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 1)
     
     

    Not possible to instantiate '{$reflection->name}' is a bit clearer I think.

  8. src/Lunr/Core/Exceptions/ContainerException.php (Diff revision 1)
     
     
     
     

    We can do better

  9. src/Lunr/Core/Exceptions/NotFoundException.php (Diff revision 1)
     
     
     
     

    Here too

  10. It doesn't though

  11. It doesn't do that either

  12. 
      
smillernl
pprkut
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 2)
     
     
     
     
     
     
     
     

    We already did the registry check when we enter the method. Executing has() does it again. I prefer the old version of the code.

  3. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 2)
     
     

    Similar here. has() and get() do redundant checks . Outside the class this may be acceptable, but inside we want a more optimized version and don't execute useless code.

    1. I think we can just drop the call to has(). In the flow, if we have a string value that isn't meant to be used as a string value it's most definitely a missing locator recipe and we want to error out.
      The previous code was entirely built around not erroring out anywhere. It's either that or erroring out everywhere, but not some weird middle ground. So

      $processed_params[] = $this->get($value);
      

      should be good enough

  4. 
      
smillernl
pprkut
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 3)
     
     
     
     
     

    I think we can just replace this with a call to load_recipe(), and then check the cache.

    But also have to check the cache before calling load_recipe()

    1. But you don't always want to load the file. You just want to know it's available right?

    2. It's an optimization. Situations where you call has() and get() in sequence are more likely than has() returning TRUE and not calling get() after.

      So we generally save one call to stream_resolve_include_path().

      But especially checking the cache would be important. Accessing the filesystem is slow and we don't load a recipe more than once. Also, just because the file exists doesn't mean the information in the file matches. That's why it's important to also check the cache after the recipe is loaded from the file system.

  3. 
      
smillernl
pprkut
  1. 
      
  2. composer.lock (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     

    composer.lock probably shouldn't be changed, considering there's no change to composer.json either

  3. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     

    We also need a cache check before load_recipe(), then we have the same logic as get(), just without actually trying to instantiate anything.

  4. 
      
smillernl
pprkut
  1. Ship It!
  2. 
      
smillernl
Review request changed

Status: Closed (submitted)

Loading...