You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Quickstart Symfony.md
+21-9Lines changed: 21 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,24 @@
1
1
Porter Quick Start Guide for Symfony
2
2
====================================
3
3
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.
5
7
6
8
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.
7
9
8
10
```sh
9
11
composer create-project symfony/skeleton . ^5
10
12
```
11
13
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.
13
17
> ```sh
14
18
> composer config minimum-stability beta
15
19
> composer config prefer-stable true
16
20
>```
17
21
18
-
Let's start with the [Steam provider][] for Porter by including it in our `composer.json` with the following command.
Now the provider is installed along with all its dependencies, including Amp and Porter herself.
27
29
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.
29
35
30
36
```php
31
37
<?php
32
38
declare(strict_types=1);
33
39
34
-
namespace App\Action;
40
+
namespace App\Controller;
35
41
36
42
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
37
43
@@ -124,8 +130,12 @@ Finally, since `SteamProvider` is third-party code, Symfony requires us to expli
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!
128
136
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`).
@@ -140,7 +150,7 @@ Refreshing our browser now should recompile the Symfony DI container and show us
140
150
+ },
141
151
```
142
152
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:
144
154
145
155
```php
146
156
<?php
@@ -184,16 +194,18 @@ This should output a long list of numbers, one on each line, in the browser. For
184
194
185
195
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.
186
196
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.
Copy file name to clipboardExpand all lines: docs/Quickstart.md
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,23 @@
1
1
Porter Quick Start Guide
2
2
========================
3
3
4
-
This quick start guide will walk through getting up and running with Porter from scratchand 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.
5
5
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.
7
15
8
16
```sh
9
17
composer require provider/european-central-bank
10
18
```
11
19
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 containeris 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.
13
21
14
22
```sh
15
23
composer require joomla/di
@@ -63,5 +71,9 @@ This just scratches the surface of Porter without going into any details. Explor
0 commit comments