Download the PHP package bbc/ipr-resolver without Composer

On this page you can find all versions of the php package bbc/ipr-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ipr-resolver

BBC\iPlayerRadio\Resolver

A simple requirement resolution system for plain-old-php objects.

Build Status Latest Stable Version Total Downloads License

Installation

This is a standard composer library, so usual install rules apply:

This library requires PHP 5.5 or higher as it makes use of generators!

Background

Objects often have dependencies on each other. It's a pain. To use a uniquely radio example; we sometimes put "Brand" objects on our pages (think "The Archers"). However, we have decided that the most useful thing to show to the audience is the latest episode from that brand. That doesn't come as part of the brand metadata, so we have to do a separate call for it. We end up with something like this:

This gets worse if you have a list of brands and need to loop through each of them, hydrating them with their latest episode since the work is now probably happening in series and definitely cluttering up your code:

And what about if the latest episode ALSO has to make a data call to make itself whole! This is a nightmare. And how do I even inject dependencies down that chain?!

Wouldn't it be nice if we could just make a brand object, and say; "Sort yourself out bucko!" and it does. Yeah, we thought so too.

Enter stage left; the Resolver.

Usage

To flag that an object has dependencies, you need to implement the BBC\iPlayerRadio\Resolver\HasRequirements interface which has a single method: requires().

If you've never come across coroutines before, this probably looks a bit weird! But you can think of it like a lazy promise, the yield throws up to the Resolver saying "I need this to continue, handle it!".

This is how you then grab a fully fleshed out item:

Hang on, what's that new EpisodesBackend? This is how the Resolver knows how to solve requirements. Resolver backends take requirements and generate the actual result of the requirement.

So the EpisodesBackend would look something like this:

Whilst the syntax of using the resolver is slightly nicer, how does this help performance? We're still looping through and running each query synchronously.

Well, consider that the fetchLatestEpisodes was making a cURL request. We could now batch all those up do it as a single multi-curl request:

Using the Resolver allows you to ignore the actual details of how your objects fetch their data, and instead simply define what they need and let the Resolver and ResolverBackends do the work!

Hint hint imagine coupling this with the WebserviceKit library with a ResolverBackend that looks for QueryInterface instances and then multiFetch()'s them... ;)

You can also pass flags into the Resolver to help requires() functions work out what they need to do:

Note: all requires() functions see all flags, so keep them specific to avoid problems!

If a requirement is not supported by any backend (none of the canResolve() functions return true), then a BBC\iPlayerRadio\Resolver\UnresolvableRequirementException will be thrown, contained within it the requirement that failed, which you can access with getFailedRequirement().

Resolver Backends

Resolver Backends have two functions; firstly to state whether or not they understand a requirement (via the canResolve function) and then to take a list of requirements that it can resolve and to resolve them (via doResolve)!

There are some rules for writing your own resolver backends:

How this actually works

You might be wondering how the whole yield thing works. It's a feature in PHP called Generators. Usually when people think of Generators they think of the "cheap iterator" side of things, but there's another side to Generators in a feature called "Coroutines".

This basically involves exploiting the fact that PHP suspends execution of a function when it reaches a yield, only returning control when the loop advances. By calling a function that yield's outside of a loop, you get an object which you can manually advance, allowing you to effectively hold a function in suspended animation until you have a real value for it.

Mind melting no? Here's some really good links that helped me get my head around them:

Credits

This library is based off of an extremely similar technique showcased by Bastian Hofmann in his talk at the PHPUK 2015 conference. Thanks Bastian!


All versions of ipr-resolver with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bbc/ipr-resolver contains the following files

Loading the files please wait ....