• 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/RedirectResponse.php
1
<?php
2

3
namespace Michalsn\CodeIgniterHtmx\HTTP;
4

5
use CodeIgniter\HTTP\RedirectResponse as BaseRedirectResponse;
6

7
class RedirectResponse extends BaseRedirectResponse
8
{
9
    use HtmxTrait;
10

11
    /**
12
     * Sets the HX-Location to redirect
13
     * without reloading the whole page.
14
     */
15
    public function hxLocation(
16
        string $path,
17
        ?string $source = null,
18
        ?string $event = null,
19
        ?string $target = null,
20
        ?string $swap = null,
21
        ?array $values = null,
22
        ?array $headers = null,
23
    ): RedirectResponse {
24
        if (str_starts_with($path, 'http://') || str_starts_with($path, 'https://')) {
6✔
25
            $path = (string) service('uri', $path, false)->withScheme('')->setHost('');
1✔
26
        }
27

28
        $data = ['path' => '/' . ltrim($path, '/')];
6✔
29

30
        if ($source !== null) {
6✔
31
            $data['source'] = $source;
1✔
32
        }
33

34
        if ($event !== null) {
6✔
35
            $data['event'] = $event;
1✔
36
        }
37

38
        if ($target !== null) {
6✔
39
            $data['target'] = $target;
1✔
40
        }
41

42
        if ($swap !== null) {
6✔
43
            $this->validateSwap($swap);
2✔
44
            $data['swap'] = $swap;
1✔
45
        }
46

47
        if ($values !== null && $values !== []) {
5✔
48
            $data['values'] = $values;
1✔
49
        }
50

51
        if ($headers !== null && $headers !== []) {
5✔
52
            $data['headers'] = $headers;
1✔
53
        }
54

55
        return $this->setStatusCode(200)->setHeader('HX-Location', json_encode($data));
5✔
56
    }
57

58
    /**
59
     * Sets the HX-Redirect to URI to redirect to.
60
     *
61
     * @param string $uri The URI to redirect to
62
     */
63
    public function hxRedirect(string $uri): RedirectResponse
64
    {
65
        if (! str_starts_with($uri, 'http')) {
2✔
66
            $uri = site_url($uri);
1✔
67
        }
68

69
        return $this->setStatusCode(200)->setHeader('HX-Redirect', $uri);
2✔
70
    }
71

72
    /**
73
     * Sets the HX-Refresh to true.
74
     */
75
    public function hxRefresh(): RedirectResponse
76
    {
77
        return $this->setStatusCode(200)->setHeader('HX-Refresh', 'true');
1✔
78
    }
79
}
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