Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ The httplug event store is an implementation that uses httplug to communicate wi
This example uses Guzzle6 httplug adapter

```php
$messageFactory = new \Prooph\Common\Messaging\FQCNMessageFactory();
$messageConverter = new \Prooph\Common\Messaging\NoOpMessageConverter();
$httplug = new \Http\Adapter\Guzzle6\Client();
$eventStore = new \Prooph\EventStore\Httplug($httpPlug, $options);
$uri = new \GuzzleHttp\Psr7\Uri('http:/localhost:8080');

$streamEvents =$eventStore->load(new StreamName('test-stream'));
$eventStore = new \Prooph\EventStore\Httplug\HttplugEventStore($messageFactory, $messageConverter, $httpPlug, $uri);

$streamEvents = $eventStore->load(new StreamName('test-stream'));
```

## Support
Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
],
"require": {
"php": "^7.1",
"prooph/event-store" : "^7.2"
"prooph/event-store": "^7.2",
"php-http/httplug": "^1.1.0",
"psr/http-message": "^1.0.1",
"php-http/message-factory": "^1.0.2",
"php-http/discovery": "^1.1.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand All @@ -43,13 +47,13 @@
},
"autoload": {
"psr-4": {
"Prooph\\EventStore\\Httplug\\": "src/"
"Prooph\\EventStore\\Httplug\\": "src/",
"ProophTest\\EventStore\\": "vendor/prooph/event-store/tests/"
}
},
"autoload-dev": {
"psr-4": {
"ProophTest\\EventStore\\Httplug\\": "tests/",
"ProophTest\\EventStore\\": "vendor/prooph/event-store/tests/"
"ProophTest\\EventStore\\Httplug\\": "tests/"
}
},
"config": {
Expand Down
106 changes: 106 additions & 0 deletions src/Container/HttplugEventStoreFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* This file is part of the prooph/httplug-event-store.
* (c) 2017-2017 prooph software GmbH <contact@prooph.de>
* (c) 2017-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Httplug\Container;

use Interop\Config\ConfigurationTrait;
use Interop\Config\ProvidesDefaultOptions;
use Interop\Config\RequiresConfigId;
use Interop\Config\RequiresMandatoryOptions;
use Prooph\Common\Messaging\FQCNMessageFactory;
use Prooph\Common\Messaging\NoOpMessageConverter;
use Prooph\EventStore\Exception\InvalidArgumentException;
use Prooph\EventStore\Httplug\HttplugEventStore;
use Psr\Container\ContainerInterface;

final class HttplugEventStoreFactory implements
ProvidesDefaultOptions,
RequiresConfigId,
RequiresMandatoryOptions
{
use ConfigurationTrait;

/**
* @var string
*/
private $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 [
* HttplugEventStore::class => [HttplugEventStoreFactory::class, 'service_name'],
* ];
* </code>
*
* @throws InvalidArgumentException
*/
public static function __callStatic(string $name, array $arguments): HttplugEventStore
{
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 __construct(string $configId = 'default')
{
$this->configId = $configId;
}

public function __invoke(ContainerInterface $container): HttplugEventStore
{
$config = $container->get('config');
$config = $this->options($config, $this->configId);

$requestFactory = null;

if (isset($config['request_factory'])) {
$requestFactory = $container->get($config['request_factory']);
}

return new HttplugEventStore(
$container->get($config['message_factory']),
$container->get($config['message_converter']),
$container->get($config['http_client']),
$requestFactory
);
}

public function dimensions(): iterable
{
return ['prooph', 'event_store'];
}

public function defaultOptions(): iterable
{
return [
'message_factory' => FQCNMessageFactory::class,
'message_converter' => NoOpMessageConverter::class,
];
}

public function mandatoryOptions(): iterable
{
return [
'http_client',
];
}
}
92 changes: 92 additions & 0 deletions src/Container/Projection/HttplugProjectionManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* This file is part of the prooph/httplug-event-store.
* (c) 2017-2017 prooph software GmbH <contact@prooph.de>
* (c) 2017-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Httplug\Container\Projection;

use Interop\Config\ConfigurationTrait;
use Interop\Config\RequiresConfigId;
use Interop\Config\RequiresMandatoryOptions;
use Prooph\EventStore\Exception\InvalidArgumentException;
use Prooph\EventStore\Httplug\Projection\HttplugProjectionManager;
use Psr\Container\ContainerInterface;

final class HttplugProjectionManagerFactory implements
RequiresConfigId,
RequiresMandatoryOptions
{
use ConfigurationTrait;

/**
* @var string
*/
private $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 [
* HttplugProjectionManager::class => [HttplugProjectionManagerFactory::class, 'service_name'],
* ];
* </code>
*
* @throws InvalidArgumentException
*/
public static function __callStatic(string $name, array $arguments): HttplugProjectionManager
{
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 __construct(string $configId = 'default')
{
$this->configId = $configId;
}

public function __invoke(ContainerInterface $container): HttplugProjectionManager
{
$config = $container->get('config');
$config = $this->options($config, $this->configId);

$requestFactory = null;

if (isset($config['request_factory'])) {
$requestFactory = $container->get($config['request_factory']);
}

return new HttplugProjectionManager(
$container->get($config['http_client']),
$requestFactory
);
}

public function dimensions(): iterable
{
return ['prooph', 'projection_manager'];
}

public function mandatoryOptions(): iterable
{
return [
'http_client',
];
}
}
20 changes: 20 additions & 0 deletions src/Exception/NotAllowed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* This file is part of the prooph/httplug-event-store.
* (c) 2017-2017 prooph software GmbH <contact@prooph.de>
* (c) 2017-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Httplug\Exception;

use Prooph\EventStore\Exception\RuntimeException;

class NotAllowed extends RuntimeException
{
protected $message = 'You are not allowed to access this resource';
}
Loading