-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[RFC] Extract configurables #202
Comments
I think it will be a good refactoring in favor of code reusability. |
+1 for the idea, but will you do it ? By creating a new bundle again ? |
No, I'm thinking about a library (component). |
@umpirsky, the registry is something that repeats a lot and always has the same behavior. Would be nice abstract this kind of classes and provide interfaces and base classes. To exemplify, I'm thinking in something like the following code for registries: <?php
interface Registry
{
public function register($object);
public function unregister($object);
public function has($object);
public function remove($object);
public function supports($object);
}
class Registry implements Registry
{
protected $type;
public function __construct($type)
{
$this->type = $type;
}
// methods implementation...
public function supports($object)
{
return $object instanceof $this->type;
}
} Thus, add a new registry will be simple like: <service id="acme.registry.car_type" class="%sylius.common.registry%">
<argument>%acme.model.car_type%</argument>
</service> What do you think? |
Yes. Thats what I had in mind. Maybe even without isSupported, so it will
|
I didn't understand what you meant with "so it will be generic and type hint on interface". |
<?php
interface Registerable
{
public function getType();
public function getConfigurationFormType();
}
interface RuleCheckerInterface extends Registerable
{
public function isEligible(PromotionSubjectInterface $subject, array $configuration);
}
interface Registry
{
public function register(Registerable $object);
public function unregister(Registerable $object);
public function has(Registerable $object);
public function remove(Registerable $object);
} And you can have generic implementation of Registry interface. |
Yes, but you are limiting to a very specific type of |
We can have two implementations then. Where are they used in Sylius other then for this things I mentioned? |
Will be used a lot in the customized product and flexible variant and probably in other tag-based situations. |
Yes, then we can go with your approach, having two implementation would just add complexity. Its up to user then to implement just this suppports() method. |
Where will this library be available ? Will all the bundles require it ? |
My idea for this registry was exactly as @marcospassos said. Generic registry with a type (interface in most cases) passed as argument. I'd include it in |
@pjedrzejewski Components is fine, but you must create composer package/git mirror for each. |
IMHO, it is more of bundle than a library. What is the point of creating a library instead of a bundle? @umpirsky why would I use it out of Sylius? I think that these generic things should be added to a |
@marcospassos I don't see why wouldn't one use it out of Sylius? |
It's something pretty simple to implement. If I need it in my non-sylius project, probably I would just implement a |
I believe we should abstract as much as possible from bundles to libraries... It's too much work to do it now probably, but with new things, used across many bundles - I think we should use libraries/components. SyliusCommonBundle is an idea I was considering for pretty long time, but my fear is that it will get a total mess. Bundles should have one concrete feature/responsibility. |
I agree that things that can be clearly reusable by someone else should moved to libraries, using a integration layer (Bundle) to integrate to Sylius (Vespolina is migrating to this approach - a lot of work that seems had frozen the development), but the "CommonBundle" is something related to a few things (and must be "few" otherwise we'll get a total mess) that I can't see why I would use out of Sylius. But maybe I just can't imagine what are your use cases. About splitting in small bundles, I don't know if it's a good idea, once you will get a ton of bundles with small responsibilities, what is impracticable due performatic issues and some other reasons. |
Any changes here? I need something like ComonBundle for #221 |
Is there any news on this? There was a Sylius/Components repo for a short period of time but it looks like that has been removed in the latest reorganization. I was going to have a look at moving the Promo/Tax/Shipping registries over to using the generic component, but with the Components repo now gone has that approach been scrapped? |
@elliot Nope, we will move it to the |
Registry part is covered now. |
For configurable I think DRY does not apply here, cause all these are fairly different. Maybe we can look at it in the future, but for now extracting registry is enough. |
error of template in Getting list of resources
We have some code duplicated across bundles currently.
For checkers and acitons in promotions bundle, we implemented configurable forms that allowed us to configure both checkers and acitons with any configuration set. And create promotions by combining different checkers and actions.
So we have for each of them (checkers and actions) a registry, a configuration form type, a form listener and compiler pass.
We done same thing for shipping and now I am trying to apply same pattern for reports.
I think that it would be nice to extract common functionality into a separate library.
It will probably be some common interfaces, form event listener to add configuration to form.registry, abstract CompilerPass...
Any opinion on this is welcome.
The text was updated successfully, but these errors were encountered: