Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2.1 KB

options.md

File metadata and controls

80 lines (59 loc) · 2.1 KB

Route Loader Options

The RouteLoader takes 2 arguments:

  • The path or paths that contain the routes
  • A RouteLoaderOptions object that contains options
use Dbout\WpRestApi\RouteLoader;
use Dbout\WpRestApi\RouteLoaderOptions;

$options = new RouteLoaderOptions(...);
$loader = new RouteLoader(
    __DIR__ . '/src/Api/Routes',
    $options
);

$loader->register();

Cache

To work, the module will automatically search for all classes that contain routes, this process can take time if there are a lot of files since the files will be read in order to extract the information on the routes.

In order to avoid this processing at each process, it can be interesting to activate the cache especially on the production environment. By default, the module does not use any cache system, so you can use any cache system that implements the PSR-6 standard.

Here is an example with Symfony cache :

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Dbout\WpRestApi\RouteLoaderOptions;

$cache = new FilesystemAdapter(
    directory: 'your_cache_path'
);

$options = new RouteLoaderOptions(
    cache: $cache,
);

By default, the wp_autoloader_routes cache key is used, you can change the key by passing the cacheKey option.

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Dbout\WpRestApi\RouteLoaderOptions;

$cache = new FilesystemAdapter(
    directory: 'your_cache_path'
);

$options = new RouteLoaderOptions(
    cache: $cache,
    cacheKey: 'my_cache_key'
);

Debug

In development mode, it may be interesting to enable debug mode so that errors (500) are visible. When mode is enabled, the full exception is returned in the response.

use Dbout\WpRestApi\RouteLoaderOptions;

$options = new RouteLoaderOptions(
    debug: true,
);
{
  "error": {
    "code": "fatal-error",
    "message": "The exception message.",
    "data": {
      "exception": "The exception full trace"
    }
  }
}