Skip to content

Instantly share code, notes, and snippets.

@basz
Created March 1, 2017 12:29
Show Gist options
  • Select an option

  • Save basz/17680640f3579e12f71ff1eb65ca2d3b to your computer and use it in GitHub Desktop.

Select an option

Save basz/17680640f3579e12f71ff1eb65ca2d3b to your computer and use it in GitHub Desktop.
added in prooph-event-store-mysql.global.php
i'm using the interface
// dependencies settings
'dependencies' => [
'factories' => [
\Prooph\EventStore\EventStore::class => [MySqlEventStoreFactory::class, 'default'],
\Prooph\EventStore\Projection\ProjectionManager::class => [\HF\Api\Infrastructure\Pdo\MySqlProjectionManagerFactory::class, 'default'],
],
],
<?php
declare(strict_types = 1);
namespace HF\Api\Infrastructure\Pdo;
use Interop\Config\ConfigurationTrait;
use Interop\Config\ProvidesDefaultOptions;
use Interop\Config\RequiresConfig;
use Interop\Config\RequiresConfigId;
use Interop\Config\RequiresMandatoryOptions;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Pdo\Exception\InvalidArgumentException;
use Prooph\EventStore\Pdo\Projection\MySqlProjectionManager;
use Psr\Container\ContainerInterface;
class MySqlProjectionManagerFactory implements
ProvidesDefaultOptions,
RequiresConfig,
RequiresConfigId,
RequiresMandatoryOptions
{
use ConfigurationTrait;
private $configId;
public function __construct(string $configId = 'default')
{
$this->configId = $configId;
}
/**
* Creates a new instance from a specified config, specifically meant to be used as static factory.
*
* In case you want to use another config key than provided by the factories, you can add the following factory to
* your config:
*
* <code>
* <?php
* return [
* ProjectionManager::class => [MySqlProjectionManagerFactory::class, 'service_name'],
* ];
* </code>
*
* @throws InvalidArgumentException
*/
public static function __callStatic(string $name, array $arguments): MySqlProjectionManager
{
if (! isset($arguments[0]) || ! $arguments[0] instanceof ContainerInterface) {
throw new InvalidArgumentException(
sprintf('The first argument must be of type %s', ContainerInterface::class)
);
}
return (new static($name))->__invoke($arguments[0]);
}
public function __invoke(ContainerInterface $container): MySqlProjectionManager
{
$config = $container->get('config');
$config = $this->options($config, $this->configId);
return new MySqlProjectionManager(
$container->get(EventStore::class),
$container->get($config['connection_service']),
$config['event_streams_table'],
$config['projections_table']
);
}
public function dimensions(): iterable
{
return ['prooph', 'event_store'];
}
public function mandatoryOptions(): iterable
{
return ['connection_service'];
}
public function defaultOptions(): iterable
{
return [
'event_streams_table' => 'event_streams',
'projections_table' => 'projections',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment