X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRequest.pm;h=47f163ca91655b36cef40d76ab0693a6d7626728;hb=8c4f656c35da0888f5c19438064bd5c76b41c875;hp=4479bd73ae7d532a0d2672c397f2114affd15a05;hpb=a23454bb1b039a31b7f77710ff663fa9152d530c;p=kivitendo-erp.git diff --git a/SL/Request.pm b/SL/Request.pm index 4479bd73a..47f163ca9 100644 --- a/SL/Request.pm +++ b/SL/Request.pm @@ -41,6 +41,17 @@ sub init_type { return 'html'; } +sub cache { + my ($self, $topic, $default) = @_; + + $topic = '::' . (caller(0))[0] . "::$topic" unless $topic =~ m{^::}; + + $self->{_cache} //= {}; + $self->{_cache}->{$topic} //= ($default // {}); + + return $self->{_cache}->{$topic}; +} + sub _store_value { my ($target, $key, $value) = @_; my @tokens = split /((?:\[\+?\])?(?:\.)|(?:\[\+?\]))/, $key; @@ -70,19 +81,23 @@ sub _store_value { sub _input_to_hash { $::lxdebug->enter_sub(2); - my ($target, $input) = @_; + my ($target, $input, $log) = @_; my @pairs = split(/&/, $input); foreach (@pairs) { my ($key, $value) = split(/=/, $_, 2); - _store_value($target, uri_decode($key), uri_decode($value)) if ($key); + next unless $key; + _store_value($target, uri_decode($key), uri_decode($value)); + + # for debugging + $::lxdebug->add_request_params(uri_decode($key) => uri_decode($value)) if $log; } $::lxdebug->leave_sub(2); } sub _parse_multipart_formdata { - my ($target, $temp_target, $input) = @_; + my ($target, $temp_target, $input, $log) = @_; my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous, $p_attachment, $encoding, $transfer_encoding); my $data_start = 0; @@ -113,6 +128,7 @@ sub _parse_multipart_formdata { } else { ${ $previous } = $data; } + $::lxdebug->add_request_params($name, $$previous) if $log; undef $previous; undef $filename; @@ -121,7 +137,7 @@ sub _parse_multipart_formdata { $content_type = "text/plain"; $boundary_found = 1; $need_cr = 0; - $encoding = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; + $encoding = 'UTF-8'; $transfer_encoding = undef; last if $last_boundary; next; @@ -250,7 +266,6 @@ sub read_cgi_input { $::lxdebug->enter_sub; my ($target) = @_; - my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; # yes i know, copying all those values around isn't terribly efficient, but # the old version of dumping everything into form and then launching a @@ -263,8 +278,8 @@ sub read_cgi_input { # since both of these can potentially bring their encoding in INPUT_ENCODING # they get dumped into temp_target - _input_to_hash($temp_target, $ENV{QUERY_STRING}) if $ENV{QUERY_STRING}; - _input_to_hash($temp_target, $ARGV[0]) if @ARGV && $ARGV[0]; + _input_to_hash($temp_target, $ENV{QUERY_STRING}, 1) if $ENV{QUERY_STRING}; + _input_to_hash($temp_target, $ARGV[0], 1) if @ARGV && $ARGV[0]; if ($ENV{CONTENT_LENGTH}) { my $content; @@ -272,16 +287,16 @@ sub read_cgi_input { if ($ENV{'CONTENT_TYPE'} && $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/) { # multipart formdata can bring it's own encoding, so give it both # and let ti decide on it's own - _parse_multipart_formdata($target, $temp_target, $content); + _parse_multipart_formdata($target, $temp_target, $content, 1); } else { # normal encoding must be recoded - _input_to_hash($temp_target, $content); + _input_to_hash($temp_target, $content, 1); } } - my $encoding = delete $temp_target->{INPUT_ENCODING} || $db_charset; + my $encoding = delete $temp_target->{INPUT_ENCODING} || 'UTF-8'; - _recode_recursively(SL::Iconv->new($encoding, $db_charset), $temp_target => $target) if keys %$target; + _recode_recursively(SL::Iconv->new($encoding, 'UTF-8'), $temp_target => $target) if keys %$target; if ($target->{RESTORE_FORM_FROM_SESSION_ID}) { my %temp_form; @@ -312,7 +327,7 @@ sub flatten { for (ref $source) { /^HASH$/ && do { my $first = 1; - for my $key (keys %$source) { + for my $key (sort keys %$source) { flatten($source->{$key} => $target, (defined $prefix ? $prefix . $arr_prefix->($first) . '.' : '') . $key); $first = 0; }; @@ -529,6 +544,21 @@ of L. Defaults to an isntance of L. For more information about layouts, see L. +=item C + +Caches an item for the duration of the request. C<$topic> must be an +index name referring to the thing to cache. It is used for retrieving +it later on. If C<$topic> doesn't start with C<::> then the caller's +package name is prepended to the topic. For example, if the a from +package C calls with topic = C then the +actual key will be C<::SL::StuffedStuff::get_stuff>. + +If no item exists in the cache for C<$topic> then it is created and +its initial value is set to C<$default>. If C<$default> is not given +(undefined) then a new, empty hash reference is created. + +Returns the cached item. + =back =head1 SPECIAL FUNCTIONS