Using the API
Besides the usage via the modified debug exception handler and the console commands, there is also a public PHP API. It can be used to solve problems directly in PHP code.
- class Solver
-
- Fully qualified name
-
\Elias
Haeussler\ Typo3Solver\ Problem Solving\ Solver
Core component to solve problems by a given exception.
- solve ( $exception)
-
Provide solution for given exception and format it according to the configured formatter. If a cached solution exists, the provider does not request a new solution.
Note
This method is basically described at Default solution.
- param Throwable $exception
-
Exception for which a solution is to provide.
- returntype
-
string
|null
- solveStreamed ( $exception)
-
Provide formatted solution for given exception, but use a solution stream for each solution delta. This basically mimics the behavior of ChatGPT, where the solution is provided asynchronous.
Note
This method is basically described at Streamed solution.
- param Throwable $exception
-
Exception for which a solution is to provide.
- returntype
-
Traversable<string>
Example
Create a new \EliasHaeussler\Typo3Solver\ProblemSolving\Solver:
use EliasHaeussler\Typo3Solver;
use TYPO3\CMS\Core;
$configuration = Core\Utility\GeneralUtility::makeInstance(
Typo3Solver\Configuration\Configuration::class,
);
// Use any supported formatter and provider
$formatter = Core\Utility\GeneralUtility::makeInstance(
Typo3Solver\Formatter\WebFormatter::class,
);
$solutionProvider = Core\Utility\GeneralUtility::makeInstance(
Typo3Solver\ProblemSolving\Solution\Provider\OpenAISolutionProvider::class,
);
$solver = new Typo3Solver\ProblemSolving\Solver(
$configuration,
$formatter,
$solutionProvider,
);
Solve synchronously:
$formattedSolution = $solver->solve($exception);
Solve asynchronously:
foreach ($solver->solveStreamed($exception) as $solutionDelta) {
echo $solutionDelta;
}