Skip to content

Commit b00d715

Browse files
committed
Added Symfony quickstart CI job and draft markdown.
1 parent 1a7028f commit b00d715

File tree

5 files changed

+187
-6
lines changed

5 files changed

+187
-6
lines changed

.gitattributes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/.* export-ignore
2-
/docs export-ignore
3-
/test export-ignore
4-
/README.md export-ignore
1+
/.* export-ignore
2+
/docs export-ignore
3+
/test export-ignore
4+
/CHANGELOG.md export-ignore
5+
/README.md export-ignore
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Symfony quickstart
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: 0 6 * * *
9+
10+
defaults:
11+
run:
12+
working-directory: Symfony quickstart
13+
14+
jobs:
15+
Symfony-quickstart:
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
php: 8.1
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- name: Setup PHP ${{ env.php }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ env.php }}
28+
29+
- name: Create working directory
30+
run: mkdir --verbose "$GITHUB_WORKFLOW"
31+
working-directory:
32+
33+
- name: Cache dependencies
34+
id: composer-cache
35+
uses: actions/cache@v3
36+
with:
37+
path: ${{ github.workflow }}/vendor
38+
key: php-quickstart-symfony-${{ env.php }}
39+
40+
- name: Create Symfony project
41+
run: composer create-project symfony/skeleton . ^5
42+
43+
- name: Configure minimum stability for Amp v3.
44+
run: |
45+
composer config minimum-stability beta
46+
composer config prefer-stable true
47+
48+
- name: Require Steam
49+
run: composer require --with-dependencies provider/steam
50+
51+
- name: Require Doctrine annotations
52+
run: composer require doctrine/annotations
53+
54+
- name: Add Porter services
55+
run: |
56+
cat <<'.' >>config/services.yaml
57+
ScriptFUSION\Porter\Porter:
58+
arguments:
59+
- '@providers'
60+
61+
providers:
62+
class: Symfony\Component\DependencyInjection\ServiceLocator
63+
arguments:
64+
-
65+
- '@ScriptFUSION\Porter\Provider\Steam\SteamProvider'
66+
67+
ScriptFUSION\Porter\Provider\Steam\SteamProvider: ~
68+
.
69+
70+
- name: Add AppListAction
71+
run: |
72+
cat <<'.' | >src/Controller/AppListAction.php sed 's/ *//'
73+
<?php
74+
declare(strict_types=1);
75+
76+
namespace App\Controller;
77+
78+
use ScriptFUSION\Porter\Porter;
79+
use ScriptFUSION\Porter\Provider\Steam\Resource\GetAppList;
80+
use ScriptFUSION\Porter\Specification\ImportSpecification;
81+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
82+
use Symfony\Component\HttpFoundation\Response;
83+
use Symfony\Component\HttpFoundation\StreamedResponse;
84+
use Symfony\Component\Routing\Annotation\Route;
85+
86+
final class AppListAction extends AbstractController
87+
{
88+
#[Route('/')]
89+
public function __invoke(Porter $porter): Response
90+
{
91+
return new StreamedResponse(
92+
function () use ($porter): void {
93+
foreach ($porter->import(new ImportSpecification(new GetAppList())) as $app) {
94+
echo "$app[appid]\n";
95+
}
96+
},
97+
Response::HTTP_OK,
98+
['content-type' => 'text/plain'],
99+
);
100+
}
101+
}
102+
.
103+
104+
- name: Start web server
105+
run: sudo php -S localhost:80 public/index.php &
106+
107+
- name: Download home page
108+
run: curl localhost | tee out
109+
110+
- name: Test output contains over 150k lines
111+
run: |
112+
echo Lines: ${lines=$(wc --lines <out)}
113+
((lines > 150000))

.github/workflows/Quickstart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
- name: Test output contains between 30-40 lines
7171
run: |
7272
echo Lines: ${lines=$(wc --lines <out)}
73-
((lines > 30 && lines < 40))
73+
((lines >= 30 && lines <= 40))

docs/Quickstart Symfony.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Porter Quick Start Guide for Symfony
2+
====================================
3+
4+
This quick start guide will walk through integrating Porter into a new Symfony project 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.
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.
7+
8+
```sh
9+
composer require provider/european-central-bank
10+
```
11+
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.
13+
14+
```sh
15+
composer require joomla/di
16+
```
17+
18+
Create a new container and register an instance of `EuropeanCentralBankProvider` with it. Pass the container to a new Porter instance. Don't forget to include the autoloader!
19+
20+
```php
21+
use Joomla\DI\Container;
22+
use ScriptFUSION\Porter\Porter;
23+
use ScriptFUSION\Porter\Provider\EuropeanCentralBank\Provider\EuropeanCentralBankProvider;
24+
25+
require 'vendor/autoload.php';
26+
27+
$container = new Container;
28+
$container->set(EuropeanCentralBankProvider::class, new EuropeanCentralBankProvider);
29+
30+
$porter = new Porter($container);
31+
```
32+
33+
We're now ready to import any of the ECB's resources. Let's import the latest daily foreign exchange rates provided by `DailyForexRates`. Porter's `import()` method requires a `Import` that accepts the resource we want to import.
34+
35+
```php
36+
use ScriptFUSION\Porter\Import\Import;
37+
use ScriptFUSION\Porter\Provider\EuropeanCentralBank\Provider\Resource\DailyForexRates;
38+
39+
$rates = $porter->import(new Import(new DailyForexRates));
40+
```
41+
42+
Porter returns an iterator, so we can now loop over the rates and print them out.
43+
44+
```php
45+
foreach ($rates as $rate) {
46+
echo "$rate[currency]: $rate[rate]\n";
47+
}
48+
```
49+
50+
This outputs something similar to the following, with today's current rates.
51+
52+
>USD: 1.2304
53+
JPY: 131.66
54+
BGN: 1.9558
55+
CZK: 25.357
56+
DKK: 7.4469
57+
...
58+
59+
Since these rates come from the European Central Bank, they're relative to the Euro (EUR), which is assumed to always be *1*. We can use this information to write a currency converter that's always up-to-date with the latest exchange rate information.
60+
61+
This just scratches the surface of Porter without going into any details. Explore the [rest of the manual][Readme] at your leisure to gain a fuller understanding of the features at your disposal.
62+
63+
[Back to main readme][Readme]
64+
65+
66+
[Readme]: https://github.com/ScriptFUSION/Porter/blob/master/README.md
67+
[ECB provider]: https://github.com/Provider/European-Central-Bank

docs/Quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 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.
55

66
Let's start with the [European Central Bank][ECB provider] (ECB) provider by including it in our `composer.json` with the following command.
77

0 commit comments

Comments
 (0)