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

Commit

Permalink
Merge branch 'hotfix/stdlib-hydrator-class-methods-has-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 30, 2012
2 parents 3216d58 + 84f977f commit 4384d8d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 42 deletions.
36 changes: 10 additions & 26 deletions README.md
Expand Up @@ -4,32 +4,16 @@ Master: [![Build Status](https://secure.travis-ci.org/zendframework/zf2.png?bran

## RELEASE INFORMATION

*Zend Framework 2.0.0rc7*

This is the seventh release candidate for 2.0.0. At this time, we anticipate
that this will be the final release candidate before issuing a stable release.
We highly recommend testing your production applications against it.

XX August 2012

### UPDATES IN RC7

- Zend\Di
- Fixes ArrayDefinition and ClassDefinition hasMethods() methods to return
boolean values.
- Zend\Form
- Fixes issue with multi-checkbox rendering.
- Zend\Ldap
- Fixes an error nesting condition
- Zend\Log
- Fixes an issue with Zend\Log\Formatter\Simple whereby it was using a legacy
key ("info") instead of the key standardized upon in ZF2 ("extra").
- Simple formatter now defaults to JSON-encoding for array and object
serialization (prevents issues with some writers.)
- Zend\Mvc
- Fixes an issue in the ViewHelperManagerFactory whereby a condition was
testing against an uninitialized value.
- Added zend-console to composer.json dependencies.
*Zend Framework 2.0.1*

This is the first maintenance release for the 2.0 series.

XX YYYY 2012

### UPDATES IN 2.0.1

- Zend\Stdlib
- Adds support for "has" methods to ClassMethods hydrator

More than XX pull requests for a variety of features and bugfixes were handled
since RC6, as well as almost XX documentation changes!
Expand Down
29 changes: 13 additions & 16 deletions library/Zend/Stdlib/Hydrator/ClassMethods.php
Expand Up @@ -58,31 +58,28 @@ public function extract($object)
};
$attributes = array();
$methods = get_class_methods($object);

foreach ($methods as $method) {
if (preg_match('/^get[A-Z]\w*/', $method)) {
if (!preg_match('/^(get|has|is)[A-Z]\w*/', $method)) {
continue;
}
if (preg_match('/^get/', $method)) {
// setter verification
$setter = preg_replace('/^get/', 'set', $method);
if (!in_array($setter, $methods)) {
continue;
}
$attribute = substr($method, 3);
$attribute = lcfirst($attribute);
if ($this->underscoreSeparatedKeys) {
$attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute);
}
$attributes[$attribute] = $this->extractValue($attribute, $object->$method());
} elseif (preg_match('/^is[A-Z]\w*/', $method)) {
} else {
// setter verification
$setter = 'set' . ucfirst($method);
if (!in_array($setter, $methods)) {
continue;
}
$attribute = $method;
if ($this->underscoreSeparatedKeys) {
$attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute);
}
$attributes[$attribute] = $this->extractValue($attribute, $object->$method());
}
if (!in_array($setter, $methods)) {
continue;
}
if ($this->underscoreSeparatedKeys) {
$attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute);
}
$attributes[$attribute] = $this->extractValue($attribute, $object->$method());
}

return $attributes;
Expand Down
22 changes: 22 additions & 0 deletions tests/ZendTest/Stdlib/HydratorTest.php
Expand Up @@ -60,10 +60,14 @@ public function testInitiateValues()
$this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), '2');
$this->assertEquals($this->classMethodsCamelCase->getIsFoo(), true);
$this->assertEquals($this->classMethodsCamelCase->isBar(), true);
$this->assertEquals($this->classMethodsCamelCase->getHasFoo(), true);
$this->assertEquals($this->classMethodsCamelCase->hasBar(), true);
$this->assertEquals($this->classMethodsUnderscore->getFooBar(), '1');
$this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), '2');
$this->assertEquals($this->classMethodsUnderscore->getIsFoo(), true);
$this->assertEquals($this->classMethodsUnderscore->isBar(), true);
$this->assertEquals($this->classMethodsUnderscore->getHasFoo(), true);
$this->assertEquals($this->classMethodsUnderscore->hasBar(), true);
}

