Factories and multitons

5 views
Skip to first unread message

Jelmer Schreuder

unread,
May 6, 2011, 2:38:11 PM5/6/11
to fuelph...@googlegroups.com
I just noticed that when you use Validation::factory() a second time for the same name it overwrites the older instance but keeps connected to the collection of fields through the old Fieldset object, this is confusing. Also people shouldn't use factory() a second time, they should use instance() to retrieve an earlier instance.

How do you guys feel about me going through all the factories and making them throw exceptions when they're trying to create an instance with a name that already exists?

Thus:

Validation::factory('example'); // creates the Validation instance "example"
$val = Validation::instance('example'); // retrieves the instance "example"
Validation::factory('example'); // throws an exception as there already is an instance named "example"

Phil Sturgeon

unread,
May 7, 2011, 6:11:44 AM5/7/11
to fuelph...@googlegroups.com
I think that is a great case for throwing an exception. Overriding will cause all kinds of havoc, so it shouldnt be possible. Maybe add "use instance('example') instead" to the message.

Phil



Jelmer Schreuder
6 May 2011 19:38

Dan Horrigan

unread,
May 7, 2011, 9:16:51 AM5/7/11
to fuelph...@googlegroups.com, fuelph...@googlegroups.com
I agree, Exception is great.

Sent from my iPhone

On May 7, 2011, at 6:11 AM, Phil Sturgeon <ph...@fuelphp.com> wrote:

I think that is a great case for throwing an exception. Overriding will cause all kinds of havoc, so it shouldnt be possible. Maybe add "use instance('example') instead" to the message.

Phil



<compose-unknown-contact.jpg>
Jelmer Schreuder
6 May 2011 19:38

Jelmer Schreuder

unread,
May 7, 2011, 12:32:18 PM5/7/11
to fuelph...@googlegroups.com
Done, you cannot use factory twice for the same name anymore for Validation or Form.

Reply all
Reply to author
Forward
0 new messages