PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.4
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.4
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Http / Concerns / InteractsWithCookies.php
kirki / libraries / framework / Http / Concerns Last commit date
InteractsWithCookies.php 1 week ago InteractsWithFiles.php 1 month ago
InteractsWithCookies.php
86 lines
1 <?php
2
3 /**
4 * Trait for HTTP response classes to attach cookies fluently.
5 * Attached cookies are pushed into the CookieManager queue rather than stored on the response.
6 * This keeps a single emission path for responses the framework sends and those WordPress serializes.
7 *
8 * @package Framework
9 * @subpackage Http\Concerns
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Http\Concerns;
13
14 \defined('ABSPATH') || exit;
15 use Kirki\Framework\Http\Cookie;
16 use Kirki\Framework\Managers\CookieManager;
17 use function Kirki\Framework\app;
18 trait InteractsWithCookies
19 {
20 /**
21 * Attach a cookie to the response.
22 *
23 * Accepts either a Cookie instance or the arguments accepted by the cookie factory.
24 * The cookie is queued immediately and emitted at the next flush point.
25 *
26 * @param mixed $parameters The cookie instance or the factory arguments.
27 *
28 * @return $this
29 *
30 * @since 1.0.0
31 */
32 public function with_cookie(...$parameters)
33 {
34 $this->cookie_manager()->queue(...$parameters);
35 return $this;
36 }
37 /**
38 * Attach several cookies to the response.
39 *
40 * Accepts a list of Cookie instances or an associative array of names and values.
41 *
42 * @param array $cookies The cookies to attach.
43 *
44 * @return $this
45 *
46 * @since 1.0.0
47 */
48 public function with_cookies(array $cookies)
49 {
50 foreach ($cookies as $name => $cookie) {
51 if ($cookie instanceof Cookie) {
52 $this->with_cookie($cookie);
53 continue;
54 }
55 $this->with_cookie((string) $name, (string) $cookie);
56 }
57 return $this;
58 }
59 /**
60 * Remove a previously attached cookie before it is emitted.
61 *
62 * @param string $name The name of the cookie.
63 * @param string|null $path The path of the cookie, or null to remove every path.
64 *
65 * @return $this
66 *
67 * @since 1.0.0
68 */
69 public function without_cookie(string $name, ?string $path = null)
70 {
71 $this->cookie_manager()->unqueue($name, $path);
72 return $this;
73 }
74 /**
75 * Get the cookie manager instance.
76 *
77 * @return CookieManager
78 *
79 * @since 1.0.0
80 */
81 protected function cookie_manager()
82 {
83 return app(CookieManager::class);
84 }
85 }
86