A Service Provider would make Tardis easy to use by another developers, the provider should:
Example
Consider this a suggestion, not as a contract to be followed or an example of implementation:
<?php
$app = new Silex\Application;
/** Other relevant configuration, such as cache storages. */
$app->register(new Computaria\Tardis\Bridge\SilexProvider); // provides `tardis.factory`
// Creating the proxy factories
$app['cache.persistent'] = $app->share(function($app) {
return $app['tardis.factory']->grow($app['cache.storage.redis']);
});
$app['cache.volatile'] = $app->share(function($app) {
return $app['tardis.factory']->grow($app['cache.storage.memcache']);
});
// Providing cached instances (using Pimple/Silex as container)
$app['user.repository'] = $app->share(function($app) {
return $app['cache.persistent']->cacheCallsFrom('MyApp\Repository\Users');
});
$app['user.stats'] = $app->share(function($app) {
return $app['cache.volatile']->cacheCallsFrom($app['user.model']);
});
As one can see, this is very verbose, if we could provide something to make it less verbose I would be very happy! 😄
$app['tardis.cache']->serviceUsingStorage('user.repository', $app['redis']);
$app['tardis.cache']->serviceUsingStorage('user.stats', $app['memcache']);
This would remove some flexibility (which can always be achieved through creating objects by hand, as shown previously), but making the factory already provide a service can make for much verbose declaration that does a lot of job for the developer:
- Extend an existing service declaration, making it a cached-only service now.
- Choose the best identity generator strategy available on the fly.
- Automatically creates and keeps proxy factories for each storage and reusing them when possible.
A Service Provider would make Tardis easy to use by another developers, the provider should:
Tardis\Factoryservice.Example
Consider this a suggestion, not as a contract to be followed or an example of implementation:
As one can see, this is very verbose, if we could provide something to make it less verbose I would be very happy! 😄
This would remove some flexibility (which can always be achieved through creating objects by hand, as shown previously), but making the factory already provide a service can make for much verbose declaration that does a lot of job for the developer: