Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 56 changed files with 736 additions and 732 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendframework/zend-stdlib",
"description": "Zend\\Stdlib component",
"description": " ",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
Expand All @@ -9,11 +9,11 @@
"homepage": "https://github.com/zendframework/zend-stdlib",
"autoload": {
"psr-4": {
"Zend\\Stdlib\\": "src/"
"Zend\\Stdlib": "src/"
}
},
"require": {
"php": ">=5.3.23"
"php": ">=5.3.3"
},
"require-dev": {
"zendframework/zend-eventmanager": "self.version",
Expand Down
102 changes: 47 additions & 55 deletions src/Options.php → src/AbstractOptions.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

namespace Zend\Stdlib;
Expand All @@ -25,14 +15,20 @@
/**
* @category Zend
* @package Zend_Stdlib
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Options implements ParameterObjectInterface
abstract class AbstractOptions implements ParameterObjectInterface
{
/**
* We use the __ prefix to avoid collisions with properties in
* user-implmentations.
*
* @var bool
*/
protected $__strictMode__ = true;

/**
* @param array|Traversable|null $options
* @return Options
* @return AbstractOptions
* @throws Exception\InvalidArgumentException
*/
public function __construct($options = null)
Expand Down Expand Up @@ -61,43 +57,23 @@ public function setFromArray($options)
}

/**
* @param string $key name of option with underscore
* @return string name of setter method
* @throws Exception\BadMethodCallException if setter method is undefined
* Cast to array
*
* @return array
*/
protected function assembleSetterNameFromKey($key)
public function toArray()
{
$parts = explode('_', $key);
$parts = array_map('ucfirst', $parts);
$setter = 'set' . implode('', $parts);
if (!method_exists($this, $setter)) {
throw new Exception\BadMethodCallException(
'The option "' . $key . '" does not '
. 'have a matching ' . $setter . ' setter method '
. 'which must be defined'
);
$array = array();
$transform = function($letters) {
$letter = array_shift($letters);
return '_' . strtolower($letter);
};
foreach ($this as $key => $value) {
if ($key === '__strictMode__') continue;
$normalizedKey = preg_replace_callback('/([A-Z])/', $transform, $key);
$array[$normalizedKey] = $value;
}
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 assembleGetterNameFromKey($key)
{
$parts = explode('_', $key);
$parts = array_map('ucfirst', $parts);
$getter = 'get' . implode('', $parts);
if (!method_exists($this, $getter)) {
throw new Exception\BadMethodCallException(
'The option "' . $key . '" does not '
. 'have a matching ' . $getter . ' getter method '
. 'which must be defined'
);
}
return $getter;
return $array;
}

/**
Expand All @@ -108,7 +84,16 @@ protected function assembleGetterNameFromKey($key)
*/
public function __set($key, $value)
{
$setter = $this->assembleSetterNameFromKey($key);
$setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
if ($this->__strictMode__ && !method_exists($this, $setter)) {
throw new Exception\BadMethodCallException(
'The option "' . $key . '" does not '
. 'have a matching ' . $setter . ' setter method '
. 'which must be defined'
);
} elseif (!$this->__strictMode__ && !method_exists($this, $setter)) {
return;
}
$this->{$setter}($value);
}

Expand All @@ -119,7 +104,14 @@ public function __set($key, $value)
*/
public function __get($key)
{
$getter = $this->assembleGetterNameFromKey($key);
$getter = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
if (!method_exists($this, $getter)) {
throw new Exception\BadMethodCallException(
'The option "' . $key . '" does not '
. 'have a matching ' . $getter . ' getter method '
. 'which must be defined'
);
}
return $this->{$getter}();
}

Expand Down
28 changes: 8 additions & 20 deletions src/ArraySerializableInterface.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

namespace Zend\Stdlib;

/**
* @category Zend
* @package Zend_Stdlib
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ArraySerializableInterface
{
/**
* Exchange internal values from provided array
*
* @param array $array
*
* @param array $array
* @return void
*/
public function exchangeArray(array $array);

/**
* Return an array representation of the object
*
*
* @return array
*/
public function getArrayCopy();
Expand Down
26 changes: 7 additions & 19 deletions src/ArrayStack.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

namespace Zend\Stdlib;
Expand All @@ -28,17 +18,15 @@
*
* @category Zend
* @package Zend_Stdlib
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ArrayStack extends ArrayObject
{
/**
* Retrieve iterator
*
* Retrieve an array copy of the object, reverse its order, and return an
* Retrieve an array copy of the object, reverse its order, and return an
* ArrayIterator with that reversed array.
*
*
* @return ArrayIterator
*/
public function getIterator()
Expand Down
38 changes: 13 additions & 25 deletions src/ArrayUtils.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

namespace Zend\Stdlib;
Expand All @@ -29,8 +19,6 @@
*
* @category Zend
* @package Zend_Stdlib
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class ArrayUtils
{
Expand All @@ -45,7 +33,7 @@ public static function hasStringKeys($value, $allowEmpty = false)
{
if (!is_array($value)) {
return false;
}
}

if (!$value) {
return $allowEmpty;
Expand All @@ -65,7 +53,7 @@ public static function hasIntegerKeys($value, $allowEmpty = false)
{
if (!is_array($value)) {
return false;
}
}

if (!$value) {
return $allowEmpty;
Expand All @@ -92,8 +80,8 @@ public static function hasNumericKeys($value, $allowEmpty = false)
{
if (!is_array($value)) {
return false;
}
}

if (!$value) {
return $allowEmpty;
}
Expand Down Expand Up @@ -125,8 +113,8 @@ public static function isList($value, $allowEmpty = false)
{
if (!is_array($value)) {
return false;
}
}

if (!$value) {
return $allowEmpty;
}
Expand Down Expand Up @@ -167,8 +155,8 @@ public static function isHashTable($value, $allowEmpty = false)
{
if (!is_array($value)) {
return false;
}
}

if (!$value) {
return $allowEmpty;
}
Expand Down
Loading

0 comments on commit 16d67da

Please sign in to comment.