diff --git a/classes/GravProxy.php b/classes/GravProxy.php new file mode 100644 index 0000000..9629dab --- /dev/null +++ b/classes/GravProxy.php @@ -0,0 +1,160 @@ +object = $object; + $this->page = $page; + $this->callable = $callable; + + if ($name) { + $this->name = is_array($name) ? $name : [$name]; + } + + if ($callable && !is_callable($callable)) { + throw new \Exception(sprintf("Function '%s' must be callable.", $callable)); + } + } + + public function __call($method, array $arguments = []) + { + if ($callable = $this->callable) { + $result = $callable([// new Event([ + 'type' => '__call', + 'object' => $this->object, + 'page' => $this->page, + 'name' => implode('.', $this->name), + 'arguments' => [$method, $arguments] + ]); + } + + return is_null($result) ? call_user_func_array([$this->object, $method], $arguments) : $result; + } + + /** + * ArrayAccess implementation + */ + + /** + * Whether or not an offset exists. + * + * @param mixed $offset An offset to check for. + * @return bool Returns TRUE on success or FALSE on failure. + */ + public function offsetExists($offset) + { + if ($callable = $this->callable) { + $result = $callable([ //new Event([ + 'type' => 'offsetExists', + 'object' => $this->object, + 'page' => $this->page, + 'name' => implode('.', $this->name), + 'arguments' => [$offset] + ]); + } + + return is_null($result) ? isset($this->object[$offset]) : $result; + } + + /** + * Returns the value at specified offset. + * + * @param mixed $offset The offset to retrieve. + * @return mixed Can return all value types. + */ + public function offsetGet($offset) + { + if (isset($this->object[$offset])) { + if ($callable = $this->callable) { + $result = $callable([ // new Event([ + 'type' => 'offsetGet', + 'object' => $this->object, + 'page' => $this->page, + 'name' => implode('.', $this->name), + 'arguments' => [$offset] + ]); + } + + if (is_null($result)) { + $name = array_merge($this->name, [$offset]); + $result = new static($this->object[$offset], $this->page, $this->callable, $name); + } + + return $result; + } + } + + /** + * Assigns a value to the specified offset. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + */ + public function offsetSet($offset, $value) + { + if ($callable = $this->callable) { + $result = $callable([ //new Event([ + 'type' => 'offsetSet', + 'object' => $object, + 'page' => $this->page, + 'name' => implode('.', $this->name), + 'arguments' => [$offset] + ]); + } + + if (is_null($result)) { + if (is_null($offset)) { + $this->object[] = $value; + } else { + $this->object[$offset] = $value; + } + } + } + + /** + * Unsets an offset. + * + * @param mixed $offset The offset to unset. + */ + public function offsetUnset($offset) + { + if ($callable = $this->callable) { + $result = $callable([// new Event([ + 'type' => 'offsetUnset', + 'object' => $this->object, + 'page' => $this->page, + 'name' => implode('.', $this->name), + 'arguments' => [$offset] + ]); + } + + if (is_null($result)) { + unset($this->object[$offset]); + } + } +} diff --git a/classes/Shortcodes/Assets.php b/classes/Shortcodes/Assets.php index 3ebf46f..a5a3f55 100644 --- a/classes/Shortcodes/Assets.php +++ b/classes/Shortcodes/Assets.php @@ -80,12 +80,8 @@ public function execute(Event $event) $type = strtolower($options->get('type')); $body = trim(strip_tags($event['body'], '