src/LearnositySdk/Request/Init.php
public function validate($service, &$securityPacket, $secret, $requestPacket, $action)
    {
        if (empty($service)) {
            throw new ValidationException('The `service` argument wasn\'t found or was empty');
        } elseif (!in_array(strtolower($service), $this->validServices)) {
            throw new ValidationException("The service provided ($service) is not valid");
        }

        // In case the user gave us a JSON securityPacket, convert to an array
        if (!is_array($securityPacket) && is_string($securityPacket)) {
            $securityPacket = json_decode($securityPacket, true);
        }

        if (empty($securityPacket) || !is_array($securityPacket)) {
            throw new ValidationException('The security packet must be an array');
        } else {
            foreach (array_keys($securityPacket) as $key) {
                if (!in_array($key, $this->validSecurityKeys)) {
                    throw new ValidationException('Invalid key found in the security packet: ' . $key);
                }
            }
            if ($service === "questions" && !array_key_exists('user_id', $securityPacket)) {
                throw new ValidationException('Questions API requires a `user_id` in the security packet');
            }

            if (!array_key_exists('timestamp', $securityPacket)) {
                $securityPacket['timestamp'] = gmdate('Ymd-Hi');
            }
        }

        if (empty($secret) || !is_string($secret)) {
            throw new ValidationException('The `secret` argument must be a valid string');
        }

        if (!empty($requestPacket) && !is_array($requestPacket)) {
            throw new ValidationException('The request packet must be an array or a valid JSON string');
        }

        if (!empty($action) && !is_string($action)) {
            throw new ValidationException('The `action` argument must be a string');
        }
    }
public function validate($service, &$securityPacket, $secret, $requestPacket, $action)
    {
        if (empty($service)) {
            throw new ValidationException('The `service` argument wasn\'t found or was empty');
        } elseif (!in_array(strtolower($service), $this->validServices)) {
            throw new ValidationException("The service provided ($service) is not valid");
        }

        // In case the user gave us a JSON securityPacket, convert to an array
        if (!is_array($securityPacket) && is_string($securityPacket)) {
            $securityPacket = json_decode($securityPacket, true);
        }

        if (empty($securityPacket) || !is_array($securityPacket)) {
            throw new ValidationException('The security packet must be an array');
        } else {
            foreach (array_keys($securityPacket) as $key) {
                if (!in_array($key, $this->validSecurityKeys)) {
                    throw new ValidationException('Invalid key found in the security packet: ' . $key);
                }
            }
            if ($service === "questions" && !array_key_exists('user_id', $securityPacket)) {
                throw new ValidationException('Questions API requires a `user_id` in the security packet');
            }

            if (!array_key_exists('timestamp', $securityPacket)) {
                $securityPacket['timestamp'] = gmdate('Ymd-Hi');
            }
        }

        if (empty($secret) || !is_string($secret)) {
            throw new ValidationException('The `secret` argument must be a valid string');
        }

        if (!empty($requestPacket) && !is_array($requestPacket)) {
            throw new ValidationException('The request packet must be an array or a valid JSON string');
        }

        if (!empty($action) && !is_string($action)) {
            throw new ValidationException('The `action` argument must be a string');
        }
    }
public function validate ( $ service , & $ securityPacket , $ secret , $ requestPacket , $ action ) { if ( empty ( $ service ) ) { throw new ValidationException ( 'The `service` argument wasn\'t found or was empty' ) ; } elseif ( ! in_array ( strtolower ( $ service ) , $ this -> validServices ) ) { throw new ValidationException ( "The service provided ($service) is not valid" ) ; } // In case the user gave us a JSON securityPacket, convert to an array if ( ! is_array ( $ securityPacket ) && is_string ( $ securityPacket ) ) { $ securityPacket = json_decode ( $ securityPacket , true ) ; } if ( empty ( $ securityPacket ) || ! is_array ( $ securityPacket ) ) { throw new ValidationException ( 'The security packet must be an array' ) ; } else { foreach ( array_keys ( $ securityPacket ) as $ key ) { if ( ! in_array ( $ key , $ this -> validSecurityKeys ) ) { throw new ValidationException ( 'Invalid key found in the security packet: ' . $ key ) ; } } if ( $ service === "questions" && ! array_key_exists ( 'user_id' , $ securityPacket ) ) { throw new ValidationException ( 'Questions API requires a `user_id` in the security packet' ) ; } if ( ! array_key_exists ( 'timestamp' , $ securityPacket ) ) { $ securityPacket [ 'timestamp' ] = gmdate ( 'Ymd-Hi' ) ; } } if ( empty ( $ secret ) || ! is_string ( $ secret ) ) { throw new ValidationException ( 'The `secret` argument must be a valid string' ) ; } if ( ! empty ( $ requestPacket ) && ! is_array ( $ requestPacket ) ) { throw new ValidationException ( 'The request packet must be an array or a valid JSON string' ) ; } if ( ! empty ( $ action ) && ! is_string ( $ action ) ) { throw new ValidationException ( 'The `action` argument must be a string' ) ; } }
Validate the arguments passed to the constructor

@param  string   $service
@param  array    $securityPacket
@param  string   $secret
@param  array    $requestPacket
@param  string   $action
Validate the arguments passed to the constructor