final class Arr
{
- public static function get($array, $key, $default=null)
+ /**
+ * @param array $array
+ * @param string|integer $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public static function get(array $array, $key, $default=null)
{
if (array_key_exists($key, $array))
return $array[$key];
return $default;
}
- public static function ensureKeyExists(&$array, $key, $default=null)
+ /**
+ * @param array $array
+ * @param string|integer $key
+ * @param mixed $default
+ */
+ public static function ensureKeyExists(array &$array, $key, $default=null)
{
if (!array_key_exists($key, $array))
- return $array[$key] = $default;
+ $array[$key] = $default;
}
- public static function pushToKey(&$array, $key, $value)
+ /**
+ * @param array $array
+ * @param string|integer $key
+ * @param mixed $value
+ */
+ public static function pushToKey(array &$array, $key, $value)
{
if (array_key_exists($key, $array))
- return $array[$key][] = $value;
+ $array[$key][] = $value;
else
- return $array[$key] = array($value);
+ $array[$key] = array($value);
}
- public static function pop(&$array, $key, $default=null)
+ /**
+ * @param array $array
+ * @param string|integer $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public static function pop(array &$array, $key, $default=null)
{
if (array_key_exists($key, $array)) {
$value = $array[$key];
}
}
- public static function flatten($array)
+ /**
+ * @param array $array
+ * @return array
+ */
+ public static function flatten(array $array)
{
$result = array();
array_walk_recursive($array, function ($value) use (&$result) {
return $result;
}
- public static function pluck($array, $key)
+ /**
+ * @param array $array
+ * @param string|integer $key
+ * @return array
+ */
+ public static function pluck(array $array, $key)
{
$result = array();
foreach ($array as $item)
return $result;
}
}
-
return $argv;
if (@is_array($_SERVER['argv']))
return $_SERVER['argv'];
- throw new Exception("Could not read command arguments (register_argc_argv=Off?)");
+ throw new \Exception("Could not read command arguments (register_argc_argv=Off?)");
}
protected abstract function commands();
}
}
}
-
switch ($name) {
case 'set':
$this->values[$args[0]] = array('value', $args[1]);
- break;
+ return $this;
case 'setFunction':
$this->values[$args[0]] = array('function', $args[1]);
- break;
+ return $this;
case 'setFactory':
$this->values[$args[0]] = array('factory', $args[1]);
- break;
+ return $this;
default:
return $this->getWithArgs($name, $args);
}
return call_user_func_array(array(self::getInstance(), $name), $args);
}
}
-
$result .= ' '.$controls[6];
break;
default:
- throw new Exception('Bad time format');
+ throw new \Exception('Bad time format');
}
return $result;
}
class Text
{
+ /**
+ * @param string $text
+ * @return string
+ */
public static function escape($text)
{
return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
{
private $name, $selfClose, $attributes, $inner=array();
+ /**
+ * @param string $name
+ * @param array $attributes
+ * @param mixed|null $inner
+ */
public function __construct($name, $attributes=array(), $inner=null)
{
$this->name = $name;
$this->append($item);
}
+ /**
+ * @return Tag
+ */
public static function create(/*name[, attributes, [... inner]]*/)
{
$args = func_get_args();
return new Tag($name, $attributes, $args);
}
- public static function __callStatic($method, $args)
+ /**
+ * @param string $name
+ * @param array $args
+ * @return Tag
+ */
+ public static function __callStatic($name, $args)
{
$attributes = array_shift($args);
- return new Tag($method, $attributes, $args);
+ return new Tag($name, $attributes, $args);
}
+ /**
+ * @param string $name
+ * @param string $value
+ * @return Tag
+ */
public function attr($name, $value)
{
$this->attributes[$name] = $value;
return $this;
}
+ /**
+ * @param string $name
+ * @return Tag
+ */
public function unsetAttr($name)
{
unset($this->attributes[$name]);
return $this;
}
- public function attrs($attributes)
+ /**
+ * @param array $attributes dictionary
+ * @return Tag
+ */
+ public function attrs(array $attributes)
{
foreach ($attributes as $k => $v) {
if ($k == 'class') {
$classes = explode(' ', $classes);
return $classes;
}
-
+
+ /**
+ * @param string $class
+ * @return Tag
+ */
public function addClass($class)
{
$classes = $this->getListAttribute('class');
return $this;
}
+ /**
+ * @param string $class
+ * @return Tag
+ */
public function removeClass($class)
{
$classes = $this->getListAttribute('class');
return $this;
}
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param boolean $condition
+ * @return Tag
+ */
public function toggleAttr($name, $value, $condition)
{
return $condition
: $this->unsetAttr($name);
}
+ /**
+ * @param string $class
+ * @param boolean $condition
+ * @return Tag
+ */
public function toggleClass($class, $condition)
{
return $condition
: $this->removeClass($class);
}
+ /**
+ * @param mixed $item
+ * @return Tag
+ */
public function append($item)
{
if (is_array($item)) {
return $this;
}
+ /**
+ * @param string $raw
+ * @return Tag
+ */
public function raw($raw)
{
if (is_array($raw)) {
return $this;
}
+ /**
+ * @return string
+ */
public function html()
{
$s = '<'.$this->name;
return $s;
}
+ /**
+ * @return string
+ */
public function __toString()
{
return $this->html();
}
}
-
{
foreach ($mixins as $class) {
if (!class_exists($class))
- throw new Exception('Tried to inherit non-existant class \''.$class.'\'.');
+ throw new \Exception('Tried to inherit non-existant class \''.$class.'\'.');
$mixin = new $class($object);
$methods = get_class_methods($mixin);
{
$m = strtolower($method);
if (!isset($this->methods[$m]))
- throw new Exception('Call to undefined method ' . get_class($this) . "::$method()");
+ throw new \Exception('Call to undefined method ' . get_class($this) . "::$method()");
$this->current_call_method = $method;
$this->current_call_mixins = $this->methods[$m];
public function call_next_method()
{
if ($this->current_call_mixins === null)
- throw new Exception('call_next_method is invoked outside of mixin method.');
+ throw new \Exception('call_next_method is invoked outside of mixin method.');
$mixin = array_pop($this->current_call_mixins);
if ($mixin === null)
- throw new Exception('No next method for ' . get_class($this) . "::$method()");
+ throw new \Exception('No next method for ' . get_class($this) . "::$method()");
return call_user_func_array(array($mixin, $this->current_call_method), func_get_args());
}
{
public static function call()
{
- return self::callv(func_get_args());
+ self::callv(func_get_args());
}
- public static function callv($command)
+ public static function callv(array $command)
{
$str = '';
foreach ($command as $part) {
proc_close($process);
}
}
-