Register a custom renderer
@param $callback mixed The callable function (the renderer type)
@param array|null $args Arguments required for the callback
@return Renderer A renderer object
@throws Server500 If renderer is not callable
966033
public function registerCustomRenderer($callback, array $args = null):Renderer
    {
        if (is_callable($callback)) {
            $end = substr($callback, (strlen($callback) - 8));
            if ($end === "Renderer") {
                $this->display_elements["custom"] = $callback;
                $this->display_elements["args"] = $args;
                return ($this);
            } else {
                throw new Server500(new \ArrayObject(array("explain" =>
                    "Renderer name must be contain [Renderer] keyword at the end to be valid : $callback",
                    "solution" => "Please set a valid renderer name")));
            }
        } else {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Cannot register $callback custom renderer : Is not callable", "solution" =>
                "Please set a callable renderer")));
        }
    }
1258183
protected static function get_render_callback( $callback ) {
		/**
		 * Rendering the field.
		 *
		 * @param Field       $field         The passed in `CMB2_Field` object.
		 * @param mixed       $escaped_value The value of this field escaped.
		 * @param int         $object_id     The ID of the current object.
		 * @param string      $object_type   The type of object you are working with.
		 * @param \CMB2_Types $field_types   The `CMB2_Types` object.
		 */
		return function ( $field, $escaped_value, $object_id, $object_type, $field_types ) use ( $callback ) {
			if ( $field instanceof Contracts\Field ) {
				$callback( $field, $escaped_value, $field_types );
			}
		};
	}
762522
public function register($name, Closure $callback)
    {
        $this->checkCallbackName($name);

        $this->callbacks[$name] = $callback;

        return $this;
    }
979815
private function _renderArgs($args = [])
    {
        return '('.
            implode(',', array_map(function ($arg) {
                if ($arg instanceof jsExpressionable) {
                    return $arg->jsRender();
                }

                return $this->_json_encode($arg);
            }, $args)).
            ')';
    }
791099
public function wrap_callback(callable $callback, array $args=[]) {
		ob_start();
		foreach (self::$override_args as $key => $val)
			$args[$key] = $val;
		$callback($args);
		self::$body_raw = ob_get_clean();
		self::$body = json_decode(self::$body_raw, true);
		if (self::$body) {
			self::$errno = self::$body['errno'];
			self::$data = self::$body['data'];
		} else {
			self::$errno = 0;
			self::$data = [];
		}
	}
871793
public function registerCallback(callable $callback)
    {
        $this->pipeline
            ->pipe($callback)
            ->process($this->config);

        return $this;
    }
229490
public function call($callback, array $parameters = [])
    {
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);

        return $event;
    }
605928
protected function commandCallback($callback)
    {
        return (
            function ($output) use ($callback) {
                $this->output .= $output;
                if (is_callable($callback)) {
                    return call_user_func($callback, $output);
                }
            }
        );
    }
731015
static function executeCallback($callback, array $params = array()) {
    // If callback has @
    if (is_string($callback) && strpos($callback, '@') !== false) {
      // Split
      $arrCallback = explode('@', $callback);
      // Set object
      $object = class_exists($arrCallback[0]) ? (new $arrCallback[0]()) : null;
      // Set method
      $method = isset($arrCallback[0]) ? $arrCallback[0] : null;
      // Set callback
      $callback = array($object, $method);
    }
    // If not callable
    if ( ! is_callable($callback)) {
      // Throw error
      throw new InvalidCallback('Callback must be callable');
    }
    // Execute and return
    return call_user_func_array($callback, $params);
  }
683445
@Programmatic
    public Renderer newRenderer() {
        final Renderer renderer = (Renderer) classService.instantiate(getRendererClassName());
        serviceRegistry2.injectServicesInto(renderer);
        return renderer;
    }
1093038
public function addCallback($type, $callback)
    {
        if (!array_key_exists($type, $this->callbacks)) {
            throw new InvalidArgumentException(sprintf('Invalid type "%s"', $type));
        }

        $this->callbacks[$type][] = $callback;
        return $this;
    }
790492
public function set($callback, $args = [])
    {
        if (!$this->app) {
            throw new Exception(['Call-back must be part of a RenderTree']);
        }

        $this->view = $this->owner;

        if (isset($_GET[$this->name])) {
            $this->triggered = $_GET[$this->name];

            $this->app->run_called = true;
            $this->app->stickyGet($this->name);
            $ret = call_user_func_array($callback, $args);
            $this->sendSse();

            return $ret;
        }

        return $this;
    }
938219
public function render( callable $callback = null )
	{
		try
		{
			$contents = $this->renderContents();

			$response = isset( $callback ) ? call_user_func( $callback, $this, $contents ) : null;

			// Once we have the contents of the view, we will flush the sections if we are
			// done rendering all views so that there is nothing left hanging over when
			// another view gets rendered in the future by the application developer.
			$this->factory->flushSectionsIfDoneRendering();

			return !is_null( $response ) ? $response : $contents;
		}
		catch ( Exception $e )
		{
			$this->factory->flushSections();

			throw $e;
		}
		catch ( Throwable $e )
		{
			$this->factory->flushSections();

			throw $e;
		}
	}
414924
static public function register_render($instance)
  {
    if ($instance == null) {
      throw new \Exception('Instance is null.');
    }
    self::$app->renders->register($instance);
  }
663843
public function registerCallback( $serviceName, callable $callback ) {

		if ( !is_string( $serviceName ) ) {
			throw new InvalidParameterTypeException( "Expected a string" );
		}

		$this->registry[$serviceName] = $callback;
	}
138512
protected function callback($callback, array $args = [])
    {
        if (isset($callback)) {
            if (is_callable($callback) && $callback instanceof \Closure) {
                // Set new object and append the callback with some data.
                $o = new \ArrayObject($args);
                $o->app = App::instance();
                $callback = $callback->bindTo($o);
            } elseif (is_string($callback) && strpos($callback, '@') !== false) {
                $fixcallback = explode('@', $callback, 2);
                $this->Controller = $fixcallback[0];

                if (is_callable(
                    $callback = [$fixcallback[0], (isset($fixcallback[1]) ? $fixcallback[1] : 'index')]
                )) {
                    $this->Method = $callback[1];
                } else {
                    throw new \Exception("Callable error on {$callback[0]} -> {$callback[1]} !");
                }
            }

            if (is_array($callback) && !is_object($callback[0])) {
                $callback[0] = new $callback[0];
            }

            if (isset($args[0]) && $args[0] == $this->fullArg) {
                array_shift($args);
            }

            // Finally, call the method.
            return call_user_func_array($callback, $args);
        }
        return false;
    }
1292033
public static function registerCustomType($type, $callback)
    {
        if (!is_callable($callback)) {
            throw new \Exception(__('callback_is_not_function_exception'));
        }

        self::$custom_types[$type]= ['callback' => $callback];
    }