Skip to content

Commit

Permalink
updated to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Aug 25, 2017
1 parent d4a017f commit 8b69f1b
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 136 deletions.
13 changes: 7 additions & 6 deletions Controller/EventStoreManagerBundleController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the Simple EventStore Manager package.
* This file is part of the Simple EventStore EventStoreManager package.
*
* (c) Mauro Cassani<https://github.com/mauretto78>
*
Expand All @@ -11,8 +11,9 @@
namespace SimpleEventStoreManager\Bundle\Controller;

use JMS\Serializer\SerializerBuilder;
use SimpleEventStoreManager\Application\Event\EventRepresentation;
use SimpleEventStoreManager\Application\EventQuery;
use SimpleEventStoreManager\Bundle\Service\Manager;
use SimpleEventStoreManager\Bundle\Service\EventStoreManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -27,13 +28,13 @@ class EventStoreManagerBundleController extends Controller
*/
public function aggregateAction(Request $request, $aggregate, $page = null)
{
/** @var Manager $manager */
$manager = $this->container->get('simple_event_store_manager');
$eventManager = $manager->getMananger();
/** @var EventStoreManager $eventStoreManager */
$eventStoreManager = $this->container->get('simple_event_store_manager');
$eventManager = $eventStoreManager->getEventMananger();

$config = $this->container->getParameter('simple_event_store_manager');
$dataTransformer = 'SimpleEventStoreManager\\Infrastructure\\DataTransformers\\'.ucfirst($config['api_format']).'EventDataTransformer';
$eventsQuery = new EventQuery(
$eventsQuery = new EventRepresentation(
$eventManager,
new $dataTransformer(
SerializerBuilder::create()->build(),
Expand Down
9 changes: 8 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the Simple EventStore Manager package.
* This file is part of the Simple EventStore EventStoreManager package.
*
* (c) Mauro Cassani<https://github.com/mauretto78>
*
Expand Down Expand Up @@ -44,6 +44,13 @@ public function getConfigTreeBuilder()
])
->defaultValue('json')
->end()
->enumNode('return_type')
->values([
'array',
'object'
])
->defaultValue('array')
->end()
->arrayNode('parameters')
->isRequired()
->prototype('variable')
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SimpleEventStoreManagerExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the Simple EventStore Manager package.
* This file is part of the Simple EventStore EventStoreManager package.
*
* (c) Mauro Cassani<https://github.com/mauretto78>
*
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ simple_event_store_manager:
password: ~
database: 'eventstore_demo'
port: '27017'
return_type: 'array'
elastic:
host: 'localhost'
port: '9200'
```

* `return_type` is an optional parameter; you can choose between array or object to return aggregates
* `api_format` is an optional parameter; you can choose between `json` (default), `xml` or `yaml`
* `elastic` is an optional parameter; you can send your events to a Elastic server

Expand Down Expand Up @@ -63,7 +65,7 @@ You can use `EventsManager` in your Controllers:
// ..

$manager = $this->container->get('simple_event_store_manager');
$eventManager = $manager->getMananger();
$eventManager = $manager->getEventMananger();

// store events in an aggregate
$eventManager->storeEvents(
Expand All @@ -73,6 +75,14 @@ $eventManager->storeEvents(
]
);

// get event streams
$eventQuery = $eventStoreManager->getEventQuery();

$stream = $eventQuery->fromAggregate('Your aggregate');
foreach ($stream as $event){
// ..
}

```

Or inject it into your services and classes:
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
simple_event_store_manager.class: SimpleEventStoreManager\Bundle\Service\Manager
simple_event_store_manager.class: SimpleEventStoreManager\Bundle\Service\EventStoreManager

services:
simple_event_store_manager:
Expand Down
80 changes: 80 additions & 0 deletions Service/EventStoreManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* This file is part of the Simple EventStore EventStoreManager package.
*
* (c) Mauro Cassani<https://github.com/mauretto78>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SimpleEventStoreManager\Bundle\Service;

use SimpleEventStoreManager\Application\Event\EventManager as EM;
use SimpleEventStoreManager\Application\Event\EventQuery as EQ;
use SimpleEventStoreManager\Application\Event\EventQuery;
use SimpleEventStoreManager\Domain\Model\Contracts\EventAggregateRepositoryInterface;

class EventStoreManager
{
/**
* @var EM
*/
private $eventManager;

/**
* @var EQ
*/
private $eventQuery;

/**
* EventStoreManager constructor.
*
* @param array $config
*/
public function __construct(array $config = [])
{
$this->setEventMananger($config);
$this->setEventQuery($this->eventManager);
}

/**
* @param $config
*/
private function setEventMananger($config)
{
$returnType = ($config['return_type'] === 'array') ? EventAggregateRepositoryInterface::RETURN_AS_ARRAY : EventAggregateRepositoryInterface::RETURN_AS_OBJECT;
$this->eventManager = EM::build()
->setDriver($config['driver'])
->setConnection($config['parameters'])
->setReturnType($returnType);

if($config['elastic']){
$this->eventManager->setElasticServer($config['elastic']);
}
}

/**
* @return EM
*/
public function getEventMananger()
{
return $this->eventManager;
}

/**
* @param EM $eventManager
*/
private function setEventQuery(EM $eventManager)
{
$this->eventQuery = new EventQuery($eventManager);
}

/**
* @return EQ
*/
public function getEventQuery()
{
return $this->eventQuery;
}
}
51 changes: 0 additions & 51 deletions Service/Manager.php

This file was deleted.

4 changes: 2 additions & 2 deletions SimpleEventStoreManagerBundle.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the Simple EventStore Manager package.
* This file is part of the Simple EventStore EventStoreManager package.
*
* (c) Mauro Cassani<https://github.com/mauretto78>
*
Expand All @@ -14,5 +14,5 @@

class SimpleEventStoreManagerBundle extends Bundle
{
const VERSION = '1.0.1';
const VERSION = '2.0.';
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
],
"require": {
"mauretto78/simple-event-store-manager": "^1.2",
"mauretto78/simple-event-store-manager": "^2.0",
"symfony/http-kernel": "~2.3|~3.0",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
Expand Down
Loading

0 comments on commit 8b69f1b

Please sign in to comment.