Skip to content

Commit

Permalink
Issue #52: v4 active mode and bump PHP 8.4
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Oct 23, 2024
1 parent b725578 commit 76cc5d3
Show file tree
Hide file tree
Showing 27 changed files with 321 additions and 202 deletions.
1 change: 0 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- ubuntu-latest

php:
- "8.1"
- "8.2"
- "8.3"

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Continuous Integration"

on:
pull_request:
push:
branches:
tags:

jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/[email protected]
47 changes: 0 additions & 47 deletions .github/workflows/cs-tests.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/workflows/static-analysis.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/unit-test.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
2 changes: 1 addition & 1 deletion OSSMETADATA
Original file line number Diff line number Diff line change
@@ -1 +1 @@
osslifecycle=active
osslifecycle=active
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
# dot-annotated-services

DotKernel component used to create services through [Laminas Service Manager](https://github.com/laminas/laminas-servicemanager) and inject them with dependencies just using method annotations. It can also create services without the need to write factories. Annotation parsing can be cached, to improve performance.
Dotkernel component used to create services through [Laminas Service Manager](https://github.com/laminas/laminas-servicemanager) and inject them with dependencies just using method annotations. It can also create services without the need to write factories. Annotation parsing can be cached, to improve performance.

This package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two.

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-annotated-services)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.1.7)
![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-annotated-services%2Fblob%2F4.0%2FOSSMETADATA)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.2.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/blob/4.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml)
[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-annotated-services)

[![SymfonyInsight](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744/big.svg)](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744)


## Installation

Run the following command in your project directory

composer require dotkernel/dot-annotated-services

```shell
composer require dotkernel/dot-annotated-services
```

After installing, add the `ConfigProvider` class to your configuration aggregate.

## Usage

### Using the AnnotatedServiceFactory

You can register services in the service manager using the `AnnotatedServiceFactory` as below
You can register services in the service manager using the `AnnotatedServiceFactory` as below.

```php
return [
'factories' => [
Expand All @@ -40,10 +39,10 @@ return [
];
```

### NOTE
> You can use only the fully qualified class name as the service key
> You can use only the fully qualified class name as the service key.
The next step is to annotate the service constructor or setters with the service names to inject.

The next step is to annotate the service constructor or setters with the service names to inject
```php
use Dot\AnnotatedServices\Annotation\Inject;

Expand All @@ -65,7 +64,8 @@ public function __construct(
The annotation `@Inject` is telling the factory to inject the services between curly braces.
Valid service names should be provided, as registered in the service manager.

To inject an array value from the service manager, you can use dot notation as below
To inject an array value from the service manager, you can use dot notation as below,

```php
use Dot\AnnotatedServices\Annotation\Inject;

Expand All @@ -76,13 +76,14 @@ use Dot\AnnotatedServices\Annotation\Inject;

which will inject `$container->get('config')['debug'];`

### NOTE
> Even if using dot annotation, the annotated factory will check first if a service name exists with that name
> Even if using dot annotation, the annotated factory will check first if a service name exists with that name.
You can use the inject annotation on setters too, they will be called at creation time and injected with the configured dependencies.

### Using the AnnotatedRepositoryFactory
You can register doctrine repositories and inject them using the AnnotatedRepositoryFactory as below:
### Using the AnnotatedRepositoryFactory

You can register doctrine repositories and inject them using the AnnotatedRepositoryFactory as below.

```php
return [
'factories' => [
Expand All @@ -96,6 +97,7 @@ The next step is to add the `@Entity` annotation in the repository class.
The `name` field has to be the fully qualified class name.

Every repository should extend `Doctrine\ORM\EntityRepository`.

```php
use Doctrine\ORM\EntityRepository;
use Dot\AnnotatedServices\Annotation\Entity;
Expand All @@ -105,16 +107,15 @@ use Dot\AnnotatedServices\Annotation\Entity;
*/
class ExampleRepository extends EntityRepository
{

}
```


### Using the abstract factory

Using this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.

In order to tell the abstract factory which services are to be created, you need to annotate the service class with the `@Service` annotation.

```php
use Dot\AnnotatedServices\Annotation\Service;

Expand All @@ -129,13 +130,14 @@ class ServiceClass

And that's it, you don't need to configure the service manager with this class, creation will happen automatically.


## Cache annotations

This package is built on top of `doctrine/annotation` and `doctrine/cache`.
In order to cache annotations, you should register a service factory at key `AbstractAnnotatedFactory::CACHE_SERVICE` that should return a valid `Doctrine\Common\Cache\Cache` cache driver. See [Cache Drivers](https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache) for available implementations offered by doctrine.
In order to cache annotations, you should register a service factory at key `AbstractAnnotatedFactory::CACHE_SERVICE` that should return a valid `Doctrine\Common\Cache\Cache` cache driver.
See [Cache Drivers](https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache) for available implementations offered by doctrine.

Below, we give an example, as defined in our frontend and admin starter applications:

Below, we give an example, as defined in our frontend and admin starter applications
```php
return [
'annotations_cache_dir' => __DIR__ . '/../../data/cache/annotations',
Expand Down
40 changes: 40 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Security Policy

## Supported Versions


| Version | Supported | PHP Version |
|---------|--------------------|------------------------------------------------------------------------------------------------------------------------|
| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.2.0) |
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.2.0) |
| <= 3.x | :x: | |


## Reporting Potential Security Issues

If you have encountered a potential security vulnerability in this project,
please report it to us at <[email protected]>. We will work with you to
verify the vulnerability and patch it.

When reporting issues, please provide the following information:

- Component(s) affected
- A description indicating how to reproduce the issue
- A summary of the security vulnerability and impact

We request that you contact us via the email address above and give the
project contributors a chance to resolve the vulnerability and issue a new
release prior to any public exposure; this helps protect the project's
users, and provides them with a chance to upgrade and/or update in order to
protect their applications.


## Policy

If we verify a reported security vulnerability, our policy is:

- We will patch the current release branch, as well as the immediate prior minor
release branch.

- After patching the release branches, we will immediately issue new security
fix releases for each patched release branch.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"service-manager"
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"laminas/laminas-servicemanager": "^3.22.1",
"doctrine/annotations": "^1.14.3",
"doctrine/cache": "^1.12.1 || ^2.1.1",
"doctrine/orm" : "^2.17.3"
"doctrine/orm" : "^2.20"
},
"require-dev": {
"phpunit/phpunit": "^10.5.9",
"vimeo/psalm": "^5.20",
"laminas/laminas-coding-standard": "^2.5"
"laminas/laminas-coding-standard": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
Loading

0 comments on commit 76cc5d3

Please sign in to comment.