[TYPO3-mvc] idea: "magic" accessors via autoloader

Martin Kutschker masi-no at spam-typo3.org
Fri May 28 10:18:46 CEST 2010


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


More information about the TYPO3-project-typo3v4mvc mailing list