Skip to content

Commit

Permalink
Docs: rework
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 10, 2025
1 parent f03f360 commit a8fa097
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,44 @@
# Contributte Doctrine Annotations

[Doctrine/Annotations](https://www.doctrine-project.org/projects/annotations.html) for Nette Framework.

Integration of [Doctrine Annotations](https://www.doctrine-project.org/projects/annotations.html) for Nette Framework.

## Content

- [Setup](#setup)
- [Relying](#relying)
- [Installation](#installation)
- [Configuration](#configuration)
- [Minimal configuration](#minimal-configuration)
- [Advanced configuration](#advanced-configuration)
- [Caching](#caching)
- [Usage](#usage)
- [Examples](#examples)


## Setup
## Installation

Install package
Install package using composer.

```bash
composer require nettrine/annotations
```

Register extension
Register prepared [compiler extension](https://doc.nette.org/en/dependency-injection/nette-container) in your `config.neon` file.

```yaml
extensions:
nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension
```
> [!NOTE]
> This is just **Annotations**, for **ORM** use [nettrine/orm](https://github.com/contributte/doctrine-orm) or **DBAL** use [nettrine/dbal](https://github.com/contributte/doctrine-dbal).
## Relying
Take advantage of empowering this package with 1 extra package:
- `doctrine/cache`


### `doctrine/cache`
## Configuration
This package can be enhanced with `doctrine/cache`, use prepared [nettrine/cache](https://github.com/contributte/doctrine-cache) integration.
### Minimal configuration
```bash
composer require nettrine/cache
```

```yaml
extensions:
nettrine.cache: Nettrine\Cache\DI\CacheExtension
```neon
nettrine.annotations:
debug: %debugMode%
```

## Configuration

**Schema definition**
### Advanced configuration
```yaml
nettrine.annotations:
Expand All @@ -60,7 +47,7 @@ nettrine.annotations:
cache: <class|service>
```
**Under the hood**
**Example**
```yaml
nettrine.annotations:
Expand All @@ -69,22 +56,13 @@ nettrine.annotations:
cache: Doctrine\Common\Cache\PhpFileCache(%tempDir%/cache/doctrine)
```
You may omit the `cache` key using [nettrine/cache](https://github.com/contributte/doctrine-cache) to setup cache. It's configured automatically.

```yaml
nettrine.annotations:
debug: %debugMode%
```


## Usage
You can count on [Nette Dependency Injection](https://doc.nette.org/en/3.0/dependency-injection).

```php
use Doctrine\Common\Annotations\Reader;

class MyReader {
class MyReader
{

/** @var Reader */
private $reader;
Expand All @@ -102,17 +80,43 @@ class MyReader {
}
```

Register reader `MyReader` under services in NEON file.
You can create, define and read your own annotations. Take a look [how to do that](https://www.doctrine-project.org/projects/doctrine-annotations/en/2.0/index.html).

```yaml
services:
- MyReader
```
### Caching

> [!TIP]
> Take a look at more information in official Doctrine documentation:
> - https://www.doctrine-project.org/projects/annotations.html
A Doctrine Annotations reader can be very slow because it needs to parse all your entities and their annotations.

> [!WARNING]
> Cache adapter must implement `Psr\Cache\CacheItemPoolInterface` interface.
> Use any PSR-6 + PSR-16 compatible cache library like `symfony/cache` or `nette/caching`.
You can create, define and read your own annotations. Take a look [how to do that](https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/index.html#create-an-annotation-class).
In the simplest case, you can define only `cache`.

```neon
nettrine.annotations:
# Create cache manually
cache: App\CacheService(%tempDir%/cache/orm)
# Use registered cache service
cache: @cacheService
```

> [!IMPORTANT]
> You should always use cache for production environment. It can significantly improve performance of your application.
> Pick the right cache adapter for your needs.
> For example from symfony/cache:
>
> - `FilesystemAdapter` - if you want to cache data on disk
> - `ArrayAdapter` - if you want to cache data in memory
> - `ApcuAdapter` - if you want to cache data in memory and share it between requests
> - `RedisAdapter` - if you want to cache data in memory and share it between requests and servers
> - `ChainAdapter` - if you want to cache data in multiple storages
## Examples

- https://github.com/contributte/playground (playground)
- https://contributte.org/examples.html (more examples)
> [!TIP]
> Take a look at more examples in [contributte/doctrine](https://github.com/contributte/doctrine/tree/master/.docs).

0 comments on commit a8fa097

Please sign in to comment.