src/AddressValidation.php
public function validate(Address $address, $requestOption = self::REQUEST_OPTION_ADDRESS_VALIDATION, $maxSuggestion = 15)
    {
        if ($maxSuggestion > 50) {
            throw new \Exception('Maximum of 50 suggestions allowed');
        }

        if (!in_array($requestOption, range(1, 3))) {
            throw new \Exception('Invalid request option supplied');
        }

        $this->address = $address;
        $this->requestOption = $requestOption;
        $this->maxSuggestion = $maxSuggestion;

        $access = $this->createAccess();
        $request = $this->createRequest();

        $this->response = $this->getRequest()->request($access, $request, $this->compileEndpointUrl(self::ENDPOINT));
        $response = $this->response->getResponse();

        if (null === $response) {
            throw new Exception('Failure (0): Unknown error', 0);
        }

        if ($response instanceof SimpleXMLElement && $response->Response->ResponseStatusCode == 0) {
            throw new Exception(
                "Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}",
                (int)$response->Response->Error->ErrorCode
            );
        }
        if ($this->useAVResponseObject) {
            unset($response->Response);
            $avResponse = new AddressValidationResponse($response, $requestOption);
            return $avResponse;
        }
        return $this->formatResponse($response);
    }
public function validate(Address $address, $requestOption = self::REQUEST_OPTION_ADDRESS_VALIDATION, $maxSuggestion = 15)
    {
        if ($maxSuggestion > 50) {
            throw new \Exception('Maximum of 50 suggestions allowed');
        }

        if (!in_array($requestOption, range(1, 3))) {
            throw new \Exception('Invalid request option supplied');
        }

        $this->address = $address;
        $this->requestOption = $requestOption;
        $this->maxSuggestion = $maxSuggestion;

        $access = $this->createAccess();
        $request = $this->createRequest();

        $this->response = $this->getRequest()->request($access, $request, $this->compileEndpointUrl(self::ENDPOINT));
        $response = $this->response->getResponse();

        if (null === $response) {
            throw new Exception('Failure (0): Unknown error', 0);
        }

        if ($response instanceof SimpleXMLElement && $response->Response->ResponseStatusCode == 0) {
            throw new Exception(
                "Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}",
                (int)$response->Response->Error->ErrorCode
            );
        }
        if ($this->useAVResponseObject) {
            unset($response->Response);
            $avResponse = new AddressValidationResponse($response, $requestOption);
            return $avResponse;
        }
        return $this->formatResponse($response);
    }
public function validate ( Address $ address , $ requestOption = self :: REQUEST_OPTION_ADDRESS_VALIDATION , $ maxSuggestion = 15 ) { if ( $ maxSuggestion > 50 ) { throw new \ Exception ( 'Maximum of 50 suggestions allowed' ) ; } if ( ! in_array ( $ requestOption , range ( 1 , 3 ) ) ) { throw new \ Exception ( 'Invalid request option supplied' ) ; } $ this -> address = $ address ; $ this -> requestOption = $ requestOption ; $ this -> maxSuggestion = $ maxSuggestion ; $ access = $ this -> createAccess ( ) ; $ request = $ this -> createRequest ( ) ; $ this -> response = $ this -> getRequest ( ) -> request ( $ access , $ request , $ this -> compileEndpointUrl ( self :: ENDPOINT ) ) ; $ response = $ this -> response -> getResponse ( ) ; if ( null === $ response ) { throw new Exception ( 'Failure (0): Unknown error' , 0 ) ; } if ( $ response instanceof SimpleXMLElement && $ response -> Response -> ResponseStatusCode == 0 ) { throw new Exception ( "Failure ({$response->Response->Error->ErrorSeverity}): {$response->Response->Error->ErrorDescription}" , ( int ) $ response -> Response -> Error -> ErrorCode ) ; } if ( $ this -> useAVResponseObject ) { unset ( $ response -> Response ) ; $ avResponse = new AddressValidationResponse ( $ response , $ requestOption ) ; return $ avResponse ; } return $ this -> formatResponse ( $ response ) ; }
Get address suggestions from UPS using the 'Street Level' Address Validation API (/XAV)

@param Address $address
@param int $requestOption
@param int $maxSuggestion

@throws Exception

@return stdClass|AddressValidationResponse
Get address suggestions from UPS using the Street Level Address Validation API ( / XAV )