Debugging
Inphinit includes multiple resources for debugging, with quick access to code editors and external assistants (e.g., AI or search engines).
Developtment mode
In development mode, instead of an instance of Inphinit\App in the $app variable, you will have an instance of Inphinit\Debug\App. This instance does exactly the same thing as Inphinit\App, but it also validates all values in all methods of the class, throwing exceptions if any value is unexpected. If development mode is turned off, none of the methods will perform validations or throw errors, which will allow for much better performance when development mode is turned off, while if it is turned on, it will allow you to develop without making so many mistakes.
Debugging errors
In development mode, all errors, warnings and exceptions can be displayed directly in the browser, displaying the content of the problematic script and line (problematic HTML and XML files loaded by a Inphinit\Dom\Document instance, will also be displayed, more details DOM errors).
You need to execute the $debug->setErrorView($view) method in the system/dev.php and it is possible to customize the view. By default the view is already defined as 'debug.error' (from system/views/debug/error.php):
// Inject CSS for debug if necessary
$debug->setBeforeView('debug.style');
// Display errors
$debug->setErrorView('debug.error');
Errors will be displayed similar to this:
Debugging routes
In development mode, all created routes will be validated, in the action($methods, $path, $callback) method, the HTTP methods will be validated, allowing only methods ANY, DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT.
In the case of passing duplicate methods in an array, such as $app->action(['GET', 'GET'], '/foo', ...), an exception will also be thrown.
Other validations:
- Duplicate patterns
- Invalid patterns
- Invalid controllers
- Incorrect method visibility on controllers
- Not callable callbacks
- Invalid prefix namespaces defined using
setNamespace($prefix)method - Invalid prefix paths defined using
setPath($prefix)method
Integrating online assistants
You can also specify a custom URL containing the placeholder {error}, which will be replaced by the actual error message system/Configs/debug.php change key:
'assistant' => 'https://duckduckgo.com/?q={error}',
Or you can also use one of the shortcut values for popular assistants or search engines:
| Value | Description |
|---|---|
'assistant' => 'chatgpt' |
In the development environment, error messages will generate links to OpenAI ChatGPT |
'assistant' => 'claude' |
In the development environment, error messages will generate links to Anthropic Claude |
'assistant' => 'duck.ai' |
In the development environment, error messages will generate links to DuckDuckGo AI Chat |
'assistant' => 'duckduckgo' |
In the development environment, error messages will generate links to DuckDuckGo search |
'assistant' => 'google' |
In the development environment, error messages will generate links to Google Search |
'assistant' => 'google.ai' |
In the development environment, error messages will generate links to Google AI / Gemini |
'assistant' => 'perplexity' |
In the development environment, error messages will generate links to Perplexity AI |
'assistant' => 'https://foo.bar?q={error}' |
Using {error} you can assemble any URL you want, thus customizing the assistant or search engine you wish to use |
Integrating the text editor
Some code editors, such as Visual Studio Code, can integrate with web browsers through links. As a result, when you are in development mode, errors, exceptions, and even minor warnings displayed in the browser can include links that take you directly to the corresponding file and line in your editor. By default, new projects generate links for VS Code. This behavior can be changed by editing the system/configs/debug.php file and updating the following key:
'editor' => 'vscode',
Sublime Text
To integrate with SubliteText, change the key to:
'editor' => 'sublimetext',
Other editors
Other editors may have different link formats, so instead of a simple value, it's possible to create your own link, using {path} and {line} as a reference. Example:
'editor' => 'foo://bar/baz?path={path}&line={line}',
Displays defined methods, constants and classes
In development mode, a feature can be enabled to display, for each request, the classes, functions, and constants that were loaded through either autoloading or standard execution. This facilitates debugging and helps identify unnecessary executions. Add the following line to your system/dev.php file:
$debug->setDefinedView('debug.defined');
Displays performance
In development mode, a feature can be enabled to display, for each request, the memory consumption and processing time. This information is useful for finding ways to optimize the project. Add the following line to your system/dev.php file:
$debug->setPerformanceView('debug.performance');