Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit aed63e5

Browse files
committed
Refactored constructor handling for configs
1 parent d0e8a1f commit aed63e5

File tree

6 files changed

+9
-57
lines changed

6 files changed

+9
-57
lines changed

Config/Config.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public static function factory(array $param, $class = 'ConfigDefault')
6161
*/
6262
private function __construct()
6363
{
64-
6564
}
6665

6766
/**
@@ -71,6 +70,5 @@ private function __construct()
7170
*/
7271
private function __clone()
7372
{
74-
7573
}
7674
}

Config/ConfigAbstract.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* This file is part of the <package> package.
3+
* This file is part of the php-utilities package.
44
*
55
* (c) Marc Aschmann <[email protected]>
66
*
@@ -30,7 +30,6 @@ abstract class ConfigAbstract extends Data
3030

3131
/**
3232
* default constructor
33-
* calls child's init() method
3433
*
3534
* @param array $param
3635
*/
@@ -40,19 +39,9 @@ public function __construct(array $param)
4039
$this->filecheck = (bool)$param['filecheck'];
4140
}
4241

43-
// default init of child class
44-
$this->init($param);
42+
$this->setConfig($param['file']);
4543
}
4644

47-
/**
48-
* abstract init
49-
* behaves like an interface and enforces implementation in child class
50-
*
51-
* @abstract
52-
* @param array $param
53-
*/
54-
abstract public function init(array $param);
55-
5645
/**
5746
* add named property to config object
5847
* and insert config as array

Config/ConfigDefault.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,4 @@
1717
*/
1818
final class ConfigDefault extends ConfigAbstract implements ConfigInterface
1919
{
20-
/**
21-
* default method
22-
* called by parent::__construct()
23-
*
24-
* @param array $param
25-
* @return \Asm\Config\ConfigDefault
26-
*/
27-
public function init(array $param)
28-
{
29-
$this->setConfig($param['file']);
30-
31-
return $this;
32-
}
3320
}

Config/ConfigEnv.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ final class ConfigEnv extends ConfigAbstract implements ConfigInterface
2525
private $defaultEnv = 'prod';
2626

2727
/**
28-
* default method
29-
* called by parent::__construct()
28+
* default constructor
3029
*
31-
* @param array $param
32-
* @return ConfigEnv
30+
* @param array $param
3331
*/
34-
public function init(array $param)
32+
public function __construct(array $param)
3533
{
34+
if (isset($param['filecheck'])) {
35+
$this->filecheck = (bool)$param['filecheck'];
36+
}
37+
3638
if (!empty($param['defaultEnv'])) {
3739
$this->defaultEnv = $param['defaultEnv'];
3840
}
3941

4042
$this->mergeEnvironments($param);
41-
42-
return $this;
4343
}
4444

4545
/**

Config/ConfigInterface.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
*/
2222
interface ConfigInterface extends DataInterface
2323
{
24-
/**
25-
* abstract init
26-
* behaves like an interface and enforces implementation in child class
27-
*
28-
* @param array $param
29-
*/
30-
public function init(array $param);
31-
3224
/**
3325
* add named property to config object
3426
* and insert config as array

Config/ConfigTimer.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@
1717
*/
1818
final class ConfigTimer extends ConfigAbstract implements ConfigInterface
1919
{
20-
/**
21-
* default method
22-
* called by parent::__construct()
23-
*
24-
* @param array $param
25-
* @return ConfigTimer
26-
*/
27-
public function init(array $param)
28-
{
29-
$this->setConfig($param['file']);
30-
31-
return $this;
32-
}
33-
3420
/**
3521
* convert config date strings to \DateTime objects or \DateIntervals
3622
*

0 commit comments

Comments
 (0)