Skip to content

Commit b2e51bd

Browse files
author
Jefersson Nathan
authored
Merge pull request #32 from lucianoqueiroz/improvements/#1
Improvements/#1
2 parents 2f90c02 + 5e382fe commit b2e51bd

File tree

15 files changed

+183
-67
lines changed

15 files changed

+183
-67
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DB_DSN=mysql:host=localhost;dbname=conticket
2+
DB_USER=root
3+
DB_PASSWORD=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ composer.phar
33
composer.lock
44
bin
55
vendor/
6+
.env
67
app/cache/*
78
app/logs/*
89
app/phpunit.xml

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"prooph/event-store-doctrine-adapter": "^3.3",
3434
"prooph/service-bus": "^5.2",
3535
"ramsey/uuid": "^2.8",
36+
"vlucas/phpdotenv": "^2.4",
3637
"zendframework/zend-expressive": "^1.0",
3738
"zendframework/zend-expressive-fastroute": "^1.0",
3839
"zendframework/zend-servicemanager": "^3.2"

config/commands.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license.
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
use Conticket\Conference\Factory\CommandHandler\CreateConferenceHandlerFactory;
22+
use Conticket\Conference\Domain\Command\CreateConference;
23+
24+
return (function () {
25+
return [
26+
'factories' => [
27+
CreateConference::class => CreateConferenceHandlerFactory::class,
28+
],
29+
];
30+
})();

config/middlewares.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use Conticket\Conference\Infrastructure\Middleware\CreateConferenceMiddleware;
66
use Conticket\Conference\Factory\Middleware\CreateConferenceMiddlewareFactory;
77

8-
return [
9-
'factories' => [
10-
CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class,
11-
],
12-
];
8+
return (function () {
9+
return [
10+
'factories' => [
11+
CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class,
12+
],
13+
];
14+
})();

config/repositories.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license.
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface;
22+
use Conticket\Conference\Factory\Repository\ConferenceRepositoryFactory;
23+
24+
return (function () {
25+
return [
26+
'factories' => [
27+
ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class,
28+
],
29+
];
30+
})();

config/service-manager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
return new \Zend\ServiceManager\ServiceManager(
99
array_merge_recursive(
1010
require __DIR__ . '/services.php',
11-
require __DIR__ . '/middlewares.php'
11+
require __DIR__ . '/commands.php',
12+
require __DIR__ . '/middlewares.php',
13+
require __DIR__ . '/repositories.php'
1214
)
1315
);
1416
})();

config/services.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,27 @@
22

33
declare(strict_types=1);
44

5-
use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface;
6-
use Conticket\Conference\Factory\Repository\ConferenceRepositoryFactory;
7-
use Conticket\Conference\Factory\CommandHandler\CreateConferenceHandlerFactory;
8-
use Conticket\Conference\Domain\Command\CreateConference;
5+
use Conticket\Conference\Infrastructure\Service\ApplicationFactory;
96
use Conticket\Conference\Infrastructure\Service\CommandBusFactory;
107
use Conticket\Conference\Infrastructure\Service\ConnectionFactory;
118
use Conticket\Conference\Infrastructure\Service\EventStoreFactory;
9+
use Conticket\Conference\Infrastructure\Service\PDOFactory;
1210
use Doctrine\DBAL\Connection;
13-
use Interop\Container\ContainerInterface;
1411
use Prooph\EventStore\EventStore;
1512
use Prooph\ServiceBus\CommandBus;
1613
use Zend\Expressive\Application;
1714
use Zend\Expressive\Router\FastRouteRouter;
15+
use Zend\ServiceManager\Factory\InvokableFactory;
1816

1917
return (function () {
2018
return [
21-
// @todo move factories to proper classes
2219
'factories' => [
23-
Application::class => function (ContainerInterface $container) {
24-
return new Application($container->get(FastRouteRouter::class), $container);
25-
},
26-
FastRouteRouter::class => function (ContainerInterface $container) {
27-
return new FastRouteRouter();
28-
},
29-
30-
CommandBus::class => CommandBusFactory::class,
31-
EventStore::class => EventStoreFactory::class,
32-
Connection::class => ConnectionFactory::class,
33-
34-
// @todo move commands/events to another config file
35-
CreateConference::class => CreateConferenceHandlerFactory::class,
36-
37-
// @todo move repository to another file
38-
ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class,
39-
40-
// @todo move db info to a class to get ENV vars
41-
'db_dsn' => function () {
42-
return 'mysql:host=localhost;dbname=conticket';
43-
},
44-
'db_user' => function () {
45-
return 'root';
46-
},
47-
'db_password' => function () {
48-
return 'root';
49-
},
20+
Application::class => ApplicationFactory::class,
21+
FastRouteRouter::class => InvokableFactory::class,
22+
CommandBus::class => CommandBusFactory::class,
23+
EventStore::class => EventStoreFactory::class,
24+
Connection::class => ConnectionFactory::class,
25+
\PDO::class => PDOFactory::class,
5026
],
5127
];
5228
})();

public/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
(function () {
88
require __DIR__ . '/../vendor/autoload.php';
99

10+
(new \Dotenv\Dotenv(__DIR__ . '/..'))->load();
11+
1012
/* @var $serviceManager \Zend\ServiceManager\ServiceManager */
1113
$serviceManager = require __DIR__ . '/../config/service-manager.php';
1214

src/Conference/Domain/Command/CreateConference.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,32 @@ final class CreateConference extends Command
5454
*/
5555
private $date;
5656

57-
private function __construct()
58-
{
59-
}
60-
61-
public static function fromRequestData(
57+
private function __construct(
6258
ConferenceId $conferenceId,
6359
string $name,
6460
string $description,
6561
string $author,
6662
\DateTimeImmutable $date
67-
): self {
68-
// @todo move to __constructor
63+
) {
6964
Assertion::notEmpty($name);
7065
Assertion::notEmpty($description);
7166
Assertion::notEmpty($author);
7267

73-
$self = new self();
74-
$self->conferenceId = $conferenceId;
75-
$self->name = $name;
76-
$self->description = $description;
77-
$self->author = $author;
78-
$self->date = $date;
68+
$this->conferenceId = $conferenceId;
69+
$this->name = $name;
70+
$this->description = $description;
71+
$this->author = $author;
72+
$this->date = $date;
73+
}
7974

80-
return $self;
75+
public static function fromRequestData(
76+
ConferenceId $conferenceId,
77+
string $name,
78+
string $description,
79+
string $author,
80+
\DateTimeImmutable $date
81+
): self {
82+
return new self($conferenceId, $name, $description, $author, $date);
8183
}
8284

8385
/**

0 commit comments

Comments
 (0)