bowerphp icon indicating copy to clipboard operation
bowerphp copied to clipboard

Config as singleton

Open piotrooo opened this issue 11 years ago • 8 comments
trafficstars

I think config should be represent as singleton pattern. Now is passed to all objects but should be one instance of object, with global access.

piotrooo avatar Nov 08 '14 14:11 piotrooo

I don't know... as you mention, singleton is a kind of global, and this recalls the bad old times of PHP. Anyway, I'm open to any suggestions: if you can summarise pros and cons of both approaches, we can discuss it

garak avatar Nov 08 '14 19:11 garak

Well I don't think singletons are good ideas.

julkue avatar Nov 08 '14 20:11 julkue

Yeep maybe singleton is nod good idea, but passing configs for all object are not good too. Maybe some factories for config for package and main bower file.

piotrooo avatar Nov 08 '14 23:11 piotrooo

I thinking about try to implements global configs. I still believe that a good solution will be singleton with reload function.

Why I think is will be good approach? Main config file (bower.json) should be globally accessed without need for passing or creating it in each object. Package config files (/.bower.json) should be globally access too.

In this objects should be method to reload configs.

Passing configs for each object is a little awkward, such an approach obscures methods usage and generates another level of complication.

@garak why you thing is bad old time? :) @julmot why?

piotrooo avatar Nov 09 '14 13:11 piotrooo

Global was (and still is) bad because makes hard to understand where variables are coming from. On the other side, passing objects gives maximum control, and it's a pattern known as "inversion of control"

garak avatar Nov 09 '14 17:11 garak

You explanations convinces me. But I think is needed to extract creating config, filesystem etc from command object and pass to command by IoC in Appication getDefaultCommands method. This approach is strictly IoC convention.

piotrooo avatar Nov 09 '14 19:11 piotrooo

I agree that commands need a refactoring. I was thinking to introduce a small dependency container (maybe Pimple) to do that

garak avatar Nov 09 '14 20:11 garak

I try to implement pimple ioc container only for update command, tests wasn't working but this commit is only proof of concept, so if you have any suggestions we can talk about it.

piotrooo avatar Nov 13 '14 22:11 piotrooo