Permalink
Browse files

Docs, refactoring

  • Loading branch information...
kakserpom committed Mar 20, 2013
1 parent a7dab17 commit f6af40ba5b2a28d34c979b660a151fb5e0022a22
Showing with 113 additions and 22 deletions.
  1. +2 −2 lib/ConnectionPool.php
  2. +58 −11 lib/Daemon_ConfigParser.php
  3. +53 −9 lib/Daemon_ConfigSection.php
View
@@ -275,7 +275,7 @@ public function finish() {
* @param [mixed Info]
* @return void
*/
- public function attachBound($bound, $inf = null) {
+ public function attachBound(BoundSocket $bound, $inf = null) {
$this->bound->attach($bound, $inf);
}
@@ -284,7 +284,7 @@ public function attachBound($bound, $inf = null) {
* @param BoundSocket
* @return void
*/
- public function detachBound($bound) {
+ public function detachBound(BoundSocket $bound) {
$this->bound->detach($bound);
}
@@ -17,27 +17,74 @@ class Daemon_ConfigParser {
const T_BLOCK = 5;
const T_CVALUE = 5;
+ /**
+ * Config file path
+ * @var string
+ */
protected $file;
+
+ /**
+ * Current line number
+ * @var number
+ */
protected $line = 1;
+
+ /**
+ * Current column number
+ * @var number
+ */
protected $col = 1;
+
+ /**
+ * Pointer (current offset)
+ * @var integer
+ */
protected $p = 0;
+
+ /**
+ * State stack
+ * @var array
+ */
protected $state = [];
- protected $result;
+
+ /**
+ * Target object
+ * @var object
+ */
+ protected $target;
+
+ /**
+ * Errorneous?
+ * @var boolean
+ */
protected $erroneous = false;
+ /**
+ * Errorneous?
+ * @return boolean
+ */
public function isErrorneous() {
return $this->erroneous;
}
- public static function parse($file, $config, $included = false) {
- return new self($file, $config, $included);
+
+ /**
+ * Parse config file
+ * @param string File path
+ * @param object Target
+ * @param boolean Included? Default is false
+ * @return Daemon_ConfigParser
+ */
+ public static function parse($file, $target, $included = false) {
+ return new self($file, $target, $included);
}
+
/**
* Constructor
* @return void
*/
- public function __construct($file, $config, $included = false) {
+ public function __construct($file, $target, $included = false) {
$this->file = $file;
- $this->result = $config;
+ $this->target = $target;
$this->revision = ++Daemon_Config::$lastRevision;
$this->data = file_get_contents($file);
@@ -51,7 +98,7 @@ public function __construct($file, $config, $included = false) {
$this->data = str_replace("\r", '', $this->data);
$this->len = strlen($this->data);
- $this->state[] = [self::T_ALL, $this->result];
+ $this->state[] = [self::T_ALL, $this->target];
$this->tokens = [
self::T_COMMENT => function($c) {
if ($c === "\n") {
@@ -263,7 +310,7 @@ public function __construct($file, $config, $included = false) {
$this->token($e[0], $c);
}
if (!$included) {
- $this->purgeScope($this->result);
+ $this->purgeScope($this->target);
}
}
@@ -328,15 +375,15 @@ public function raiseError($msg, $level = 'emerg', $line = null, $col = null) {
* Executes token server.
* @return mixed|void
*/
- public function token($token, $c) {
+ protected function token($token, $c) {
return call_user_func($this->tokens[$token], $c);
}
/**
* Current character.
* @return string Character.
*/
- public function getCurrentChar() {
+ protected function getCurrentChar() {
$c = substr($this->data, $this->p, 1);
if ($c === "\n") {
@@ -353,7 +400,7 @@ public function getCurrentChar() {
* Returns next character.
* @return string Character.
*/
- public function getNextChar() {
+ protected function getNextChar() {
return substr($this->data, $this->p + 1, 1);
}
@@ -362,7 +409,7 @@ public function getNextChar() {
* @param integer Number of characters to rewind back.
* @return void
*/
- public function rewind($n) {
+ protected function rewind($n) {
$this->p -= $n;
}
}
@@ -13,6 +13,11 @@ class Daemon_ConfigSection implements ArrayAccess, Countable {
public $source;
public $revision;
+ /**
+ * Constructor
+ * @param hash
+ * @return object
+ */
public function __construct($arr = []) {
foreach ($arr as $k => $v) {
if (!is_object($v)) {
@@ -25,6 +30,10 @@ public function __construct($arr = []) {
}
}
+ /**
+ * Count elements
+ * @return number
+ */
public function count() {
$c = 0;
@@ -35,6 +44,10 @@ public function count() {
return $c;
}
+ /**
+ * toArray handler
+ * @return hash
+ */
public function toArray() {
$arr = [];
foreach ($this as $k => $entry) {
@@ -46,24 +59,55 @@ public function toArray() {
return $arr;
}
- public function getRealOffsetName($offset) {
+ /**
+ * Get real property name
+ * @param string Property name
+ * @return string Real property name
+ */
+ public function getRealPropertyName($prop) {
return str_replace('-', '', strtolower($offset));
}
- public function offsetExists($offset) {
- return $this->offsetGet($offset) !== null;
+ /**
+ * Checks if property exists
+ * @param string Property name
+ * @return boolean Exists?
+ */
+
+ public function offsetExists($prop) {
+ $prop = $this->getRealPropertyName($prop);
+ return propery_exists($this, $prop);
}
- public function offsetGet($offset) {
- return $this->{$this->getRealOffsetName($offset)}->value;
+ /**
+ * Get property by name
+ * @param string Property name
+ * @return mixed
+ */
+ public function offsetGet($prop) {
+ $prop = $this->getRealPropertyName($prop);
+ return isset($this->{$prop}) ? $this->{$prop}->value : null;
}
- public function offsetSet($offset,$value) {
- $this->{$this->getRealOffsetName($offset)} = $value;
+ /**
+ * Set property
+ * @param string Property name
+ * @param mixed Value
+ * @return void
+ */
+ public function offsetSet($prop,$value) {
+ $prop = $this->getRealPropertyName($prop);
+ $this->{$prop} = $value;
}
- public function offsetUnset($offset) {
- unset($this->{$this->getRealOffsetName($offset)});
+ /**
+ * Unset property
+ * @param string Property name
+ * @return void
+ */
+ public function offsetUnset($prop) {
+ $prop = $this->getRealPropertyName($prop);
+ unset($this->{$prop});
}
/**

0 comments on commit f6af40b

Please sign in to comment.