src/TypeHinter.php
public static function to($type, $value, $argNum = 0, $pseudoTypes = [])
    {
        try {
            return lib\Type::to($type, $value, $pseudoTypes);
        } catch (\LogicException $exception) {
            $callerInfomation = self::getCallerInfomation();
            $errorMessage = $callerInfomation['function'] === '__set'
                ? sprintf(
                    'Value set to %s is not of the expected type',
                    $callerInfomation['class'] . '::' . $callerInfomation['args'][0]
                )
                : sprintf(
                    'Argument %d passed to %s is not of the expected type',
                    $argNum + 1,
                    $callerInfomation['class'] . '::' . $callerInfomation['function'] . '()'
                );
            if ($exception instanceof \DomainException) {
                throw new \DomainException($errorMessage, 0, $exception);
            } elseif ($exception instanceof \InvalidArgumentException) {
                throw new \InvalidArgumentException($errorMessage, 0, $exception);
            } else {
                throw $exception;
            }
        }
    }
public static function to($type, $value, $argNum = 0, $pseudoTypes = [])
    {
        try {
            return lib\Type::to($type, $value, $pseudoTypes);
        } catch (\LogicException $exception) {
            $callerInfomation = self::getCallerInfomation();
            $errorMessage = $callerInfomation['function'] === '__set'
                ? sprintf(
                    'Value set to %s is not of the expected type',
                    $callerInfomation['class'] . '::' . $callerInfomation['args'][0]
                )
                : sprintf(
                    'Argument %d passed to %s is not of the expected type',
                    $argNum + 1,
                    $callerInfomation['class'] . '::' . $callerInfomation['function'] . '()'
                );
            if ($exception instanceof \DomainException) {
                throw new \DomainException($errorMessage, 0, $exception);
            } elseif ($exception instanceof \InvalidArgumentException) {
                throw new \InvalidArgumentException($errorMessage, 0, $exception);
            } else {
                throw $exception;
            }
        }
    }
public static function to ( $ type , $ value , $ argNum = 0 , $ pseudoTypes = [ ] ) { try { return lib \ Type :: to ( $ type , $ value , $ pseudoTypes ) ; } catch ( \ LogicException $ exception ) { $ callerInfomation = self :: getCallerInfomation ( ) ; $ errorMessage = $ callerInfomation [ 'function' ] === '__set' ? sprintf ( 'Value set to %s is not of the expected type' , $ callerInfomation [ 'class' ] . '::' . $ callerInfomation [ 'args' ] [ 0 ] ) : sprintf ( 'Argument %d passed to %s is not of the expected type' , $ argNum + 1 , $ callerInfomation [ 'class' ] . '::' . $ callerInfomation [ 'function' ] . '()' ) ; if ( $ exception instanceof \ DomainException ) { throw new \ DomainException ( $ errorMessage , 0 , $ exception ) ; } elseif ( $ exception instanceof \ InvalidArgumentException ) { throw new \ InvalidArgumentException ( $ errorMessage , 0 , $ exception ) ; } else { throw $ exception ; } } }
Converts a given value in accordance with a given IDL type.
@link https://github.com/esperecyan/webidl/blob/master/README.md#esperecyanwebidltypehintertotype-value-argnum-pseudotypes webidl/README.md at master · esperecyan/webidl
@param string $type The IDL type.
@param mixed $value The value being converted.
@param int $argNum The argument offset that received the value being converted.
Arguments are counted starting from zero.  If the caller method is __set(), this argument are ignored.
@param (string|string[]|array)[] The associative array with the identifiers of
callback interface types, enumeration types, callback function types or dictionary types
(the strings passed in $type) as key.
For the corresponding values, see the link.
@throws \InvalidArgumentException
If $value is not castable. The exception includes a message with method name etc.
@throws \DomainException If $value is not castable. The exception includes a message with method name etc.
@return mixed
Converts a given value in accordance with a given IDL type .