1994 / cookie-connect-core
The framework-free core shared by Cookie Connect for Craft CMS and Statamic: every cookie consent platform described as data, the head and blocking markup they need, Google Consent Mode v2, and one JavaScript consent API for all of them.
Requires
- php: ^8.2
- ext-json: *
- ext-mbstring: *
- symfony/yaml: ^6.4|^7.0|^8.0
Requires (Dev)
- laravel/pint: ^1.18
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-18 00:25:58 UTC
README
The framework-free core shared by Cookie Connect for Craft CMS and Cookie Connect for Statamic. You don't install it yourself; the plugin or addon requires it.
Cookie Connect connects a site to the cookie consent platform it already pays for (Cookiebot, Usercentrics, OneTrust, CookieYes, iubenda, Termly, CookieFirst, Cookie-Script, or any other), handles Google Consent Mode v2, and gives templates one way to mark scripts that need consent, whichever platform is behind it.
Each product stays thin: it stores the settings, draws the Control Panel, adds the template tags and puts the output into pages. Everything that's the same on both lives here:
- Every platform, as data (
resources/providers/*.yaml): its fields and how to check them, its head tags, how it blocks scripts in each category, who sets Consent Mode defaults, its cookie declaration, the date it was last checked against the platform's docs. See Providers. - The output (
Output\Renderer): the head block, consent-gated HTML (gate()), the declaration, "Cookie settings" links and placeholders, CSP hashes; andOutput\Injector, which puts it all into a finished page. - The browser script (
resources/runtime/cookie-connect.js): reads consent from whichever platform the site uses and gives site code one API. See The browser API. - Settings and validation (
Settings\*): IDs taken out of pasted snippets, problems explained field by field.
Core depends on no framework or CMS. CI fails if src/ names Illuminate, Laravel, Craft, Yii or Statamic (bin/check-boundaries).
Using it
use NineteenNinetyFour\CookieConnect\Core\Output\Context; use NineteenNinetyFour\CookieConnect\Core\Output\Injector; use NineteenNinetyFour\CookieConnect\Core\Output\Renderer; use NineteenNinetyFour\CookieConnect\Core\Settings\Settings; $renderer = new Renderer( Settings::fromArray([ 'provider' => 'cookiebot', 'values' => ['cbid' => '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d'], 'google' => ['gtmId' => 'GTM-ABC1234'], ]), new Context(host: 'example.com', lang: 'en', nonce: $nonce), ); $html = Injector::inject($html, $renderer->head(), $renderer->bodyStart(), $renderer->bodyEnd()); echo $renderer->gate('<script src="https://plausible.io/js/script.js" defer></script>', 'analytics');
Development
composer install npm install vendor/bin/phpunit # PHP tests, with a snapshot of each provider's output (tests/Fixtures/snapshots) npm test # the browser script's tests (jsdom) npm run build # minifies the browser script; commit the result vendor/bin/pint # code style vendor/bin/phpstan analyse php bin/check-boundaries
After a deliberate change to the output, UPDATE_SNAPSHOTS=1 vendor/bin/phpunit rewrites the snapshots; read the diff before committing.
Licence
Commercial, as part of Cookie Connect. See LICENSE.md.