Skip to content

Commit 6f5e788

Browse files
committed
Move code example to react component
1 parent 56e0eb8 commit 6f5e788

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

docs/general/quick-start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ $server->addWorker(
3434
new WorkerProcess(
3535
name: 'Worker',
3636
count: 1,
37-
onStart: function (WorkerProcess $worker): void {
37+
onStart: static function (WorkerProcess $worker): void {
3838
$worker->logger->notice("Hello from worker!");
3939
}
4040
),
4141
new HttpServerProcess(
4242
name: 'Web Server',
4343
count: 2,
4444
listen: '0.0.0.0:8080',
45-
onRequest: function (Request $request, HttpServerProcess $worker): Response {
45+
onRequest: static function (Request $request, HttpServerProcess $worker): Response {
4646
return match ($request->getUri()->getPath()) {
4747
'/' => new Response(body: 'Hello world'),
4848
'/ping' => new Response(body: 'pong'),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const ExampleCode = `
2+
use Amp\\Http\\Server\\HttpErrorException;
3+
use Amp\\Http\\Server\\Request;
4+
use Amp\\Http\\Server\\Response;
5+
use PHPStreamServer\\Core\\Server;
6+
use PHPStreamServer\\Plugin\\HttpServer\\HttpServerPlugin;
7+
use PHPStreamServer\\Plugin\\HttpServer\\Worker\\HttpServerProcess;
8+
9+
$server = new Server();
10+
11+
$server->addPlugin(
12+
new HttpServerPlugin(), // Register the HTTP server plugin
13+
);
14+
15+
$server->addWorker(
16+
new HttpServerProcess(
17+
listen: '0.0.0.0:8080', // Address to listen on
18+
count: 2, // Number of worker processes
19+
onRequest: static function (Request $request): Response {
20+
return match ($request->getUri()->getPath()) {
21+
'/' => new Response(body: 'Hello world'),
22+
default => throw new HttpErrorException(404),
23+
};
24+
}
25+
),
26+
);
27+
28+
exit($server->run());
29+
`;
30+
31+
export default ExampleCode;

src/components/LandingPage/index.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import LogoImg from '@site/static/img/phpss-banner.svg';
77
import GithubImg from '@site/static/img/github.svg';
88
import CodeBlock from '@theme/CodeBlock';
99
import Navbar from '@theme/Navbar';
10+
import CodeExample from './CodeExample';
1011

1112
import Icon1 from '@site/static/icons/icon1.svg';
1213
import Icon2 from '@site/static/icons/icon2.svg';
@@ -96,36 +97,7 @@ const Index = () => {
9697
<Link className={styles.button} to="/docs/general/">View Full Documentation</Link>
9798
</div>
9899
<div className="flex-1">
99-
<CodeBlock language="php" title="server.php">
100-
{`use Amp\\Http\\Server\\HttpErrorException;
101-
use Amp\\Http\\Server\\Request;
102-
use Amp\\Http\\Server\\Response;
103-
use PHPStreamServer\\Core\\Server;
104-
use PHPStreamServer\\Plugin\\HttpServer\\HttpServerPlugin;
105-
use PHPStreamServer\\Plugin\\HttpServer\\Worker\\HttpServerProcess;
106-
107-
$server = new Server();
108-
109-
$server->addPlugin(
110-
new HttpServerPlugin(), // Register the HTTP server plugin
111-
);
112-
113-
$server->addWorker(
114-
new HttpServerProcess(
115-
listen: '0.0.0.0:8080', // Address to listen on
116-
count: 2, // Number of worker processes
117-
onRequest: function (Request $request): Response {
118-
return match ($request->getUri()->getPath()) {
119-
'/' => new Response(body: 'Hello world'),
120-
'/ping' => new Response(body: 'pong'),
121-
default => throw new HttpErrorException(404),
122-
};
123-
}
124-
),
125-
);
126-
127-
exit($server->run());`}
128-
</CodeBlock>
100+
<CodeBlock language="php" title="server.php">{CodeExample.trim()}</CodeBlock>
129101
</div>
130102
</div>
131103
</div>

0 commit comments

Comments
 (0)