Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main joseph 1.0 #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
vendor/
.phpunit*
.idea*
./tests/reports/*
./tests/reports/*
nbproject
composer.phar
132 changes: 132 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Rob Dunham
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Simple Recursive Autoloader
*
* A simple autoloader that loads class files recursively starting in the directory
* where this class resides. Additional options can be provided to control the naming
* convention of the class files.
*
* @package Autoloader
* @license http://opensource.org/licenses/MIT MIT License
* @author Rob Dunham <[email protected]>
*/
class Autoloader
{

/**
* File extension as a string. Defaults to ".php".
*/
protected static $fileExt = '.php';

/**
* The top level directory where recursion will begin. Defaults to the current
* directory.
*/
protected static $pathTop = __DIR__ . DIRECTORY_SEPARATOR . 'src';

/**
* A placeholder to hold the file iterator so that directory traversal is only
* performed once.
*/
protected static $fileIterator = null;

/**
* Autoload function for registration with spl_autoload_register
*
* Looks recursively through project directory and loads class files based on
* filename match.
*
* @param string $className
*/
public static function loader($className)
{
$directory = new RecursiveDirectoryIterator(static::$pathTop, RecursiveDirectoryIterator::SKIP_DOTS);

if (is_null(static::$fileIterator)) {

static::$fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);
}

$temp = explode('\\', $className);
end($temp);
$temp = current($temp);

$filename = $temp . static::$fileExt;

foreach (static::$fileIterator as $key => $file) {

if (strtolower($file->getFilename()) === strtolower($filename)) {

if ($file->isReadable()) {

include_once $file->getPathname();
}
break;
}
}
}

/**
* Sets the $fileExt property
*
* @param string $fileExt The file extension used for class files. Default is "php".
*/
public static function setFileExt($fileExt)
{
static::$fileExt = $fileExt;
}

/**
* Sets the $path property
*
* @param string $path The path representing the top level where recursion should
* begin. Defaults to the current directory.
*/
public static function setPath($path)
{
static::$pathTop = $path;
}

}

Autoloader::setFileExt('.php');

spl_autoload_register('Autoloader::loader');

//set cookie lifetime for 100 days (60sec * 60mins * 24hours * 100days)
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 100);
ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 100);
ini_set('session.cookie_secure', 1);

setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');

//error_reporting(0);
//ini_set('display_errors', 0);
error_reporting(E_ALL);
ini_set('display_errors', 1);
39 changes: 39 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

include ('bootstrap.php');

$frauCheckerContainerLibrary = new App\Domain\Libraries\FraudChecker\FraudCheckerContainer();
$frauCheckerIteratorLibrary = new App\Domain\Libraries\FraudChecker\FraudCheckerIterator();
$fraudCheckerService = new App\Domain\Services\FraudChecker($frauCheckerContainerLibrary, $frauCheckerIteratorLibrary);

$taxManagerLibrary = new App\Domain\Libraries\TaxManagerLibrary();
$notifierLibrary = new App\Domain\Libraries\NotifierLibrary();

$notifierService = new \App\Domain\Services\Notifier($notifierLibrary);
$taxCalculatorService = new \App\Domain\Services\TaxCalculator($taxManagerLibrary);
$transactionRepository = new \App\Domain\Repositories\TransactionRepository();

$transactionCalculator = new App\Domain\Services\Transaction\TransactionCalculator($taxCalculatorService);
$transactionChecker = new App\Domain\Services\Transaction\TransactionChecker($fraudCheckerService);
$transactionConfigurator = new App\Domain\Services\Transaction\TransactionConfigurator();
$transactionNotifier = new App\Domain\Services\Transaction\TransactionNotifier($notifierService);
$transactionSaver = new App\Domain\Services\Transaction\TransactionSaver($transactionRepository);

$buyer = new \App\Domain\Entities\Buyer();
$buyer->setEmail('[email protected]');
$seller = new \App\Domain\Entities\Seller();
$seller->setEmail('[email protected]');

$transaction = new App\Domain\Entities\Transaction();
$transaction->setBuyer($buyer);
$transaction->setSeller($seller);
$transaction->setSellerTax(10);
$transaction->setInitialAmount(100);

$handler = (new App\Domain\Services\TransactionHandler(
$transactionChecker,
$transactionCalculator,
$transactionConfigurator,
$transactionSaver,
$transactionNotifier
))->create($transaction);
13 changes: 13 additions & 0 deletions src/App/Domain/Contracts/FraudCheckerClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

use App\Domain\Entities\Transaction;

interface FraudCheckerClientInterface
{

public function check(Transaction $transaction): void;
}
17 changes: 17 additions & 0 deletions src/App/Domain/Contracts/FraudCheckerVendorClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

use App\Domain\Contracts\FraudCheckerClientInterface;

interface FraudCheckerVendorClientInterface extends FraudCheckerClientInterface
{

public function isAuthorized(): bool;

//public function notify(string $message, int $code): void;

public function extractMessageResponse($response): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

declare(strict_types=1);

namespace App\Domain\Clients;
namespace App\Domain\Contracts;

use App\Domain\Entities\Notification;

interface NotifierClientInterface
{

public function notify(Notification $notifier): void;
}
11 changes: 11 additions & 0 deletions src/App/Domain/Contracts/ReceptorEmailClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

interface ReceptorEmailClientInterface
{

public function getEmail(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

declare(strict_types=1);

namespace App\Domain\Clients;
namespace App\Domain\Contracts;

/**
* Interface TaxManagerClientInterface
* @package App\Domain\Clients
* @package App\Domain\Contracts
*/
interface TaxManagerClientInterface
{

/**
* @param float $amount
* @return float
Expand Down
17 changes: 17 additions & 0 deletions src/App/Domain/Contracts/TransactionProcessorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

use App\Domain\Entities\Transaction;

interface TransactionProcessorInterface
{

/**
* @param Transaction $transaction
* @param type $complement
*/
public function process(Transaction $transaction, $complement = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

declare(strict_types=1);

namespace App\Domain\Repositories;
namespace App\Domain\Contracts;

use App\Domain\Entities\Transaction;

interface TransactionRepositoryInterface
{

/**
* @param Transaction $transaction
* @return Transaction
*/
public function save(Transaction $transaction): Transaction;
}
14 changes: 13 additions & 1 deletion src/App/Domain/Entities/Buyer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace App\Domain\Entities;

class Buyer
use App\Domain\Contracts\ReceptorEmailClientInterface;
use App\Domain\Traits\Emailer;

class Buyer implements ReceptorEmailClientInterface
{

use Emailer;

/**
* @var string
*/
Expand All @@ -15,4 +21,10 @@ class Buyer
* @var string
*/
private string $name;

/**
* @var string
*/
private string $email;

}
30 changes: 30 additions & 0 deletions src/App/Domain/Entities/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace App\Domain\Entities;

use App\Domain\Traits\Emailer;

class Notification
{

use Emailer;

/**
* @var string
*/
Expand All @@ -15,4 +20,29 @@ class Notification
* @var string
*/
private string $message;

/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
}

/**
* @param string $message
*/
public function setMessage(string $message): void
{
$this->message = $message;
}

/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}

}
9 changes: 8 additions & 1 deletion src/App/Domain/Entities/Seller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace App\Domain\Entities;

class Seller
use App\Domain\Contracts\ReceptorEmailClientInterface;
use App\Domain\Traits\Emailer;

class Seller implements ReceptorEmailClientInterface
{

use Emailer;

/**
* @var string
*/
Expand All @@ -15,4 +21,5 @@ class Seller
* @var string
*/
private string $name;

}
Loading