[TYPO3-mvc] idea: "magic" accessors via autoloader
"Christian Müller [kitsunet]"
christian at kitsunet.de
Fri May 28 10:52:07 CEST 2010
On 28.05.2010 10:18, Martin Kutschker wrote:
> Hi!
>
> Now that we have an autoloader we can ship load any class we want to for the one that has been asked
> for. IIRC the AOP framework works that way. Instead of loading the real class it will return a
> generated proxy class.
>
> But why use a proxy if you can augment the real class? Changing a class on-the-fly is no big thing
> using PHP's tokenizer.
>
> So the idea is to create yet another annotation for properties that tells the autoloader to create
> default accessors if none are present in the source code.
>
> eg
>
> class Foo {
>
> /**
> * @accessors set get
> */
> protected $bar;
>
> }
>
> will be turned into this code:
>
> class Foo {
>
> protected $bar;
>
> public function setBar($value) {
> $this->bar = $value;
> }
>
> public function getBar($value) {
> return $this->bar;
> }
>
> }
>
> No funny magic with __call and yet no tedious type work.
>
> But what does this mean for unit testing? Can it cope with the autoloader? Or does it need a special
> loader as well that does the generation magic just for the tests?
>
> Masi
I also proposed to have magic acccessors with annotations, I just had
not thought about the implementation, and this way is a great idea!
Maybe it could even be a stream wrapper? Then it should be no problem
for unit tests?
Chrisitian
More information about the TYPO3-project-typo3v4mvc
mailing list