public function exportCallable($callback)
{
$wrappedCallback = null;
while ($callback instanceof WrappedInvocable) {
$wrappedCallback = $callback;
$callback = $callback->callback();
}
$label = '';
if ($wrappedCallback) {
if ($wrappedCallback->isAnonymous()) {
return $this->export($wrappedCallback);
}
$label = $wrappedCallback->label();
if (null !== $label) {
$label = '[' . $label . ']';
}
}
if ($callback instanceof Closure) {
return $this->export($callback) . $label;
}
$reflector = $this->invocableInspector->callbackReflector($callback);
if (!$reflector instanceof ReflectionMethod) {
return $reflector->getName() . $label;
}
$class = $reflector->getDeclaringClass();
$name = $reflector->getName();
if ($class->implementsInterface('Eloquent\\Phony\\Mock\\Mock')) {
if (($parentClass = $class->getParentClass()) && $parentClass->hasMethod($name)) {
$class = $parentClass;
} else {
try {
$prototype = $reflector->getPrototype();
$class = $prototype->getDeclaringClass();
} catch (ReflectionException $e) {
// ignore
}
}
}
$atoms = explode('\\', $class->getName());
$rendered = array_pop($atoms);
if ($wrappedCallback instanceof WrappedMethod) {
$name = $wrappedCallback->name();
$handle = $wrappedCallback->handle();
if ($handle instanceof InstanceHandle) {
$label = $handle->label();
if (null !== $label) {
$rendered .= '[' . $label . ']';
}
}
}
if ($reflector->isStatic()) {
$callOperator = '::';
} else {
$callOperator = '->';
}
return $rendered . $callOperator . $name;
}