Permalink
Browse files

Docs, refactoring

  • Loading branch information...
1 parent 3a14c55 commit 6a92504bebef960a2f76249676e504a8c4e9a25e @kakserpom committed Mar 20, 2013
View
@@ -17,24 +17,42 @@ class Daemon_ConfigEntry {
public $revision;
public $hasDefaultValue = FALSE;
+ /**
+ * Constructor
+ * @return void
+ */
public function __construct() {
if (func_num_args() == 1) {
$this->setDefaultValue(func_get_arg(0));
$this->setHumanValue(func_get_arg(0));
}
}
-
+
+ /**
+ * Set value
+ * @param mixed
+ * @return void
+ */
public function setValue($value) {
$old = $this->value;
$this->value = $value;
- $this->humanValue = $this->PlainToHuman($value);
+ $this->humanValue = static::PlainToHuman($value);
$this->onUpdate($old);
}
+ /**
+ * Set value type
+ * @param mixed
+ * @return void
+ */
public function setValueType($type) {
$this->valueType = $type;
}
+ /**
+ * Reset to default
+ * @return void
+ */
public function resetToDefault() {
if ($this->hasDefaultValue) {
$this->setHumanValue($this->defaultValue);
@@ -45,26 +63,51 @@ public function resetToDefault() {
return false;
}
+
+ /**
+ * Set default value
+ * @param mixed
+ * @return void
+ */
public function setDefaultValue($value) {
$this->defaultValue = $value;
$this->hasDefaultValue = true;
}
+ /**
+ * Set human-readable value
+ * @param mixed
+ * @return void
+ */
public function setHumanValue($value) {
$this->humanValue = $value;
$old = $this->value;
- $this->value = $this->HumanToPlain($value);
+ $this->value = static::HumanToPlain($value);
$this->onUpdate($old);
}
- public function HumanToPlain($value) {
+
+ /**
+ * Converts human-readable value to plain
+ * @param mixed
+ * @return mixed
+ */
+ public static function HumanToPlain($value) {
return $value;
}
- public function PlainToHuman($value) {
+ /**
+ * Converts plain value to human-readable
+ * @param mixed
+ * @return mixed
+ */
+ public static function PlainToHuman($value) {
return $value;
}
- public function onUpdate($old) {
- }
+ /**
+ * Called when
+ * @return void
+ */
+ public function onUpdate($old) {}
}
@@ -10,7 +10,7 @@
*/
class Daemon_ConfigEntryArray extends Daemon_ConfigEntry {
- public function HumanToPlain($value) {
+ public static function HumanToPlain($value) {
if (is_array($value)) {
return $value;
}
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Boolean config entry
+ *
+ * @package Core
+ * @subpackage Config
+ *
+ * @author Zorin Vasily <kak.serpom.po.yaitsam@gmail.com>
+ */
+class Daemon_ConfigEntryBoolean extends Daemon_ConfigEntry {
+
+ public static function HumanToPlain($value) {
+ return (boolean) $value;
+ }
+
+}
@@ -10,7 +10,7 @@
*/
class Daemon_ConfigEntryExtFunc extends Daemon_ConfigEntry {
- public function HumanToPlain($value) {
+ public static function HumanToPlain($value) {
$cb = include($value);
return is_callable($cb) ? $cb : null;
}
@@ -10,7 +10,7 @@
*/
class Daemon_ConfigEntryNumber extends Daemon_ConfigEntry {
- public function HumanToPlain($value) {
+ public static function HumanToPlain($value) {
if ($value === null) {
return null;
}
@@ -10,7 +10,7 @@
*/
class Daemon_ConfigEntrySize extends Daemon_ConfigEntry {
- public function HumanToPlain($value) {
+ public static function HumanToPlain($value) {
$l = substr($value, -1);
if ($l === 'b' || $l === 'B') {
@@ -10,7 +10,7 @@
*/
class Daemon_ConfigEntryTime extends Daemon_ConfigEntry {
- public function HumanToPlain($value) {
+ public static function HumanToPlain($value) {
$time = 0;
preg_replace_callback('~(\d+(\.\d+)?)\s*([smhd])\s*|(.+)~i', function($m) use (&$time) {

0 comments on commit 6a92504

Please sign in to comment.