public function testHydratorReflection()
Expand Down Expand Up @@ -95,12 +99,18 @@ public function testHydratorClassMethodsCamelCase()
$this->assertEquals($datas['isFoo'], true);
$this->assertTrue(isset($datas['isBar']));
$this->assertEquals($datas['isBar'], true);
$this->assertTrue(isset($datas['hasFoo']));
$this->assertEquals($datas['hasFoo'], true);
$this->assertTrue(isset($datas['hasBar']));
$this->assertEquals($datas['hasBar'], true);
$test = $hydrator->hydrate(
array(
'fooBar' => 'foo',
'fooBarBaz' => 'bar',
'isFoo' => false,
'isBar' => false,
'hasFoo' => false,
'hasBar' => false,
),
$this->classMethodsCamelCase
);
Expand All @@ -109,6 +119,8 @@ public function testHydratorClassMethodsCamelCase()
$this->assertEquals($test->getFooBarBaz(), 'bar');
$this->assertEquals($test->getIsFoo(), false);
$this->assertEquals($test->isBar(), false);
$this->assertEquals($test->getHasFoo(), false);
$this->assertEquals($test->hasBar(), false);
}

public function testHydratorClassMethodsCamelCaseWithSetterMissing()
Expand Down Expand Up @@ -139,12 +151,20 @@ public function testHydratorClassMethodsUnderscore()
$this->assertTrue(isset($datas['is_bar']));
$this->assertFalse(isset($datas['isBar']));
$this->assertEquals($datas['is_bar'], true);
$this->assertTrue(isset($datas['has_foo']));
$this->assertFalse(isset($datas['hasFoo']));
$this->assertEquals($datas['has_foo'], true);
$this->assertTrue(isset($datas['has_bar']));
$this->assertFalse(isset($datas['hasBar']));
$this->assertEquals($datas['has_bar'], true);
$test = $hydrator->hydrate(
array(
'foo_bar' => 'foo',
'foo_bar_baz' => 'bar',
'is_foo' => false,
'is_bar' => false,
'has_foo' => false,
'has_bar' => false,
),
$this->classMethodsUnderscore
);
Expand All @@ -153,6 +173,8 @@ public function testHydratorClassMethodsUnderscore()
$this->assertEquals($test->getFooBarBaz(), 'bar');
$this->assertEquals($test->getIsFoo(), false);
$this->assertEquals($test->isBar(), false);
$this->assertEquals($test->getHasFoo(), false);
$this->assertEquals($test->hasBar(), false);
}

public function testHydratorClassMethodsIgnoresInvalidValues()
Expand Down
26 changes: 26 additions & 0 deletions tests/ZendTest/Stdlib/TestAsset/ClassMethodsCamelCase.php
Expand Up @@ -20,6 +20,10 @@ class ClassMethodsCamelCase

protected $isBar = true;

protected $hasFoo = true;

protected $hasBar = true;

public function getFooBar()
{
return $this->fooBar;
Expand Down Expand Up @@ -63,4 +67,26 @@ public function setIsBar($value)
$this->isBar = $value;
return $this;
}

public function getHasFoo()
{
return $this->hasFoo;
}

public function setHasFoo($value)
{
$this->hasFoo = $value;
return $this;
}

public function hasBar()
{
return $this->hasBar;
}

public function setHasBar($value)
{
$this->hasBar = $value;
return $this;
}
}
26 changes: 26 additions & 0 deletions tests/ZendTest/Stdlib/TestAsset/ClassMethodsUnderscore.php
Expand Up @@ -20,6 +20,10 @@ class ClassMethodsUnderscore

protected $is_bar = true;

protected $has_foo = true;

protected $has_bar = true;

public function getFooBar()
{
return $this->foo_bar;
Expand Down Expand Up @@ -63,4 +67,26 @@ public function setIsBar($value)
$this->is_bar = $value;
return $this;
}

public function getHasFoo()
{
return $this->has_foo;
}

public function setHasFoo($value)
{
$this->has_foo = $value;
return $this;
}

public function hasBar()
{
return $this->has_bar;
}

public function setHasBar($value)
{
$this->has_bar = $value;
return $this;
}
}

0 comments on commit 4384d8d

Please sign in to comment.