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 'master' of git://github.com/zendframework/zf2 into zf11884
- Loading branch information
Richard Kellner
committed
Nov 19, 2011
43 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
+
ccab83f
+
00b350f
commit dbfb1b8
Showing
3 changed files
with
259 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,39 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Stdlib\Exception; | ||
|
||
use Zend\Stdlib\Exception; | ||
|
||
/** | ||
* Bad method call exception | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
class BadMethodCallException extends \BadMethodCallException | ||
implements Exception | ||
{ | ||
} |
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,162 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Stdlib; | ||
|
||
use Traversable; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
abstract class Options implements ParameterObject | ||
{ | ||
/** | ||
* @param array|Traversable|null $config | ||
* @return Options | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public function __construct($config = null) | ||
{ | ||
if (!is_null($config)) { | ||
if (is_array($config) || $config instanceof Traversable) { | ||
$this->processArray($config); | ||
} else { | ||
throw new Exception\InvalidArgumentException( | ||
'Parameter to \Zend\Stdlib\Options\'s ' | ||
. 'constructor must be an array or implement the ' | ||
. 'Traversable interface' | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param array $config | ||
* @return void | ||
*/ | ||
protected function processArray(array $config) | ||
{ | ||
foreach ($config as $key => $value) { | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
$this->{$setter}($value); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $key name of option with underscore | ||
* @return string name of setter method | ||
* @throws Exception\BadMethodCallException if setter method is undefined | ||
*/ | ||
protected function assembleSetterNameFromConfigKey($key) | ||
{ | ||
$parts = explode('_', $key); | ||
$parts = array_map('ucfirst', $parts); | ||
$setter = 'set' . implode('', $parts); | ||
if (!method_exists($this, $setter)) { | ||
throw new Exception\BadMethodCallException( | ||
'The configuration key "' . $key . '" does not ' | ||
. 'have a matching ' . $setter . ' setter method ' | ||
. 'which must be defined' | ||
); | ||
} | ||
return $setter; | ||
} | ||
|
||
/** | ||
* @param string $key name of option with underscore | ||
* @return string name of getter method | ||
* @throws Exception\BadMethodCallException if getter method is undefined | ||
*/ | ||
protected function assembleGetterNameFromConfigKey($key) | ||
{ | ||
$parts = explode('_', $key); | ||
$parts = array_map('ucfirst', $parts); | ||
$getter = 'get' . implode('', $parts); | ||
if (!method_exists($this, $getter)) { | ||
throw new Exception\BadMethodCallException( | ||
'The configuration key "' . $key . '" does not ' | ||
. 'have a matching ' . $getter . ' getter method ' | ||
. 'which must be defined' | ||
); | ||
} | ||
return $getter; | ||
} | ||
|
||
/** | ||
* @see ParameterObject::__set() | ||
* @param string $key | ||
* @param mixed $value | ||
* @return void | ||
*/ | ||
public function __set($key, $value) | ||
{ | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
$this->{$setter}($value); | ||
} | ||
|
||
/** | ||
* @see ParameterObject::__get() | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function __get($key) | ||
{ | ||
$getter = $this->assembleGetterNameFromConfigKey($key); | ||
return $this->{$getter}(); | ||
} | ||
|
||
/** | ||
* @see ParameterObject::__isset() | ||
* @param string $key | ||
* @return boolean | ||
*/ | ||
public function __isset($key) | ||
{ | ||
$getter = $this->assembleGetterNameFromConfigKey($key); | ||
return !is_null($this->{$getter}()); | ||
} | ||
|
||
/** | ||
* @see ParameterObject::__unset() | ||
* @param string $key | ||
* @return void | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public function __unset($key) | ||
{ | ||
$setter = $this->assembleSetterNameFromConfigKey($key); | ||
try { | ||
$this->{$setter}(null); | ||
} catch(\InvalidArgumentException $e) { | ||
throw new Exception\InvalidArgumentException( | ||
'The class property $' . $key . ' cannot be unset as' | ||
. ' NULL is an invalid value for it', | ||
0, | ||
$e | ||
); | ||
} | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Stdlib; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
interface ParameterObject | ||
{ | ||
/** | ||
* @param string $key | ||
* @param mixed $value | ||
* @return void | ||
*/ | ||
public function __set($key, $value); | ||
|
||
/** | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function __get($key); | ||
|
||
/** | ||
* @param string $key | ||
* @return boolean | ||
*/ | ||
public function __isset($key); | ||
|
||
/** | ||
* @param string $key | ||
* @return void | ||
*/ | ||
public function __unset($key); | ||
} |