Index: tests/Zend/Filter/InflectorTest.php =================================================================== --- tests/Zend/Filter/InflectorTest.php (revision 21111) +++ tests/Zend/Filter/InflectorTest.php (working copy) @@ -422,7 +422,7 @@ $this->_testOptions($inflector); } - public function testSetConfigSetsStateAndRules() + public function testPassingConfigObjectToSetConfigSetsStateAndRules() { $config = $this->getConfig(); $inflector = new Zend_Filter_Inflector(); @@ -503,7 +503,27 @@ $rules = $this->inflector->getRules('controller'); $this->assertEquals(5, count($rules)); } - + + /** + * @issue ZF-8997 + */ + public function testPassingArrayToConstructorSetsStateAndRules() + { + $options = $this->getOptions(); + $inflector = new Zend_Filter_Inflector($options); + $this->_testOptions($inflector); + } + + /** + * @issue ZF-8997 + */ + public function testPassingArrayToSetConfigSetsStateAndRules() + { + $options = $this->getOptions(); + $inflector = new Zend_Filter_Inflector(); + $inflector->setOptions($options); + $this->_testOptions($inflector); + } } // Call Zend_Filter_InflectorTest::main() if this source file is executed directly. Index: library/Zend/Filter/Inflector.php =================================================================== --- library/Zend/Filter/Inflector.php (revision 21111) +++ library/Zend/Filter/Inflector.php (working copy) @@ -75,6 +75,8 @@ { if ($target instanceof Zend_Config) { $this->setConfig($target); + } else if(is_array($target)) { + $this->setOptions($target); } else { if ((null !== $target) && is_string($target)) { $this->setTarget($target); @@ -128,7 +130,18 @@ */ public function setConfig(Zend_Config $config) { - foreach ($config as $key => $value) { + return $this->setOptions($config->toArray()); + } + + /** + * Use Array object to set object state + * + * @param Array $options + * @return Zend_Filter_Inflector + */ + public function setOptions(Array $options) + { + foreach ($options as $key => $value) { switch ($key) { case 'target': $this->setTarget($value); @@ -137,8 +150,7 @@ if (is_scalar($value)) { break; } - $paths = $value->toArray(); - foreach ($paths as $prefix => $path) { + foreach ($value as $prefix => $path) { $this->addFilterPrefixPath($prefix, $path); } break; @@ -149,7 +161,7 @@ $this->setTargetReplacementIdentifier($value); break; case 'rules': - $this->addRules($value->toArray()); + $this->addRules($value); break; default: break;