Lazily initialize Model's metadata, refactor Model::_init() and Model::_classes is no more static #608

wants to merge 1 commit into


None yet
1 participant

jails commented Aug 9, 2012

Some refactoring of the Model class :

1 - Model's metadatas can be initialized using cutom closures.

    'initializers' => array(
        'source' => function(&$meta) {
            if ($meta['source'] === null) {
                $meta['source'] = 'custom_posts';
        'custom' => function(&$meta) {
            $meta['custom'] = 'custom_data';

2 - Model::_classes is no more static.

3 - Since Models are in the "same time" static and dynamic, for consistency, this PR reintroduce the _init() method which is a standard method called just after __construct.
Here _init() is called just after the class instanciation (instead of __construct) and can be used for lazy initializations.
__init() can always be used for "direct" initializations.

__init() is a static function called during the autoload step. using parent::__init() will result to call the parent's __init() twice. So in li3 parent::__init() is an invalid syntax and shouldn't be used.

@jails jails closed this Aug 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment