Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailatkurt committed Jul 4, 2018
0 parents commit d31ee0d
Show file tree
Hide file tree
Showing 28 changed files with 2,992 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
vendor
bin
reports
18 changes: 18 additions & 0 deletions bootstrap/DiKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace CashMachine\Bootstrap;

class DiKeys
{
const APPLICATION_CONFIG = 'applicationConfig';

const NOTE_APPLICATION_SERVICE = 'noteApplicationService';
const NOTE_DOMAIN_SERVICE = 'noteDomainService';
const NOTE_REPOSITORY = 'noteRepository';
const NOTES_CONTROLLER = 'notesController';

const REQUEST = 'request';
const RESPONSE = 'response';

const WITHDRAW_AMOUNT_REQUEST_FILTER = 'withdrawAmountRequestFilter';
}
13 changes: 13 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$application = new \Slim\App([
'settings' => [
'displayErrorDetails' => true
]
]);

require_once 'paths.php';
require_once 'dependencies.php';
require_once 'routes.php';

return $application;
62 changes: 62 additions & 0 deletions bootstrap/dependencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

use CashMachine\Bootstrap\DiKeys;
use Symfony\Component\Yaml\Yaml;

$container = $application->getContainer();

$container[DiKeys::APPLICATION_CONFIG] = function () use ($container) {
$result = defined('APPLICATION_ENV') ?
APPLICATION_ENV :
(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');

switch ($result) {
case 'production':
$file = 'production';
break;
case 'staging':
$file = 'staging';
break;
default:
$file = 'production';
break;
}

$contents = file_get_contents(CONFIG_PATH . $file . '.yaml');

return yaml_parse($contents);
};

$container[DiKeys::NOTES_CONTROLLER] = function (\Psr\Container\ContainerInterface $container) {
return new \CashMachine\Note\Infrastructure\Presentation\Controllers\NotesController(
$container->get(DiKeys::REQUEST),
$container->get(DiKeys::RESPONSE),
$container->get(DiKeys::WITHDRAW_AMOUNT_REQUEST_FILTER),
$container->get(DiKeys::NOTE_APPLICATION_SERVICE)
);
};

$container[DiKeys::WITHDRAW_AMOUNT_REQUEST_FILTER] = function () {
return new \CashMachine\Note\Application\RequestFilters\WithdrawAmountFilter();
};

$container[DiKeys::NOTE_APPLICATION_SERVICE] = function (\Psr\Container\ContainerInterface $container) {
return new \CashMachine\Note\Application\Services\NoteService(
$container->get(DiKeys::NOTE_DOMAIN_SERVICE)
);
};

$container[DiKeys::NOTE_DOMAIN_SERVICE] = function (\Psr\Container\ContainerInterface $container) {
return new \CashMachine\Note\Domain\NoteService(
$container->get(DiKeys::NOTE_REPOSITORY)
);
};

$container[DiKeys::NOTE_REPOSITORY] = function (\Psr\Container\ContainerInterface $container) {
$noteConfig = $container->get(DiKeys::APPLICATION_CONFIG)['availableNotes'];

return new \CashMachine\Note\Infrastructure\Persistence\Repositories\NoteRepository(
new \CashMachine\Note\Domain\NoteFactory(),
$noteConfig
);
};
5 changes: 5 additions & 0 deletions bootstrap/paths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

define('SOURCE_PATH', dirname(PROJECT_PATH, 1) . '/_cashmachine_source');
define('CONFIG_PATH', PROJECT_PATH . '/configs/');
define('LOGGER_PATH', SOURCE_PATH . '/logs');
10 changes: 10 additions & 0 deletions bootstrap/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use CashMachine\Bootstrap\DiKeys;

$application->get('/notes/withdraw/[{amount}]', function ($request, $response, $args) use ($container) {
/** @var \CashMachine\Note\Infrastructure\Presentation\Controllers\NotesController $notesController */
$notesController = $container->get(DiKeys::NOTES_CONTROLLER);

return $notesController->withdraw($args);
});
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "cash-machine",
"description": "Cash Machine Code Challenge",
"minimum-stability": "stable",
"config": {
"bin-dir": "bin/",
"disable-tls": true,
"secure-http": false
},
"require": {
"php": "^7.2",
"slim/slim": "^3.10",
"zendframework/zend-inputfilter": "^2.8"
},
"require-dev": {
"phpunit/phpunit": "^7.2"
},
"autoload": {
"psr-4": {
"CashMachine\\Bootstrap\\": "./bootstrap",
"CashMachine\\": "./src"
}
},
"autoload-dev": {
"CashMachine\\Tests": "./tests"
}
}
Loading

0 comments on commit d31ee0d

Please sign in to comment.