/** * Magic call from the function collection. * * @param $method * @param $params * @return mixed * @throws \WP_Error */ public function __call($method, $params) { if (!isset($this->methods[$method])) { throw new Exception("Method '{$method}' not set!"); } return $this->app->call($this->methods[$method], $params); }
/** * Boot the widgets. * * @return void */ public function boot() { global $wp_widget_factory; foreach ($this->widgets as $widget) { register_widget($widget['class']); if (method_exists($instance = $wp_widget_factory->widgets[$widget['class']], 'boot')) { $this->app->call([$instance, 'boot'], ['app' => $this->app, 'plugin' => $widget['plugin']]); } } }
/** * Handles the route. */ public function handle() { $response = $this->app->call($this->uses, array_merge(['app' => $this->app], $this->parameters)); if ($response instanceof Response) { return $response; } if (is_null($response) || is_string($response)) { return new Response($response); } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { return new JsonResponse($response); } throw new Exception('Unknown response type!'); }
/** * Add a new shortcode. * * @param $name * @param $callable * @param array $arguments */ public function add($name, $callable, $arguments = []) { add_shortcode($name, function ($attributes = [], $content = null) use($callable, $arguments) { if (!is_array($attributes)) { $attributes = []; } if (!empty($arguments)) { $attributes = $this->renameArguments($arguments, $attributes); } if (strpos($callable, '::') !== false) { list($api, $method) = explode('::', $callable); global ${$api}; if (${$api} === null) { throw new Exception("API '{$api}' not set!"); } $callable = ${$api}->get($method); if ($callable === null) { throw new Exception("Method '{$method}' not set!"); } } $response = $this->app->call($callable, array_merge(['_attributes' => $attributes, '_content' => $content], $attributes)); if ($response instanceof RedirectResponse) { $response->flash(); } if ($response instanceof Response) { status_header($response->getStatusCode()); foreach ($response->getHeaders() as $key => $value) { @header($key . ': ' . $value); } return $response->getBody(); } if (is_null($response) || is_string($response)) { return $response; } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { return (new JsonResponse($response))->getBody(); } throw new Exception('Unknown response type!'); }); }
/** * Add a new shortcode. * * @param $name * @param $callable * @param array $arguments */ public function add($name, $callable, $arguments = []) { add_shortcode($name, function ($attributes = [], $content = null) use($callable, $arguments) { if (!is_array($attributes)) { $attributes = []; } if (!empty($arguments)) { $attributes = $this->renameArguments($arguments, $attributes); } if (strpos($callable, '::') !== false) { list($api, $method) = explode('::', $callable); global ${$api}; if (${$api} === null) { throw new Exception("API '{$api}' not set!"); } $callable = ${$api}->get($method); if ($callable === null) { throw new Exception("Method '{$method}' not set!"); } } return $this->app->call($callable, array_merge(['_attributes' => $attributes, '_content' => $content], $attributes)); }); }
/** * Calls the panel's callable. * * @param $callable * @return void */ protected function call($callable) { $response = $this->app->call($callable, ['app' => $this->app]); if ($response instanceof RedirectResponse) { $response->flash(); } if ($response instanceof Response) { status_header($response->getStatusCode()); foreach ($response->getHeaders() as $key => $value) { @header($key . ': ' . $value); } echo $response->getBody(); return; } if (is_null($response) || is_string($response)) { echo $response; return; } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { echo (new JsonResponse($response))->getBody(); return; } throw new Exception('Unknown response type!'); }