Integration of Doctrine Annotations for Nette Framework.
Install package using composer.
composer require nettrine/annotationsRegister prepared compiler extension in your config.neon file.
extensions:
nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtensionNote
This is just Annotations, for ORM use nettrine/orm or DBAL use nettrine/dbal.
nettrine.annotations:
debug: %debugMode%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)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.
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: @cacheServiceImportant
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 diskArrayAdapter- if you want to cache data in memoryApcuAdapter- if you want to cache data in memory and share it between requestsRedisAdapter- if you want to cache data in memory and share it between requests and serversChainAdapter- if you want to cache data in multiple storages
Tip
Take a look at more examples in contributte/doctrine.