array = $array; } /** * @return array */ public function keys() { return array_keys( $this->array ); } /** * @param string $name * @param mixed $value */ public function set( $name, $value ) { $this->array[ $name ] = $value; } /** * @param string $name * @param mixed $default * * @return mixed */ public function get( $name, $default = null ) { if( isset( $this->array[ $name ] ) ) { return $this->array[ $name ]; } // allow dot access for nested array keys: key.subkey $array = $this->array; foreach(explode('.', $name) as $segment) { if ( ! array_key_exists( $segment, $array )) { return $default; } $array = $array[$segment]; } return $array; } /** * @return array */ public function all() { return $this->array; } /** * @param $prefix * * @return array */ public function all_with_prefix( $prefix ) { $return = array(); $length = strlen( $prefix ); foreach( $this->array as $key => $value ) { if( strpos( $key, $prefix ) === 0 ) { $new_key = substr( $key, $length ); $return[ $new_key ] = $value; } } return $return; } /** * @param $prefix * @return array */ public function all_without_prefix( $prefix ) { $return = array(); foreach( $this->array as $key => $value ) { if( strpos( $key, $prefix ) !== 0 ) { $return[ $key ] = $value; } } return $return; } }