function __set($key, $value) { if (!_birch_is_valid_var_name($key)) { throw new ErrorException(sprintf('String <%s> is invalid as the sub-namespace or function name in namespace <%s>', $key, $this->ns_string)); } if ($key !== 'ns_string' && (!is_a($value, 'Birch_NSObject') && !is_a($value, 'Birch_Fn'))) { throw new ErrorException(sprintf('Namespace <%s> can only has instances of the Birch_NSObject or Birch_Fn classes.' . ' The given value is <%s>', $this->ns_string, $value)); } $this->{$key} = $value; if (is_a($value, 'Birch_NSObject')) { $pos = strpos($value->ns_string, $this->ns_string); if ($pos === false || $pos !== 0) { throw new ErrorException(sprintf('Namespace <%s> is not a sub namespace of namespace <%s>', $value->ns_string, $this->ns_string)); } $this->sub_ns_keys[] = $key; } }
function __set($key, $value) { if (!_birch_is_valid_var_name($key)) { throw new ErrorException(sprintf('String <%s> is invalid as the sub-namespace or function name in namespace <%s>', $key, $this->ns_string)); } if (!is_a($value, 'Birch_NSObject') && !is_callable($value)) { throw new ErrorException(sprintf('Namespace <%s> can only has namespace object or callable.' . ' The given value is <%s>', $this->ns_string, $value)); } if (isset($this->data[$key]) && is_a($this->data[$key], 'Birch_NSObject')) { throw new ErrorException(sprintf('<%s> has been defined in Namespace <%s> as a sub-namespace and cannot be redefined.', $key, $this->ns_string)); } if (is_a($value, 'Birch_NSObject')) { $pos = strpos($value->ns_string, $this->ns_string); if ($pos === false || $pos !== 0) { throw new ErrorException(sprintf('Namespace <%s> is not a sub namespace of namespace <%s>', $value->ns_string, $this->ns_string)); } $this->data[$key] = $value; if (!in_array($key, $this->sub_ns_keys)) { $this->sub_ns_keys[] = $key; } } elseif (is_callable($value)) { if (isset($this->data[$key])) { $this->data[$key]->_set_default($value); } else { $config = array('ns' => $this, 'name' => $key, 'fn' => $value); $this->data[$key] = new Birch_Fn($config); } } }