Skip to content

Commit

Permalink
added count() to config class
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgaro committed Nov 3, 2014
1 parent b334ef8 commit f62c5ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion phalcon/config.zep
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use Phalcon\Config\Exception;
*</code>
*
*/
class Config implements \ArrayAccess
class Config implements \ArrayAccess, \Countable
{

/**
Expand Down Expand Up @@ -199,6 +199,24 @@ class Config implements \ArrayAccess
return arrayConfig;
}

/**
* Returns the count of properties set in the config
*
*<code>
* print count($config);
*</code>
*
* or
*
*<code>
* print $config->count();
*</code>
*/
public function count()
{
return count(get_object_vars(this));
}

/**
* Restores the state of a Phalcon\Config object
*/
Expand Down
13 changes: 13 additions & 0 deletions unit-tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ public function testConfigMerge()

}

public function testConfigCount()
{

$config = new Phalcon\Config(array(
"controllersDir" => "../x/y/z",
"modelsDir" => "../x/y/z",
));


$this->assertEquals(2, count($config));

}

public function testIniConfigDirective()
{
$config = new \Phalcon\Config\Adapter\Ini('unit-tests/config/directive.ini');
Expand Down

0 comments on commit f62c5ce

Please sign in to comment.