Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Silex through a Service Provider #8

Open
3 tasks
augustohp opened this issue Nov 28, 2015 · 0 comments
Open
3 tasks

Support for Silex through a Service Provider #8

augustohp opened this issue Nov 28, 2015 · 0 comments

Comments

@augustohp
Copy link

A Service Provider would make Tardis easy to use by another developers, the provider should:

  • Provide a Tardis\Factory service.
  • Manage proxy factories internally.
  • Proxy an existing service, extending it.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant