Skip to content

Commit

Permalink
Implemented the services layer from Grizz-IT
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankruijter committed Mar 28, 2021
1 parent 8887fac commit 94b62b8
Show file tree
Hide file tree
Showing 41 changed files with 555 additions and 439 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/tests export-ignore
/examples export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
vendor/
composer.lock
var/
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: php
php:
- '7.3'
- '7.4'
- '8.0'

before_script:
- yes '' | pecl install yaml
- composer install

script:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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).

## 2.0.0 - 2021-03-28
### Changed
- Implemented the new service layer from Grizz-IT.

## 1.3.3 - 2020-10-25
### Fixed
- PHP warnings were thrown when `ext-yaml` was not installed.
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^7.3",
"php": "^8.0",
"ext-json": "*",
"grizz-it/cache": "^1.0",
"grizz-it/configuration": "^1.1",
"grizz-it/enum": "^1.0",
"grizz-it/translator": "^1.0",
"ulrack/json-schema": "^1.0",
"ulrack/services": "^3.0"
"grizz-it/cache": "^1.1",
"grizz-it/configuration": "^1.3",
"grizz-it/enum": "^1.1",
"grizz-it/json-schema": "^1.0",
"grizz-it/services": "^1.0",
"grizz-it/translator": "^1.2"
},
"authors": [
{
Expand Down Expand Up @@ -55,7 +55,7 @@
]
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5"
}
}
5 changes: 0 additions & 5 deletions configuration/configuration/parameters.configuration.json

This file was deleted.

5 changes: 0 additions & 5 deletions configuration/configuration/preferences.configuration.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

22 changes: 22 additions & 0 deletions configuration/schema/invocations.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "invocations.schema.json",
"type": ["object"],
"properties": {
"service": {
"type": "string",
"pattern": "^[\\.\\w-]+$"
},
"method": {
"type": "string"
},
"parameters": {
"type": "object"
},
"cache": {
"type": "boolean",
"default": true
}
},
"required": ["service", "method"]
}
5 changes: 0 additions & 5 deletions configuration/schema/parameters.schema.json

This file was deleted.

19 changes: 0 additions & 19 deletions configuration/schema/preferences.schema.json

This file was deleted.

8 changes: 8 additions & 0 deletions configuration/schema/services.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"abstract": {
"type": "boolean",
"default": false
},
"cache": {
"type": "boolean",
"default": true
}
},
"required": ["class"]
Expand All @@ -33,6 +37,10 @@
"abstract": {
"type": "boolean",
"default": false
},
"cache": {
"type": "boolean",
"default": true
}
},
"required": ["parent"]
Expand Down
18 changes: 18 additions & 0 deletions configuration/schema/tags.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "tags.schema.json",
"type": "object",
"properties": {
"trigger": {
"type": "string"
},
"service": {
"type": "string"
},
"sortOrder": {
"type": "integer",
"default": 1000
}
},
"required": ["service", "trigger"]
}
10 changes: 10 additions & 0 deletions configuration/schema/triggers.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "triggers.schema.json",
"type": ["object", "array"],
"properties": {
"service": {
"type": "string"
}
}
}

This file was deleted.

8 changes: 8 additions & 0 deletions configuration/services/core.services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"triggers": {
"core.service.compilers": {},
"core.service.validators": {},
"core.service.factories": {},
"core.service.hooks": {}
}
}
6 changes: 4 additions & 2 deletions docs/usage/create-an-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ example an environment variable is being emited to the user. To do this, first
follow the following guide to support autoloading configuration:
[GrizzIT Configuration - Adding a locator](https://github.com/grizz-it/configuration/blob/master/docs/usage/adding-a-locator.md).

When this is done, create the file `configuration/parameters/my-parameters.json`.
When this is done, create the file `configuration/services/my-services.json`.
The contents of the file for this example will be:
```json
{
"my-parameter": "${SHELL}"
"parameters": {
"my-parameter": "${parameters.SHELL}"
}
}
```

Expand Down
6 changes: 3 additions & 3 deletions src/Common/Manager/ServiceManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Ulrack\Kernel\Common\Manager;

use Ulrack\Services\Common\ServiceFactoryInterface;
use Ulrack\Services\Common\ServiceCompilerInterface;
use GrizzIt\Services\Common\Factory\ServiceFactoryInterface;
use Ulrack\Kernel\Common\InitializableKernelManagerInterface;
use GrizzIt\Services\Common\Compiler\ServiceCompilerInterface;

interface ServiceManagerInterface extends InitializableKernelManagerInterface
{
Expand All @@ -21,7 +21,7 @@ interface ServiceManagerInterface extends InitializableKernelManagerInterface
*
* @return void
*/
public function registerService(string $key, $service): void;
public function registerService(string $key, mixed $service): void;

/**
* Retrieves the service compiler.
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Manager/ValidationManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Ulrack\Kernel\Common\Manager;

use Ulrack\Kernel\Common\InitializableKernelManagerInterface;
use Ulrack\JsonSchema\Common\SchemaValidatorFactoryInterface;
use GrizzIt\JsonSchema\Common\SchemaValidatorFactoryInterface;

interface ValidationManagerInterface extends InitializableKernelManagerInterface
{
Expand Down
87 changes: 87 additions & 0 deletions src/Component/Compiler/WrappedServiceCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/

namespace Ulrack\Kernel\Component\Compiler;

use GrizzIt\Validator\Common\ValidatorInterface;
use Ulrack\Kernel\Component\Registry\WrappedServiceRegistry;
use GrizzIt\Services\Common\Compiler\ServiceCompilerInterface;
use GrizzIt\Services\Common\Registry\ServiceRegistryInterface;
use GrizzIt\Services\Common\Compiler\ServiceCompilerExtensionInterface;

class WrappedServiceCompiler implements ServiceCompilerInterface
{
/**
* Contains the original service compiler.
*
* @var ServiceCompilerInterface
*/
private ServiceCompilerInterface $serviceCompiler;

/**
* Contains the compiled service registry.
*
* @var ServiceRegistryInterface|null
*/
private ?ServiceRegistryInterface $serviceRegistry = null;

/**
* Constructor.
*
* @param ServiceCompilerInterface $serviceCompiler
*/
public function __construct(ServiceCompilerInterface $serviceCompiler)
{
$this->serviceCompiler = $serviceCompiler;
}

/**
* Compiles the services and returns the compiled services.
*
* @return ServiceRegistryInterface
*/
public function compile(): ServiceRegistryInterface
{
if ($this->serviceRegistry === null) {
$this->serviceRegistry = new WrappedServiceRegistry(
$this->serviceCompiler->compile()
);
}

return $this->serviceRegistry;
}

/**
* Adds a validator for a service key.
*
* @param string $key
* @param ValidatorInterface $validator
*
* @return void
*/
public function addValidator(
string $key,
ValidatorInterface $validator
): void {
$this->serviceCompiler->addValidator($key, $validator);
}

/**
* Adds an extension to the service compiler.
*
* @param ServiceCompilerExtensionInterface $extension
* @param int $sortOrder
*
* @return void
*/
public function addExtension(
ServiceCompilerExtensionInterface $extension,
int $sortOrder
): void {
$this->serviceCompiler->addExtension($extension, $sortOrder);
}
}
5 changes: 2 additions & 3 deletions src/Component/Kernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class Kernel implements KernelInterface
*
* @param CoreManagerInterface $coreManager
*/
public function __construct(
CoreManagerInterface $coreManager
) {
public function __construct(CoreManagerInterface $coreManager)
{
$this->coreManager = $coreManager;
}

Expand Down
Loading

0 comments on commit 94b62b8

Please sign in to comment.