src/Radius.php
public function setAttribute($type, $value)
    {
        $index = -1;
        if (is_array($this->attributesToSend)) {
            foreach($this->attributesToSend as $i => $attr) {
                if (is_array($attr)) {
                    $tmp = $attr[0];
                } else {
                    $tmp = $attr;
                }
                if ($type == ord(substr($tmp, 0, 1))) {
                    $index = $i;
                    break;
                }
            }
        }

        $temp = null;

        if (isset($this->attributesInfo[$type])) {
            switch ($this->attributesInfo[$type][1]) {
                case 'T':
                    // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279).
                    $temp = chr($type) . chr(2 + strlen($value)) . $value;
                    break;
                case 'S':
                    // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive).
                    $temp = chr($type) . chr(2 + strlen($value)) . $value;
                    break;
                case 'A':
                    // Address, 32 bit value, most significant octet first.
                    $ip = explode('.', $value);
                    $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]);
                    break;
                case 'I':
                    // Integer, 32 bit unsigned value, most significant octet first.
                    $temp = chr($type) . chr(6) .
                            chr(($value / (256 * 256 * 256)) % 256) .
                            chr(($value / (256 * 256)) % 256) .
                            chr(($value / (256)) % 256) .
                            chr($value % 256);
                    break;
                case 'D':
                    // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC)
                    $temp = null;
                    break;
                default:
                    $temp = null;
            }
        }

        if ($index > -1) {
            if ($type == 26) { // vendor specific
                $this->attributesToSend[$index][] = $temp;
                $action = 'Added';
            } else {
                $this->attributesToSend[$index] = $temp;
                $action = 'Modified';
            }
        } else {
            $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp;
            $action = 'Added';
        }

        $info = $this->getAttributesInfo($type);
        $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>");

        return $this;
    }
public function setAttribute($type, $value)
    {
        $index = -1;
        if (is_array($this->attributesToSend)) {
            foreach($this->attributesToSend as $i => $attr) {
                if (is_array($attr)) {
                    $tmp = $attr[0];
                } else {
                    $tmp = $attr;
                }
                if ($type == ord(substr($tmp, 0, 1))) {
                    $index = $i;
                    break;
                }
            }
        }

        $temp = null;

        if (isset($this->attributesInfo[$type])) {
            switch ($this->attributesInfo[$type][1]) {
                case 'T':
                    // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279).
                    $temp = chr($type) . chr(2 + strlen($value)) . $value;
                    break;
                case 'S':
                    // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive).
                    $temp = chr($type) . chr(2 + strlen($value)) . $value;
                    break;
                case 'A':
                    // Address, 32 bit value, most significant octet first.
                    $ip = explode('.', $value);
                    $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]);
                    break;
                case 'I':
                    // Integer, 32 bit unsigned value, most significant octet first.
                    $temp = chr($type) . chr(6) .
                            chr(($value / (256 * 256 * 256)) % 256) .
                            chr(($value / (256 * 256)) % 256) .
                            chr(($value / (256)) % 256) .
                            chr($value % 256);
                    break;
                case 'D':
                    // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC)
                    $temp = null;
                    break;
                default:
                    $temp = null;
            }
        }

        if ($index > -1) {
            if ($type == 26) { // vendor specific
                $this->attributesToSend[$index][] = $temp;
                $action = 'Added';
            } else {
                $this->attributesToSend[$index] = $temp;
                $action = 'Modified';
            }
        } else {
            $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp;
            $action = 'Added';
        }

        $info = $this->getAttributesInfo($type);
        $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>");

        return $this;
    }
public function setAttribute ( $ type , $ value ) { $ index = - 1 ; if ( is_array ( $ this -> attributesToSend ) ) { foreach ( $ this -> attributesToSend as $ i => $ attr ) { if ( is_array ( $ attr ) ) { $ tmp = $ attr [ 0 ] ; } else { $ tmp = $ attr ; } if ( $ type == ord ( substr ( $ tmp , 0 , 1 ) ) ) { $ index = $ i ; break ; } } } $ temp = null ; if ( isset ( $ this -> attributesInfo [ $ type ] ) ) { switch ( $ this -> attributesInfo [ $ type ] [ 1 ] ) { case 'T' : // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). $ temp = chr ( $ type ) . chr ( 2 + strlen ( $ value ) ) . $ value ; break ; case 'S' : // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). $ temp = chr ( $ type ) . chr ( 2 + strlen ( $ value ) ) . $ value ; break ; case 'A' : // Address, 32 bit value, most significant octet first. $ ip = explode ( '.' , $ value ) ; $ temp = chr ( $ type ) . chr ( 6 ) . chr ( $ ip [ 0 ] ) . chr ( $ ip [ 1 ] ) . chr ( $ ip [ 2 ] ) . chr ( $ ip [ 3 ] ) ; break ; case 'I' : // Integer, 32 bit unsigned value, most significant octet first. $ temp = chr ( $ type ) . chr ( 6 ) . chr ( ( $ value / ( 256 * 256 * 256 ) ) % 256 ) . chr ( ( $ value / ( 256 * 256 ) ) % 256 ) . chr ( ( $ value / ( 256 ) ) % 256 ) . chr ( $ value % 256 ) ; break ; case 'D' : // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) $ temp = null ; break ; default : $ temp = null ; } } if ( $ index > - 1 ) { if ( $ type == 26 ) { // vendor specific $ this -> attributesToSend [ $ index ] [ ] = $ temp ; $ action = 'Added' ; } else { $ this -> attributesToSend [ $ index ] = $ temp ; $ action = 'Modified' ; } } else { $ this -> attributesToSend [ ] = ( $ type == 26 /* vendor specific */ ) ? array ( $ temp ) : $ temp ; $ action = 'Added' ; } $ info = $ this -> getAttributesInfo ( $ type ) ; $ this -> debugInfo ( "{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>" ) ; return $ this ; }
Set an arbitrary RADIUS attribute to be sent in the next packet.

@param number $type  The number of the RADIUS attribute
@param mixed  $value  The value of the attribute
@return \Dapphp\Radius\Radius
Set an arbitrary RADIUS attribute to be sent in the next packet .