pugx / godfather Goto Github PK
View Code? Open in Web Editor NEWThis project forked from liuggio/godfather
Strategy Pattern for PHP and Symfony2
License: MIT License
This project forked from liuggio/godfather
Strategy Pattern for PHP and Symfony2
License: MIT License
Could be great have a way to configure the bundle in order to have multiple instances of the service, this is useful when you want to separate concern.
godfather:
death:
contexts:
manager:
interface: \ABInterface
life:
default: true
contexts:
manager:
interface: \ABInterface
the strategies:
services:
manager.entity_life:
class: EntityProductManager
arguments: ['life']
tags:
- { name: godfather.strategy, instance:'life', context_name: 'manager', context_key: %product.show.class% }
manager.entity_death:
class: EntityProductManager
arguments: ['death']
tags:
- { name: godfather.strategy, instance:'death', context_name: 'manager', context_key: %product.show.class% }
and then the code with multiple instances
$this->getContainer('godfather.life')->getManager($entity);
$this->getContainer('godfather.death')->getManager($entity);
this will introduce a BC
In order to not recreate a new definition and use instead the alias on standard contexts, the FQCN is harcoded on non standard context.
A cleaner solution would be using the Configuration.
the defahttps://github.com/PUGX/godfather/blob/master/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/GodfatherExtension.php#L72
Add name as key into the dependency injection.
The goal is remove the name
key from the configuration
Strategy pattern work like a black box, sometimes is difficult to debug,
could be great to have a command to view all the strategies and contexts, like
app/console container:debug
The context_key that works as discriminator for a strategy is a concrete class. Would it be useful extending this discrimination to abstract classes and interfaces?
services:
manager.standard:
class: StandardProductManager
manager.shoe:
class: ShoeProductManager
tags:
- { name: godfather.strategy, context_name: 'manager', context_key: PUGX\CartBundle\FootWear\AbstractShoe }
thus I can treat Sneakers, HighHeels and HikingBoots with a single strategy.
Does it make sense? do you see any dangerous side effect ?
Is very bad practice recreate the container.
Should be great if the symfony bundle could use the container of the framework, instead of a personal array of services.
The step should be:
Godfather
container
getStrategy
with something like: /**
* Get the strategy for the key ($contextName, $context).
*
* @param string $contextName
* @param mixed $context
*
* @return mixed
*/
public function getStrategy($contextName, $context)
{
$contexts = $this->getContext();
$serviceId = $contexts[$contextName]->getStrategy($context);
return $this->container->get($serviceId);
}
Another option could be not inject the container and uses the getStrategy in order to retrieve the name of the service not the service itself
eg
$strategyServiceId = $this->container->get('godfather')->getStrategy('xyz', $class);
$this->container->get($strategyServiceId)->doSomething();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.