ownerStack[] = $this->owner; $this->owner = $owner; } /** * Temporarily modify the owner. The original owner is ensured to be restored * * @param mixed $owner Owner to set * @param callable $callback Callback to invoke * @param array $args Args to pass to callback * @return mixed */ public function withOwner($owner, callable $callback, $args = []) { try { $this->setOwner($owner); return $callback(...$args); } finally { $this->clearOwner(); } } /** * Clear the current owner, and restore extension to the state prior to the last setOwner() */ public function clearOwner() { if (empty($this->ownerStack)) { throw new BadMethodCallException("clearOwner() called more than setOwner()"); } $this->owner = array_pop($this->ownerStack); } /** * Returns the owner of this extension. * * @return Object */ public function getOwner() { return $this->owner; } /** * Helper method to strip eval'ed arguments from a string * that's passed to {@link DataObject::$extensions} or * {@link Object::add_extension()}. * * @param string $extensionStr E.g. "Versioned('Stage','Live')" * @return string Extension classname, e.g. "Versioned" */ public static function get_classname_without_arguments($extensionStr) { // Split out both args and service name return strtok(strtok($extensionStr, '('), '.'); } }