Skip to content

Commit

Permalink
Added Symfony quickstart CI job and draft markdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Dec 2, 2022
1 parent 1a7028f commit b00d715
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.* export-ignore
/docs export-ignore
/test export-ignore
/README.md export-ignore
/.* export-ignore
/docs export-ignore
/test export-ignore
/CHANGELOG.md export-ignore
/README.md export-ignore
113 changes: 113 additions & 0 deletions .github/workflows/Quickstart Symfony.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Symfony quickstart

on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: 0 6 * * *

defaults:
run:
working-directory: Symfony quickstart

jobs:
Symfony-quickstart:
runs-on: ubuntu-latest

env:
php: 8.1

steps:
- uses: actions/checkout@v3

- name: Setup PHP ${{ env.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php }}

- name: Create working directory
run: mkdir --verbose "$GITHUB_WORKFLOW"
working-directory:

- name: Cache dependencies
id: composer-cache
uses: actions/cache@v3
with:
path: ${{ github.workflow }}/vendor
key: php-quickstart-symfony-${{ env.php }}

- name: Create Symfony project
run: composer create-project symfony/skeleton . ^5

- name: Configure minimum stability for Amp v3.
run: |
composer config minimum-stability beta
composer config prefer-stable true
- name: Require Steam
run: composer require --with-dependencies provider/steam

- name: Require Doctrine annotations
run: composer require doctrine/annotations

- name: Add Porter services
run: |
cat <<'.' >>config/services.yaml
ScriptFUSION\Porter\Porter:
arguments:
- '@providers'
providers:
class: Symfony\Component\DependencyInjection\ServiceLocator
arguments:
-
- '@ScriptFUSION\Porter\Provider\Steam\SteamProvider'
ScriptFUSION\Porter\Provider\Steam\SteamProvider: ~
.
- name: Add AppListAction
run: |
cat <<'.' | >src/Controller/AppListAction.php sed 's/ *//'
<?php
declare(strict_types=1);
namespace App\Controller;
use ScriptFUSION\Porter\Porter;
use ScriptFUSION\Porter\Provider\Steam\Resource\GetAppList;
use ScriptFUSION\Porter\Specification\ImportSpecification;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Annotation\Route;
final class AppListAction extends AbstractController
{
#[Route('/')]
public function __invoke(Porter $porter): Response
{
return new StreamedResponse(
function () use ($porter): void {
foreach ($porter->import(new ImportSpecification(new GetAppList())) as $app) {
echo "$app[appid]\n";
}
},
Response::HTTP_OK,
['content-type' => 'text/plain'],
);
}
}
.
- name: Start web server
run: sudo php -S localhost:80 public/index.php &

- name: Download home page
run: curl localhost | tee out

- name: Test output contains over 150k lines
run: |
echo Lines: ${lines=$(wc --lines <out)}
((lines > 150000))
2 changes: 1 addition & 1 deletion .github/workflows/Quickstart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
- name: Test output contains between 30-40 lines
run: |
echo Lines: ${lines=$(wc --lines <out)}
((lines > 30 && lines < 40))
((lines >= 30 && lines <= 40))
67 changes: 67 additions & 0 deletions docs/Quickstart Symfony.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Porter Quick Start Guide for Symfony
====================================

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.

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

```sh
composer require provider/european-central-bank
```

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.

```sh
composer require joomla/di
```

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!

```php
use Joomla\DI\Container;
use ScriptFUSION\Porter\Porter;
use ScriptFUSION\Porter\Provider\EuropeanCentralBank\Provider\EuropeanCentralBankProvider;

require 'vendor/autoload.php';

$container = new Container;
$container->set(EuropeanCentralBankProvider::class, new EuropeanCentralBankProvider);

$porter = new Porter($container);
```

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.

```php
use ScriptFUSION\Porter\Import\Import;
use ScriptFUSION\Porter\Provider\EuropeanCentralBank\Provider\Resource\DailyForexRates;

$rates = $porter->import(new Import(new DailyForexRates));
```

Porter returns an iterator, so we can now loop over the rates and print them out.

```php
foreach ($rates as $rate) {
echo "$rate[currency]: $rate[rate]\n";
}
```

This outputs something similar to the following, with today's current rates.

>USD: 1.2304
JPY: 131.66
BGN: 1.9558
CZK: 25.357
DKK: 7.4469
...

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.

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.

[Back to main readme][Readme]


[Readme]: https://github.com/ScriptFUSION/Porter/blob/master/README.md
[ECB provider]: https://github.com/Provider/European-Central-Bank
2 changes: 1 addition & 1 deletion docs/Quickstart.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Porter Quick Start Guide
========================

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.
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.

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

Expand Down

0 comments on commit b00d715

Please sign in to comment.