Fix configuration service injection.
parent
b6bae7cc9a
commit
201934a852
|
@ -8,24 +8,25 @@ use RprtCli\Utils\Configuration\ConfigurationInterface;
|
|||
use RprtCli\Utils\Configuration\ConfigurationService;
|
||||
use RprtCli\Utils\CsvReport\CsvReport;
|
||||
use RprtCli\Utils\CsvReport\CsvReportInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
return [
|
||||
'config.file' => 'rprt.config.yml',
|
||||
'config.path' => '~/.config/rprt-cli/',
|
||||
'guzzle' => create()->constructor(\GuzzleHttp\Client::class),
|
||||
'yaml' => create()->constructor(\Symfony\Component\Yaml\Yaml::class),
|
||||
\GuzzleHttp\ClientInterface::class => DI\get(\GuzzleHttp\Client::class),
|
||||
CsvReportInterface::class => DI\get(CsvReport::class),
|
||||
'guzzle' => create()->constructor(Client::class),
|
||||
ConfigurationInterface::class => get(ConfigurationService::class),
|
||||
ConfigurationService::class => create()->constructor(
|
||||
get('config.path'),
|
||||
get('config.file'),
|
||||
get('yaml')
|
||||
get('config.file')
|
||||
),
|
||||
RprtCommand::class => DI\create()->constructor(
|
||||
get(CsvReportInterface::class),
|
||||
get(ConfigurationInterface::class)
|
||||
'config.service' => get(ConfigurationInterface::class),
|
||||
CsvReportInterface::class => get(CsvReport::class),
|
||||
CsvReport::class => create()->constructor(
|
||||
get('config.service')
|
||||
),
|
||||
'csv.report' => get(CsvReportInterface::class),
|
||||
RprtCommand::class => create()->constructor(
|
||||
get('csv.report'),
|
||||
get('config.service')
|
||||
)
|
||||
];
|
||||
|
|
|
@ -49,20 +49,34 @@ class RprtCommand extends Command {
|
|||
}
|
||||
|
||||
protected function generateTable($output, $data) {
|
||||
// @TODO - get configuration
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['Project', 'Hours', 'Rate', 'Price']);
|
||||
$rows = [];
|
||||
$together = 0;
|
||||
$config = $this->configuration->get('projects');
|
||||
var_dump($config);
|
||||
foreach ($data as $project => $hours) {
|
||||
$row = [$project, $hours/60];
|
||||
$together += $hours / 60;
|
||||
list($rows, $total_hours, $total_price) = [[], 0, 0];
|
||||
$projects_config = $this->configuration->get('projects');
|
||||
var_dump($projects_config);
|
||||
foreach ($projects_config as $name => $config) {
|
||||
if (!isset($data[$name])) {
|
||||
var_dump('Project ' . $name . ' is not set!');
|
||||
continue;
|
||||
}
|
||||
$hours = $data[$name];
|
||||
if ($config['time_format'] === 'm') {
|
||||
$hours = $hours/60;
|
||||
}
|
||||
$price = $hours * (int) $config['price'];
|
||||
$row = [
|
||||
$config['name'],
|
||||
$hours,
|
||||
$config['price'],
|
||||
$hours * $config['price'],
|
||||
];
|
||||
$rows[] = $row;
|
||||
$total_hours += $hours;
|
||||
$total_price += $price;
|
||||
}
|
||||
$rows[] = new TableSeparator();
|
||||
$rows[] = ['Zusamen', $together];
|
||||
// @TODO Check rate in final result.
|
||||
$rows[] = ['Zusamen', $total_hours, $config['price'], $total_price];
|
||||
$table->setRows($rows);
|
||||
return $table;
|
||||
}
|
||||
|
|
|
@ -35,21 +35,20 @@ class ConfigurationService implements ConfigurationInterface
|
|||
/**
|
||||
* Yaml service.
|
||||
*
|
||||
* @var \Symfony\Component\Yaml\Yaml;
|
||||
* @var \Symfony\Component\Yaml\Yaml::parseFile;
|
||||
*/
|
||||
protected $yaml;
|
||||
protected $yamlParseFile;
|
||||
|
||||
/**
|
||||
* Construct method.
|
||||
*/
|
||||
function __construct(string $filepath, string $filename, Yaml $yaml) {
|
||||
function __construct(string $filepath, string $filename) {
|
||||
$file = $filepath . $filename;
|
||||
$this->configFileName = $filename;
|
||||
$this->configFilePath = $this->findConfig($file);
|
||||
if ($this->configFilePath) {
|
||||
$this->getConfig();
|
||||
}
|
||||
$this->yaml = $yaml;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +78,7 @@ class ConfigurationService implements ConfigurationInterface
|
|||
public function getConfig() {
|
||||
if ($this->configFilePath) {
|
||||
var_dump($this->configFilePath);
|
||||
$config = $this->yaml->parseFile($this->configFilePath);
|
||||
$config = Yaml::parseFile($this->configFilePath);
|
||||
$this->data = $config;
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,23 @@
|
|||
|
||||
namespace RprtCli\Utils\CsvReport;
|
||||
|
||||
use RprtCli\Utils\Configuration\ConfigurationInterface;
|
||||
use RprtCli\Utils\CsvReport\CsvReportInterface;
|
||||
|
||||
class CsvReport implements CsvReportInterface {
|
||||
|
||||
protected $configurationService;
|
||||
|
||||
function __construct(ConfigurationInterface $config) {
|
||||
$this->configurationService = $config;
|
||||
}
|
||||
|
||||
public function getReportData(string $file_path): array {
|
||||
$output = [];
|
||||
// @TODO replace with config service.
|
||||
$config = $this->dummyConfig();
|
||||
foreach (array_keys($config['projects']) as $key) {
|
||||
// $config = $this->dummyConfig()['projects'];
|
||||
$config = $this->configurationService->get('projects');
|
||||
foreach (array_keys($config) as $key) {
|
||||
$output[$key] = 0;
|
||||
}
|
||||
if ($file = fopen($file_path, 'r')) {
|
||||
|
@ -27,9 +35,10 @@ class CsvReport implements CsvReportInterface {
|
|||
}
|
||||
|
||||
protected function parseCsvFile(array $raw_data): array {
|
||||
$config = $this->dummyConfig();
|
||||
// $config = $this->dummyConfig();
|
||||
$config = $this->configurationService->get('projects');
|
||||
// var_dump($raw_data);
|
||||
foreach ($config['projects'] as $key => $project) {
|
||||
foreach ($config as $key => $project) {
|
||||
if (preg_match('/'.$project['pattern'].'/', $raw_data[1])) {
|
||||
return [$key => $raw_data[4]];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue