get = $get; $this->post = $post; $this->cookie = $cookie; $this->server = $server; } /** * @param string $key * * @return bool */ public function has_twofas_param( $key ) { return $this->are_twofas_params_sent() && array_key_exists( $key, $this->post[ self::TWOFAS_ARRAY_KEY ] ); } /** * @param array $params * * @return bool */ public function has_twofas_params( array $params ) { if ( ! $this->are_twofas_params_sent() ) { return false; } $keys = array_keys( $this->post[ self::TWOFAS_ARRAY_KEY ] ); $diff = array_diff( $params, $keys ); return empty( $diff ); } /** * @param string $key * * @return null|string */ public function get_twofas_param( $key ) { if ( ! $this->has_twofas_param( $key ) ) { return null; } return $this->post[ self::TWOFAS_ARRAY_KEY ][ $key ]; } /** * @return string */ public function http_method() { return strtoupper( $this->header( 'REQUEST_METHOD' ) ); } /** * @return bool */ public function is_post() { return 'POST' === $this->http_method(); } /** * @return bool */ public function is_ajax() { return 'xmlhttprequest' === strtolower( $this->header( 'HTTP_X_REQUESTED_WITH' ) ); } /** * @return array|null|string */ public function get_nonce() { if ( $this->is_post() ) { return $this->post( '_wpnonce' ); } return $this->get( '_wpnonce' ); } /** * @param string $parameter * * @return null|string|array */ public function get( $parameter ) { return $this->get_from_array( $this->get, $parameter ); } /** * @param string $parameter * * @return null|string|array */ public function post( $parameter ) { return $this->get_from_array( $this->post, $parameter ); } /** * @return Cookie */ public function cookie() { return $this->cookie; } /** * @param string $parameter * * @return null|string|array */ public function request( $parameter ) { $request = array_merge( $this->get, $this->post, $this->cookie->get_cookies() ); return $this->get_from_array( $request, $parameter ); } /** * @param string $parameter * * @return array|null|string */ public function header( $parameter ) { return $this->get_from_array( $this->server, $parameter ); } /** * @param string $name * * @return bool */ public function has( $name ) { if ( array_key_exists( $name, $this->get ) ) { return true; } elseif ( array_key_exists( $name, $this->post ) ) { return true; } return false; } /** * @param mixed $action * * @return bool */ public function is_login_action_equal_to( $action ) { return $this->post( Authenticate_Filter::LOGIN_ACTION_KEY ) === $action; } /** * @return string */ public function page() { $page = $this->get( Route::PAGE_KEY ); if ( is_string( $page ) ) { return $page; } return ''; } /** * @return string */ public function action() { $action = $this->get( Route::TWOFAS_ACTION_KEY ); if ( is_string( $action ) ) { return $action; } return ''; } /** * @return string */ public function referer_action() { parse_str( $this->header( 'HTTP_REFERER' ), $query ); if ( array_key_exists( Route::TWOFAS_ACTION_KEY, $query ) ) { return $query[Route::TWOFAS_ACTION_KEY]; } return ''; } /** * @param string $page * * @return bool */ public function is_page_equal_to( $page ) { return $this->get( 'page' ) === $page; } /** * @param string $action * * @return bool */ public function is_action_equal_to( $action ) { return $this->get( 'twofas-action' ) === $action; } /** * @param array $source * @param string $item * * @return null|string|array */ private function get_from_array( array $source, $item ) { if ( array_key_exists( $item, $source ) ) { return $source[ $item ]; } return null; } /** * @return bool */ private function are_twofas_params_sent() { return array_key_exists( self::TWOFAS_ARRAY_KEY, $this->post ) && is_array( $this->post[ self::TWOFAS_ARRAY_KEY ] ); } }