Feature #7221

Automatic accessor methods (especially for models)

Added by Michael Sauter about 11 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
Complexity:

Description

When writing models, there is a lot of code to be written for getters/setters. I understand why __get() and __set() is not a good solution for this problem, but maybe we could do something else to shorten this:

FLOW3 already parses annotations and builds proxies for all mdoels, so why not have something similar to the following example:

/**
 * @var string
 * @accessors
 */
protected $title;

FLOW3 could then build getTitle() and setTitle() in the proxy class.

I got the inspiration from the Cappucino framework, see more on this topic here: http://cappuccino.org/discuss/2008/10/26/synthesizing-accessor-methods/

In this blog post, they also suggest more options, like "readonly", or specifying a custom name for the getter / setter method.

What do you think?

#1

Updated by Karsten Dambekalns about 11 years ago

  • Start date deleted (2010-04-12)

That sounds great... on first read. But in a scripting language like PHP those methods are only available when you use the proxy class. Something you do not do in unit tests. So, how would you test that?

What would be really cool, is if that was a language feature, like in C#...

#2

Updated by Michael Sauter about 11 years ago

Hmm, didn't think of unit tests. Too bad. Guess you would have implemented this already if it were possible ;)

#3

Updated by Robert Lemke about 11 years ago

  • Status changed from New to Closed

Also available in: Atom PDF