Skip to content

Commit

Permalink
Introduce Settings concept (#103)
Browse files Browse the repository at this point in the history
* Introduce Settings

* huge update for settings support

* add content for testing website build

* update docs

* update gettings tarted docs

* potential final draft for getting started

* move settins interfaces around to be more logical, start settings docs

* flesh out warning for synch settings loader

* a little more work on fleshing out settings docs

* implement settings loader factory, composer update

* attempt to fix problem with env var values

* fix coding style errors

* fix code lint violations
  • Loading branch information
cspray authored Mar 28, 2021
1 parent 27d4654 commit 4a1ef93
Show file tree
Hide file tree
Showing 63 changed files with 2,962 additions and 1,616 deletions.
40 changes: 25 additions & 15 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'PHP Unit Testing & Code Lint'
name: 'Unit Testing & Code Lint'

on:
push:
Expand All @@ -7,21 +7,31 @@ on:
branches: [ main ]

jobs:
build:
build-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: composer run-script test

- name: Run code sniffer
run: composer run-script code-lint
- uses: actions/checkout@v2
- name: Composer 7
uses: php-actions/composer@v5
with:
php_version: 7
- name: PHP 7 tests
uses: php-actions/phpunit@v2
with:
version: 8
php_version: 7

- name: Composer 8
uses: php-actions/composer@v5
with:
php_version: 8
- name: PHP 8 tests
uses: php-actions/phpunit@v2
with:
version: 8
php_version: 8

- name: Run code sniffer
run: composer run code-lint
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.2.0 - 2020-??-??

#### Added

- An `ApplicationEnvironment` enum that determines the environment of the host machine running your Labrador app.
- An `Environment` interface and implementations that encapsulates access to the `ApplicationEnvironment` and
environment variables that exist on the host machine.
- A `Settings` interface and implementation that allows for providing configuration details for both Labrador and
your app.
- A `SettingsLoader` and `SettingsStorageHandler` interface and implementations that allow fine-grained control on how
the `Settings` for your application are generated. Comes out of the box with support for both PHP and JSON settings on
the local filesystem. You should read over /docs/tutorials/02-application-settings.md
- An `ApplicationObjectGraph` interface that will facilitate more robust bootstrapping code in the future. An instance,
the `CoreApplicationObjectGraph`, takes over the responsibilities of the `DependencyGraph` while also providing in the
injector an `Environment` instance and, an optional, `Settings` instance.

#### Deprecated

- The `DependecyGraph` is deprecated and will be removed in the next major release. Users should transition to use the
`CoreApplicationObjectGraph` instead.

## 3.1.0 - 2020-08-02

#### Added
Expand Down
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# Labrador core
# Labrador Core

[![PHP Unit Testing & Code Lint](https://github.com/labrador-kennel/core/workflows/PHP%20Unit%20Testing%20&%20Code%20Lint/badge.svg)](https://github.com/labrador-kennel/core/actions?query=workflow%3A%22PHP+Unit+Testing+%26+Code+Lint%22)
[![GitHub release](https://img.shields.io/github/release/labrador-kennel/core.svg?style=flat-square)](https://github.com/cspray/labrador/releases/latest)
[![GitHub license](https://img.shields.io/github/license/labrador-kennel/core.svg?style=flat-square)](http://opensource.org/licenses/MIT)

Provides the core concepts for building applications on top of Labrador. Provides the default third-party dependencies
that are required as well as important foundational concepts.

- **IoC Container** A recursive, autowiring Inversion of Control container provided through [Auryn].
- **Event** Trigger semantic, data-rich events taking full advantage of Amp's async nature with [async-event].
- **Plugin** A series of simple to implement interfaces that allow you to easily hook into Labrador execution and provide reusable modules!
- **Application** An interface that you implement, or extend from `AbstractApplication`, to encapsulate your app's business logic.
- **Engine** An interface that is responsible for running your Application on the Loop and tying everything together.
An opinionated, asynchronous micro-framework written on top of [amphp](https://amphp.org). Built using SOLID principles,
unit testing, and a modular ecosystem Labrador aims to be a production-ready framework for creating asynchronous PHP
applications. Labrador Core serves as the foundation for this framework and provides important key concepts for building
apps with Labrador.

## Installation

[Composer] is the only supported method for installing Labrador packages.
[Composer](https://getcomposer.org) is the only supported method for installing Labrador packages.

```
composer require cspray/labrador
Expand All @@ -24,8 +20,8 @@ composer require cspray/labrador
## Quick Start

If you'd rather get started quickly without having to read a bunch of documentation the code below demonstrates how to
quickly get an `Application` implemented and running. Otherwise, we recommend checking out the Documentation section
below for more information.
quickly get an `Application` implemented and running. Otherwise, we recommend checking out the Documentation for more
detailed information, and a complete guide to getting started.

```php
<?php
Expand All @@ -35,36 +31,50 @@ below for more information.
require_once __DIR__ . '/vendor/autoload.php';

use Cspray\Labrador\AbstractApplication;
use Cspray\Labrador\DependencyGraph;
use Cspray\Labrador\EnvironmentType;
use Cspray\Labrador\CoreApplicationObjectGraph;
use Cspray\Labrador\Engine;
use Cspray\Labrador\StandardEnvironment;
use Amp\Promise;
use Amp\Delayed;
use Amp\Log\StreamHandler;
use Auryn\Injector;
use Monolog\Logger;
use function Amp\call;
use function Amp\ByteStream\getStdout;

class HelloWorldApplicationObjectGraph extends CoreApplicationObjectGraph {

public function wireObjectGraph() : Injector {
$injector = parent::wireObjectGraph();

// wire up your app's dependencies

return $injector;
}

}

class HelloWorldApplication extends AbstractApplication {

protected function doStart() : Promise {
return call(function() {
yield new Delayed(1); // just to show that we are running on the Loop
yield new Delayed(500); // just to show that we are running on the Loop
$this->logger->info('Hello Labrador!');
});
}

}

$logger = new Logger('labrador.hello-world');
$logger->pushHandler(new StreamHandler(getStdout()));
$environment = new StandardEnvironment(EnvironmentType::Development());
$logger = new Logger('labrador.hello-world', [new StreamHandler(getStdout())]);

$injector = (new DependencyGraph($logger))->wireObjectGraph();
$injector = (new HelloWorldApplicationObjectGraph($environment, $logger))->wireObjectGraph();

$app = $injector->make(HelloWorldApplication::class);
$engine = $injector->make(Engine::class);

$engine->run($app);
?>
```

## Documentation
Expand All @@ -75,7 +85,3 @@ documentation online at [https://labrador-kennel.io/docs/core](https://labrador-
## Governance

All Labrador packages adhere to the rules laid out in the [Labrador Governance repo](https://github.com/labrador-kennel/governance)

[Auryn]: https://github.com/rdlowrey/Auryn
[async-event]: https://github.com/labrador-kennel/async-event
[Composer]: https://getcomposer.org
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
],
"scripts": {
"code-lint": "vendor/bin/labrador-cs src/ test/",
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html ./build/coverage"
},
"require": {
"php": ">=7.2",
"php": "^7.2|^8.0",
"ext-json": "*",
"adbario/php-dot-notation": "^2.2",
"amphp/amp": "^2.4",
"amphp/log": "^1.1",
"cspray/labrador-async-event": "^2.2",
"cspray/labrador-exceptions": "^1.1",
"cspray/yape": "^3.0",
"cspray/labrador-async-event": "^2.3",
"cspray/labrador-exceptions": "^1.2",
"cspray/yape": "^3.1",
"monolog/monolog": "^2.0",
"rdlowrey/auryn": "^1.4"
},
"require-dev": {
"amphp/phpunit-util": "^1.2",
"cspray/labrador-coding-standard": "^0.2",
"cspray/yape-cli": "^1.0",
"phpunit/phpunit": "~9.1"
},
"autoload": {
Expand Down
Loading

0 comments on commit 4a1ef93

Please sign in to comment.