1. Go to this page and download the library: Download distantmagic/resonance library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
#[RespondsToPromptSubject(
action: 'adopt',
subject: 'cat',
)]
#[Singleton(collection: SingletonCollection::PromptSubjectResponder)]
readonly class CatAdopt implements PromptSubjectResponderInterface
{
public function respondToPromptSubject(PromptSubjectRequest $request, PromptSubjectResponse $response): void
{
// Pipes message through WebSocket...
$response->write("Here you go:\n\n");
$response->write(" |\_._/|\n");
$response->write(" | o o |\n");
$response->write(" ( T )\n");
$response->write(" .^`-^-`^.\n");
$response->write(" `. ; .`\n");
$response->write(" | | | | |\n");
$response->write(" ((_((|))_))\n");
$response->end();
}
}
#[RespondsToWebSocketJsonRPC(JsonRPCMethod::Echo)]
#[Singleton(collection: SingletonCollection::WebSocketJsonRPCResponder)]
final readonly class EchoResponder extends WebSocketJsonJsonRPCResponder
{
public function getConstraint(): Constraint
{
return new StringConstraint();
}
public function onRequest(
WebSocketAuthResolution $webSocketAuthResolution,
WebSocketConnection $webSocketConnection,
RPCRequest $rpcRequest,
): void {
$webSocketConnection->push(new JsonRPCResponse(
$rpcRequest,
$rpcRequest->payload,
));
}
}
#[RespondsToHttp(
method: RequestMethod::GET,
pattern: '/',
)]
function Homepage(ServerRequestInterface $request, ResponseInterface $response): TwigTemplate
{
return new TwigTemplate('website/homepage.twig');
}
#[ListensTo(HttpServerStarted::class)]
#[Singleton(collection: SingletonCollection::EventListener)]
final readonly class InitializeErrorReporting extends EventListener
{
public function handle(object $event): void
{
// ...
}
}
#[GraphQLRootField(
name: 'blogPosts',
type: GraphQLRootFieldType::Query,
)]
#[Singleton(collection: SingletonCollection::GraphQLRootField)]
final readonly class Blog implements GraphQLFieldableInterface
{
public function __construct(
private DatabaseConnectionPoolRepository $connectionPool,
private BlogPostType $blogPostType,
) {}
public function resolve(): GraphQLReusableDatabaseQueryInterface
{
return new SelectBlogPosts($this->connectionPool);
}
public function toGraphQLField(): array
{
return [
'type' => new ListOfType($this->blogPostType),
'resolve' => $this->resolve(...),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.