Skip to content

Commit 838c112

Browse files
committed
Copy edit Symfony quickstart guide.
Added additional links to Quickstart guide.
1 parent 8c81872 commit 838c112

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

docs/Quickstart Symfony.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
Porter Quick Start Guide for Symfony
22
====================================
33

4-
This quick start guide will walk through integrating Porter into a new Symfony project from scratch and assumes we already have a PHP 8.1 environment set up with Composer. This guide is based on a real-world use-case, used in production on [Steam 250][]. If we want to integrate Porter into an existing Symfony project, simply skip the Composer steps. If you encounter any other errors or get stuck, don't hesitate to file an issue.
4+
This quick start guide will walk through integrating Porter into a new Symfony project from scratch and assumes we already have a PHP 8.1 environment set up with Composer. This guide is based on a real-world use-case, used in production on [Steam 250][]. If you want to integrate Porter into an existing Symfony project, skip all steps except modifying `services.yaml`.
5+
6+
This steps in this guide are automatically verified by a nightly [CI build][] to ensure their correctness. However, if you encounter any errors or get stuck, don't hesitate to file an issue.
57

68
Let's start by creating a new Symfony 5 project in an empty directory using the following command. Ensure the current working directory is set to the empty project directory.
79

810
```sh
911
composer create-project symfony/skeleton . ^5
1012
```
1113

12-
>Note: The Steam provider (used below) requires [Amp v3][], which is currently in beta, so we need to allow beta dependencies temporarily. This can be enabled with the following command.
14+
Let's start with the [Steam provider][] for Porter by including it in our `composer.json` with the following command.
15+
16+
>Note: The Steam provider requires [Amp v3][], which is currently in beta, so we need to allow beta dependencies temporarily. This can be enabled with the following command.
1317
> ```sh
1418
> composer config minimum-stability beta
1519
> composer config prefer-stable true
1620
> ```
1721
18-
Let's start with the [Steam provider][] for Porter by including it in our `composer.json` with the following command.
19-
2022
```sh
2123
composer require --with-dependencies provider/steam
2224
```
@@ -25,13 +27,17 @@ composer require --with-dependencies provider/steam
2527
2628
Now the provider is installed along with all its dependencies, including Amp and Porter herself.
2729

28-
In this simple exercise, we will use the Steam provider to display a list of all the app IDs for every app available on [Steam][]. We're going to start coding now, so let's fire up our favourite editor. Start by creating a new `AppListAction` in our existing `src/Controller` directory. We're following the [ADR][] pattern rather than MVC, so we could rename the *Controller* directory to *Action*, too, but we will refrain for now, to keep things simple. Actions only handle a single route, using the `__invoke` method, so let's add that, too.
30+
In this simple exercise, we will use the [Steam provider][] to display a list of all the app IDs for every app available on [Steam][]. We're going to start coding now, so let's fire up our favourite editor. Start by creating a new `AppListAction` in our existing `src/Controller` directory.
31+
32+
>Note: We're following the [ADR][] pattern rather than MVC, so we should rename the *Controller* directory to *Action*, too, but to keep things simple we will refrain for now.
33+
34+
Actions only handle a single route, using the `__invoke` method, so let's add that, too.
2935

3036
```php
3137
<?php
3238
declare(strict_types=1);
3339

34-
namespace App\Action;
40+
namespace App\Controller;
3541

3642
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
3743

@@ -124,8 +130,12 @@ Finally, since `SteamProvider` is third-party code, Symfony requires us to expli
124130
ScriptFUSION\Porter\Provider\Steam\SteamProvider: ~
125131
```
126132

133+
>Note: The tilde is optional and can be omitted.
134+
127135
Refreshing our browser now should recompile the Symfony DI container and show us the same message as before (without errors). Porter is now injected into our action, ready to use!
128136

137+
Let's replace the previous `StreamedResponse` closure with a new implementation that uses Porter to import data from the `GetAppList` resource (a resource belonging to `SteamProvider`).
138+
129139
```diff
130140
use ScriptFUSION\Porter\Porter;
131141
+use ScriptFUSION\Porter\Provider\Steam\Resource\GetAppList;
@@ -140,7 +150,7 @@ Refreshing our browser now should recompile the Symfony DI container and show us
140150
+ },
141151
```
142152

