Skip to content

Commit

Permalink
do register_object_hoooks on load, deprecate register_object_hooks fu…
Browse files Browse the repository at this point in the history
…nction.
  • Loading branch information
makasim committed Jul 24, 2018
1 parent 55ab292 commit 0936e6e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/functions/objects.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
<?php
namespace Makasim\Values;

call_user_func(function() {
$resetObjectsHook = function($object, $key) {
call($object, $key, function($key) {
if (property_exists($this, 'objects')) {
array_unset($key, $this->objects);
}
});
};

register_global_hook(HooksEnum::POST_SET_VALUE, $resetObjectsHook);
register_global_hook(HooksEnum::POST_ADD_VALUE, $resetObjectsHook);
register_global_hook(HooksEnum::POST_SET_VALUES, function($object) {
call($object, function() {
$this->objects = [];
});
});
});

function register_object_hooks() {
// does nothing, is kept for BC. will be removed later.
}

/**
* @param object $context
* @param string $key
Expand Down Expand Up @@ -135,25 +157,6 @@ function get_objects($context, $key, $classOrClosure = null)
})->call($context, $key, $classOrClosure);
}

function register_object_hooks()
{
$resetObjectsHook = function($object, $key) {
call($object, $key, function($key) {
if (property_exists($this, 'objects')) {
array_unset($key, $this->objects);
}
});
};

register_global_hook(HooksEnum::POST_SET_VALUE, $resetObjectsHook);
register_global_hook(HooksEnum::POST_ADD_VALUE, $resetObjectsHook);
register_global_hook(HooksEnum::POST_SET_VALUES, function($object) {
call($object, function() {
$this->objects = [];
});
});
}

function register_propagate_root_hooks($object)
{
register_hook($object, HooksEnum::POST_SET_OBJECT, function ($object, $context, $contextKey) {
Expand Down

0 comments on commit 0936e6e

Please sign in to comment.