Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks: separate model hooks from collection hooks #12

Open
enov opened this issue Jan 31, 2014 · 0 comments
Open

Hooks: separate model hooks from collection hooks #12

enov opened this issue Jan 31, 2014 · 0 comments

Comments

@enov
Copy link
Owner

enov commented Jan 31, 2014

Currently we have the following hooks:

Main API Interface Method
Loading Interface_Aurora_Hook_Before_Load before_load(&$params)
Loading Interface_Aurora_Hook_After_Load after_load($model_or_collection)
Saving Interface_Aurora_Hook_Before_Save before_save($model_or_collection)
Saving Interface_Aurora_Hook_After_Save after_save($model_or_collection)
Saving (create) Interface_Aurora_Hook_Before_Create before_create($model)
Saving (create) Interface_Aurora_Hook_After_Create after_create($model)
Saving (update) Interface_Aurora_Hook_Before_Update before_update($model)
Saving (update) Interface_Aurora_Hook_After_Update after_update($model)
Deleting Interface_Aurora_Hook_Before_Delete before_delete($model_or_collection)
Deleting Interface_Aurora_Hook_After_Delete after_delete($model_or_collection)

Now, every time I want to implement an after load hook, I see myself doing this:

    public function after_load($model_or_collection) {
        if (Au::type()->is_collection($model_or_collection)) {

            // either loop through it
            foreach ($model_or_collection as $model) {
                $this->after_load($model);
            }

            // or silently return;
            return;
        }

        // it's a model now, change variable name
        // for the sake of readability
        $model = $model_or_collection;
        ...
}

So I am thinking of separating the hooks for models and collections. I hope to have two separate hooks for each case, something like:

    public function after_load_model($model);
    public function after_load_collection($collection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant