Skip to content

Latest commit

 

History

History
executable file
·
122 lines (88 loc) · 3.14 KB

README.md

File metadata and controls

executable file
·
122 lines (88 loc) · 3.14 KB

Contributte Doctrine Annotations

Integration of Doctrine Annotations for Nette Framework.

Content

Installation

Install package using composer.

composer require nettrine/annotations

Register prepared compiler extension in your config.neon file.

extensions:
  nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension

Note

This is just Annotations, for ORM use nettrine/orm or DBAL use nettrine/dbal.

Configuration

Minimal configuration

nettrine.annotations:
  debug: %debugMode%

Advanced configuration

nettrine.annotations:
  debug: <boolean>
  ignore: <string[]>
  cache: <class|service>

Example

nettrine.annotations:
  debug: %debugMode%
  ignore: [author, since, see]
  cache: Doctrine\Common\Cache\PhpFileCache(%tempDir%/cache/doctrine)

Usage

use Doctrine\Common\Annotations\Reader;

class MyReader
{

  /** @var Reader */
  private $reader;

  public function __construct(Reader $reader)
  {
    $this->reader = $reader;
  }

  public function reader()
  {
    $annotations = $this->reader->getClassAnnotations(new \ReflectionClass(UserEntity::class));
  }

}

You can create, define and read your own annotations. Take a look how to do that.

Caching

Tip

Take a look at more information in official Doctrine documentation:

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.

In the simplest case, you can define only cache.

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

Tip

Take a look at more examples in contributte/doctrine.