Compare commits

...

2 commits

Author SHA1 Message Date
942f8a4bde make Settings countable 2023-09-21 09:18:05 +02:00
82346bc36f output errors to STDERR 2023-09-21 09:17:26 +02:00
2 changed files with 16 additions and 5 deletions

View file

@ -22,7 +22,7 @@ foreach ($autoloadFiles as $autoloadFile) {
} }
} }
$version = '0.2'; $version = '0.3';
$actions = [ 'show', 'write', 'help' ]; $actions = [ 'show', 'write', 'help' ];
$settings = ['key' => '', 'value' => '']; $settings = ['key' => '', 'value' => ''];
@ -158,7 +158,7 @@ try {
exit(0); exit(0);
} }
} }
echo $ex->getMessage().PHP_EOL; fwrite(STDERR, $ex->getMessage().PHP_EOL);
exit(1); exit(1);
} }
@ -204,7 +204,7 @@ try {
$cfg->load(require($cfgFile)); $cfg->load(require($cfgFile));
} }
} catch (Exception $e) { } catch (Exception $e) {
echo "Error: ".$e->getMessage()."\n"; fwrite(STDERR, "Error: ".$e->getMessage().PHP_EOL);
exit(1); exit(1);
} }
//var_dump($cfg); //var_dump($cfg);
@ -220,7 +220,7 @@ if ($settings['key'])
$result = $result->{$setting}; $result = $result->{$setting};
} }
catch (\OutOfRangeException $e) { catch (\OutOfRangeException $e) {
echo $e->getMessage().PHP_EOL; fwrite(STDERR, $e->getMessage().PHP_EOL);
exit(1); exit(1);
} }
} }

View file

@ -26,7 +26,7 @@ namespace rabe\Util;
* Settings Class to read Configuration Files * Settings Class to read Configuration Files
* @author Norbert.e.Wagner dev@norb.me * @author Norbert.e.Wagner dev@norb.me
*/ */
class Settings implements \Iterator class Settings implements \Iterator, \Countable
{ {
private const SITE = 0x01; private const SITE = 0x01;
@ -314,6 +314,17 @@ class Settings implements \Iterator
// }}} // }}}
// Countable {{{
/**
* Count elements
* @link https://www.php.net/countable.count.php
*/
public function count()
{
count($this->settings);
}
// }}}
// Magic getter/setter methods {{{ // Magic getter/setter methods {{{
public function __set( $name, $value ) public function __set( $name, $value )
{ {