id = $id; $this->old_id = $old_id; $this->id_name = $id_name; $this->db_name = $db_name; } /** * Execute validation. * @throws Exception When id is invalid. */ public function exe() { // Get language setting. $lan = new Language( get_locale() ); try { // If id is empty throws error. if ( '' === $this->id ) { throw new Exception( $lan->{$this->id_name . '_cannot_be_empty'} ); } // If id has invalid charactors throws error. if ( preg_match( '/[\[\]\<\>\&\/\t\'\"]+/', $this->id ) ) { throw new Exception( $lan->{$this->id_name . '_has_unavailable_characters'} ); } // If user changed id. if ( $this->id !== $this->old_id ) { // If the new id is already in DB table, throws error. if ( ! is_null( $this->db_name::get( $this->id ) ) ) { throw new Exception( $lan->{$this->id_name . '_exists'} ); } } } catch ( Exception $e ) { $this->error_occured = true; $this->msg = $e->getMessage(); } } /** * Check whtere an error occured or not. * @return bool when error occurd return true, if no return false. */ public function doesErrorOccur() { return $this->error_occured; } /** * Get an error message. * @return string return message. */ public function getMessage() { return $this->msg; } }