propelorm/Propel2 — Issue #84: [RFC] Add `typehint` attribute on `Columns`
Author: willdurand
Created: 2011-12-07 20:51:11+00:00
State: open
Labels: RFC

Hi,

I started a new behavior for Propel 1.6 named [**Typehintable**](https://github.com/willdurand/TypehintableBehavior) and I thought that should be nice to provide a native solution for the following use case: to allow users to typehint generated code in order to be compliant with _interfaces_.

### Why ?

* Because it's possible to type hint methods, and to implement interfaces using proxy classes is almost always a pain;
* Because it's cool to implement interfaces;
* Because it's cool to type hint methods.

Feel free to add more use cases :)

### What ?

We should be able to typehint the following methods:

* `setXXX()`
* `addXXX()`
* `removeXXX()`

We should allow PHP interfaces and primitive types (actually `array`).

### How ?

By adding new attributes to the `column` and `table` tags:

``` xml

```

Will generate:

``` php
public function setRoles(array $roles)
{
// ...
}
```

Or:

``` xml

```

A `typehint` on a `table` tag will allow to typehint `addGroup()`, `removeGroup()` methods on related tables (in a N-N relation for instance). That way, you'll deal with relations, which is the most common use case.
It will also modify the phpdoc.

The `typehint` has to be an interface or `array`, if it's not the case, you'll throw an exception at build time.

Thoughts?

William