This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/module-manager-events' of https://github.com/Ev…
…anDotPro/zf2 into features/module-events-refactor
- Loading branch information
42 parents
78945d0
+
f0e5f4b
+
ceb7d8c
+
9e124d1
+
3de5912
+
b6a974a
+
10a6438
+
cb6c1e7
+
18afd6c
+
3baf1bd
+
c800904
+
f52dcb8
+
126ccb2
+
e7d6206
+
e2d24ab
+
ec1abfc
+
290ea90
+
9f4ca1b
+
edaa760
+
c4c0c95
+
d21f055
+
5b18029
+
e6b97af
+
010fb36
+
64c7b8d
+
636523e
+
4cc2cd6
+
e34098a
+
16367cd
+
943c77f
+
8226e5b
+
0b47726
+
3cd8a03
+
cc4782c
+
9c653a6
+
656dbe5
+
9bce1ba
+
7dc18ca
+
861130d
+
2d2ffbd
+
4f413a5
+
ef2cc8f
commit 00b350f
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
abstract class Options implements ParameterObject | ||
{ | ||
|
||
public function __construct($config = null) | ||
{ | ||
if (!is_null($config)) { | ||
if (is_array($config) || $config instanceof \Traversable) { | ||
$this->processArray($config); | ||
} else { | ||
throw new \InvalidArgumentException( | ||
'Parameter to \\Zend\\Stdlib\\Options\'s ' | ||
. 'constructor must be an array or implement the ' | ||
. '\\Traversable interface' | ||
); | ||
} | ||
} | ||
} | ||
|
||
protected function processArray(array $config) | ||
{ | ||
foreach ($config as $key => $value) { | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
$this->{$setter}($value); | ||
} | ||
} | ||
|
||
protected function assembleSetterNameFromConfigKey($key) | ||
{ | ||
$parts = explode('_', $key); | ||
$parts = array_map('ucfirst', $parts); | ||
$setter = 'set' . implode('', $parts); | ||
if (!method_exists($this, $setter)) { | ||
throw new \BadMethodCallException( | ||
'The configuration key "' . $key . '" does not ' | ||
. 'have a matching ' . $setter . ' setter method ' | ||
. 'which must be defined' | ||
); | ||
} | ||
return $setter; | ||
} | ||
|
||
protected function assembleGetterNameFromConfigKey($key) | ||
{ | ||
$parts = explode('_', $key); | ||
$parts = array_map('ucfirst', $parts); | ||
$getter = 'get' . implode('', $parts); | ||
if (!method_exists($this, $getter)) { | ||
throw new \BadMethodCallException( | ||
'The configuration key "' . $key . '" does not ' | ||
. 'have a matching ' . $getter . ' getter method ' | ||
. 'which must be defined' | ||
); | ||
} | ||
return $getter; | ||
} | ||
|
||
public function __set($key, $value) | ||
{ | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
$this->{$setter}($value); | ||
} | ||
|
||
public function __get($key) | ||
{ | ||
$getter = $this->assembleGetterNameFromConfigKey($key); | ||
return $this->{$getter}(); | ||
} | ||
|
||
public function __isset($key) | ||
{ | ||
$getter = $this->assembleGetterNameFromConfigKey($key); | ||
return !is_null($this->{$getter}()); | ||
} | ||
|
||
public function __unset($key) | ||
{ | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
try { | ||
$this->{$setter}(null); | ||
} catch(\InvalidArgumentException $e) { | ||
throw new \InvalidArgumentException( | ||
'The class property $' . $key . ' cannot be unset as' | ||
. ' NULL is an invalid value for it: ' . $e->getMessage() | ||
); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
interface ParameterObject | ||
{ | ||
|
||
public function __set($key, $value); | ||
|
||
public function __get($key); | ||
|
||
public function __isset($key); | ||
|
||
public function __unset($key); | ||
|
||
} |