143-
We iterate over each result from importing `GetAppList` and emit it using `echo`, appending a new line. Viewing the results in our browser shows us lots of numbers (the ID of each Steam app) but it does not respect the new line character (`\n`) because it renders as HTML by default. Let's fix that by specifying the correct mime type. Below is the completed code, including the new `content-type` header:
153+
We iterate over each result from `GetAppList` and emit it using `echo`, appending a new line to each. Viewing the results in our browser shows us lots of numbers (the ID of each Steam app) but it does not respect the new line character (`\n`) because it renders as HTML by default. Let's fix that by specifying the correct mime type. Below is the complete code, including the new `content-type` header:
144154

145155
```php
146156
<?php
@@ -184,16 +194,18 @@ This should output a long list of numbers, one on each line, in the browser. For
184194

185195
We now have a Porter service defined that can be injected into as many services or actions as we wish. We can add as many [providers] to the `providers` service locator as we want, without any performance impact, since each service is lazy-loaded when required.
186196

187-
This just scratches the surface of Porter without going into any details. Explore the [rest of the manual][Readme] to gain a fuller understanding of the features at your disposal.
197+
This just scratches the surface of Porter without going into any details. Explore the [rest of the manual][Readme] to gain a fuller understanding of the features at your disposal. For another worked example, check out the framework-less [quickstart guide][], too.
188198

189199
⮪ [Back to main Readme][Readme]
190200

191201

192-
[Readme]: https://github.com/ScriptFUSION/Porter/blob/master/README.md#quick-start
202+
[Readme]: ../README.md#quick-start
193203
[Steam provider]: https://github.com/Provider/Steam
194204
[Steam 250]: https://steam250.com
195205
[Steam]: https://store.steampowered.com
196206
[ADR]: https://github.com/pmjones/adr
197207
[Amp v3]: https://v3.amphp.org
198208
[Defining a Service Locator]: https://symfony.com/doc/current/service_container/service_subscribers_locators.html#defining-a-service-locator
199209
[Providers]: https://github.com/provider
210+
[CI build]: https://github.com/ScriptFUSION/Porter/actions/workflows/Quickstart%20Symfony.yaml
211+
[Quickstart guide]: Quickstart.md

docs/Quickstart.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
Porter Quick Start Guide
22
========================
33

4-
This quick start guide will walk through getting up and running with Porter from scratch and assumes you already have a PHP environment set up with Composer. Let's start by initializing our Composer file by running `composer init` in our project's root directory and accepting the defaults. We can skip defining dependencies interactively because we'll issue separate commands in a moment.
4+
This quick start guide will walk through getting up and running with Porter from scratch, without a framework, and assumes we already have a PHP environment set up with Composer. If you use Symfony, check out the [Symfony quickstart guide][], too.
55

6-
Let's start with the [European Central Bank][ECB provider] (ECB) provider by including it in our `composer.json` with the following command.
6+
This steps in this guide are automatically verified by a nightly [CI build][] to ensure their correctness. However, if you encounter any errors or get stuck, don't hesitate to file an issue.
7+
8+
Let's start by initializing our Composer file by running the following command in our project's root directory and accepting the defaults. We can skip defining dependencies interactively because we'll issue separate commands in a moment.
9+
10+
```sh
11+
composer init
12+
```
13+
14+
For this demo we'll use the [European Central Bank][ECB provider] (ECB) provider by including it in our `composer.json` with the following command.
715

816
```sh
917
composer require provider/european-central-bank
1018
```
1119

12-
We now have the provider installed along with all its dependencies, including Porter herself. We want to create a `new Porter` instance now, but we need to pass a `ContainerInterface` to her constructor. Any PSR-11 container is valid, but let's use Joomla DI for now.
20+
We now have the provider installed along with all its dependencies, including Porter herself. We want to create a `new Porter` instance now, but we need to pass a `ContainerInterface` to her constructor. [Any PSR-11 container][PSR-11 search] is valid, but let's use [Joomla DI][] for now.
1321

1422
```sh
1523
composer require joomla/di
@@ -63,5 +71,9 @@ This just scratches the surface of Porter without going into any details. Explor
6371
[Back to main Readme][Readme]
6472

6573

66-
[Readme]: https://github.com/ScriptFUSION/Porter/blob/master/README.md#quick-start
74+
[Readme]: ../README.md#quick-start
6775
[ECB provider]: https://github.com/Provider/European-Central-Bank
76+
[CI build]: https://github.com/ScriptFUSION/Porter/actions/workflows/Quickstart.yaml
77+
[PSR-11 search]: https://packagist.org/explore/?type=library&tags=psr-11
78+
[Joomla DI]: https://github.com/joomla-framework/di
79+
[Symfony quickstart guide]: Quickstart%20Symfony.md

0 commit comments

Comments
 (0)