Domena
UserRepository
Doctrine
PDO
RegisterUserResponder
Aplikacja
Symfony
https://github.com/cocoders/invoice-design-patterns
Nasz piękny legacy wczesny 2004 ;)
https://github.com/cocoders/invoice-design-patterns/blob/master/docker-compose.yml
version: '3.4'
services:
web:
image: nginx:1.13.7
depends_on:
- php
volumes:
- ./docker/nginx/invoice.conf:/etc/nginx/conf.d/default.conf
- ./public:/var/www/invoice/public
ports:
- "8080:80"
php:
image: cocoders/php-fpm:7.2.0
volumes:
- .:/var/www/invoice
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
environment:
POSTGRES_DSN: 'pgsql:host=postgres;port=5432;dbname=invoice;'
POSTGRES_USER: 'invoice'
POSTGRES_DB: 'invoice'
POSTGRES_PASSWORD: '!E4\mP-C;Q!@2vV3'
restart: always
working_dir: /var/www/invoice
postgres:
image: postgres:10.1
volumes:
- pg_data:/var/lib/postgresql/data
- ./docker/postgres/initsql:/docker-entrypoint-initdb.d/
environment:
POSTGRES_PASSWORD: '!E4\mP-C;Q!@2vV3'
POSTGRES_USER: 'invoice'
restart: always
ports:
- "5432:5432"
volumes:
pg_data:
PHPSpec i PHPUnit
PHPSpec i PHPUnit
Tworzymy opis domeny użytkownka w phpspecu
Tworzymy opis domena użytkownka w phpspecu
Tworzymy opis przypadku użycia naszej aplikacji w PHPSpecu, dla przypadku rejestracji użytkownika
Domena
Users
Adapter
Aplikacja
TransactionManager
UserFactory
Domena
Users
PDO Adapter
Aplikacja
TransactionManager
UserFactory
Cocoders\Invoice\Adapter\Pdo\Application\TransactionManager
Cocoders\Invoice\Adapter\Pdo\Domain\Users
Cocoders\Invoice\Adapter\Pdo\Domain\User
Cocoders\Invoice\Adapter\Pdo\Domain\UserFactory
extends User
function register()
{
global $connection, $registerErrors;
if (empty($_POST['email'])) {
$registerErrors['email'] = "Email field was empty.";
} elseif (empty($_POST['password'])) {
$registerErrors['password'] = "Password field was empty.";
} elseif (!empty($_POST['email']) && !empty($_POST['password'])) {
$stmt = $connection->prepare('SELECT id, email FROM users WHERE email = :email');
$stmt->execute(['email' => $_POST['email']]);
$users = $stmt->fetchAll();
if (count($users) > 0) {
$registerErrors['email'] = "User with given email exists already.";
return;
}
$stmt = $connection->prepare('INSERT INTO users
(email, password_hash) VALUES (:email, :password)');
$stmt->execute(['email' => $_POST['email'], 'password' => password_hash($_POST['password'], PASSWORD_BCRYPT)]);
header('Location: /login.php?successRegister=1');
exit;
}
}
function register()
{
global $registerErrors, $registerUser;
if (empty($_POST['password'])) {
$registerErrors->addError("password", "Password field was empty.");
return;
}
$registerUser->registerResponder(new RegisterUserResponder($registerErrors));
$registerUser->execute(new RegisterUser\Command(
$_POST['email'],
password_hash($_POST['password'], PASSWORD_BCRYPT)
));
if ($registerErrors->errors()) {
return;
}
header('Location: /login.php?successRegister=1');
exit;
}
function editProfile()
{
global $connection;
$stmt = $connection->prepare('UPDATE users SET name = :name, vat = :vat,
address = :address WHERE id = :user_id');
$stmt->execute([
'vat' => $_POST['vat'],
'address' => $_POST['address'],
'name' => $_POST['name'],
'user_id' => $_SESSION['loggedInUser']['id']
]);
header('Location: /index.php?page=user-profile&successMessage="Profile data updated successfully"');
exit;
}