• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

michalsn / codeigniter-htmx / 13707691824

06 Mar 2025 08:36PM UTC coverage: 74.783%. First build
13707691824

Pull #83

github

web-flow
Merge 7f79fbae7 into 2ec7f6426
Pull Request #83: chore: update workflow to support PHP 8.4

17 of 22 new or added lines in 6 files covered. (77.27%)

258 of 345 relevant lines covered (74.78%)

7.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/HTTP/Response.php
1
<?php
2

3
namespace Michalsn\CodeIgniterHtmx\HTTP;
4

5
use CodeIgniter\HTTP\Response as BaseResponse;
6
use InvalidArgumentException;
7

8
class Response extends BaseResponse
9
{
10
    use HtmxTrait;
11

12
    /**
13
     * Pushes a new url into the history stack.
14
     */
15
    public function setPushUrl(?string $url = null): Response
16
    {
17
        $this->setHeader('HX-Push-Url', $url ?? 'false');
2✔
18

19
        return $this;
2✔
20
    }
21

22
    /**
23
     * Replaces the current URL in the location bar.
24
     */
25
    public function setReplaceUrl(?string $url = null): Response
26
    {
27
        $this->setHeader('HX-Replace-Url', $url ?? 'false');
2✔
28

29
        return $this;
2✔
30
    }
31

32
    /**
33
     * Allows you to specify how the response will be swapped.
34
     */
35
    public function setReswap(string $method): Response
36
    {
37
        $this->validateSwap($method, 'HX-Reswap');
3✔
38

39
        $this->setHeader('HX-Reswap', $method);
2✔
40

41
        return $this;
2✔
42
    }
43

44
    /**
45
     * A CSS selector that updates the target of the content
46
     * update to a different element on the page.
47
     */
48
    public function setRetarget(string $selector): Response
49
    {
50
        $this->setHeader('HX-Retarget', $selector);
1✔
51

52
        return $this;
1✔
53
    }
54

55
    /**
56
     * A CSS selector that allows you to choose which part
57
     * of the response is used to be swapped in.
58
     */
59
    public function setReselect(string $selector): Response
60
    {
61
        $this->setHeader('HX-Reselect', $selector);
1✔
62

63
        return $this;
1✔
64
    }
65

66
    /**
67
     * Allows you to trigger client side events.
68
     */
69
    public function triggerClientEvent(string $name, array|string $params = '', string $after = 'receive'): Response
70
    {
71
        $header = match ($after) {
7✔
72
            'receive' => 'HX-Trigger',
4✔
73
            'settle'  => 'HX-Trigger-After-Settle',
1✔
74
            'swap'    => 'HX-Trigger-After-Swap',
1✔
75
            default   => throw new InvalidArgumentException('A value for "after" argument must be one of: "receive", "settle", or "swap".'),
1✔
76
        };
7✔
77

78
        if ($this->hasHeader($header)) {
6✔
79
            $data = json_decode($this->header($header)->getValue(), true);
2✔
80
            if ($data === null) {
2✔
81
                throw new InvalidArgumentException(sprintf('%s header value should be a valid JSON.', $header));
1✔
82
            }
83
            $data[$name] = $params;
1✔
84
        } else {
85
            $data = [$name => $params];
5✔
86
        }
87

88
        $this->setHeader($header, json_encode($data));
5✔
89

90
        return $this;
5✔
91
    }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc