1. Go to this page and download the library: Download lmc/cqrs-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lmc / cqrs-handler example snippets
$queryFetcher = new QueryFetcher(
// Cache
false, // disabled cache
null, // no cache pool -> no caching
// Profiling
null // no profiler bag -> no profiling
);
$profilerBag = new ProfilerBag();
$queryFetcher = new QueryFetcher(
// Cache
true, // is cache enabled
$cache, // instance of Psr\Cache\CacheItemPoolInterface
// Profiling
$profilerBag, // collection of profiled information
// Custom handlers
// NOTE: there is multiple ways of defining handler
[
[new TopMostHandler(), PrioritizedItem::PRIORITY_HIGHEST], // Array definition of priority
new OtherHandler(), // Used with default priority of 50
new PrioritizedItem(new FallbackHandler(), PrioritizedItem::PRIORITY_LOWEST) // PrioritizedItem value object definition
],
// Custom response decoders
// NOTE: there is multiple ways of defining response decoders
[
[new TopMostDecoder(), PrioritizedItem::PRIORITY_HIGHEST], // Array definition of priority
new OtherDecoder(), // Used with default priority of 50
new PrioritizedItem(new FallbackDecoder(), PrioritizedItem::PRIORITY_LOWEST) // PrioritizedItem value object definition
]
);
$query = new CallbackQueryHandler(
fn () => $this->repository->fetchData(),
new CacheKey('my-data-key'),
CacheTime::oneHour()
);
$query = new ProfiledCallbackQueryHandler(
fn () => $this->repository->fetchData(),
new CacheKey('my-data-key'),
CacheTime::oneHour(),
'my-profiler-key',
['additional' => 'data'] // optional
);
$commandSender = new CommandSender(
// Profiling
null // no profiler bag -> no profiling
);
$profilerBag = new ProfilerBag();
$commandSender = new CommandSender(
// Profiling
$profilerBag, // collection of profiled information
// Custom handlers
// NOTE: there is multiple ways of defining handler
[
[new TopMostHandler(), PrioritizedItem::PRIORITY_HIGHEST], // Array definition of priority
new OtherHandler(), // Used with default priority of 50
new PrioritizedItem(new FallbackHandler(), PrioritizedItem::PRIORITY_LOWEST) // PrioritizedItem value object definition
],
// Custom response decoders
// NOTE: there is multiple ways of defining response decoders
[
[new TopMostDecoder(), PrioritizedItem::PRIORITY_HIGHEST], // Array definition of priority
new OtherDecoder(), // Used with default priority of 50
new PrioritizedItem(new FallbackDecoder(), PrioritizedItem::PRIORITY_LOWEST) // PrioritizedItem value object definition
]
);