Skip to content

Commit 23ff154

Browse files
committed
docs: Update the check mode page
1 parent e24cf10 commit 23ff154

File tree

6 files changed

+330
-15
lines changed

6 files changed

+330
-15
lines changed

_docs/check-mode.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Check mode
3+
navigation:
4+
priority: 15
5+
---
6+
7+
# Check mode
8+
9+
JSON Schema for PHP check mode can be configured using the flags from the Constraint class. These can be configured as default
10+
or provided for a single `validate()` call.
11+
12+
```php
13+
$checkMode = Constraint::CHECK_MODE_NORMAL | Constraint::CHECK_MODE_VALIDATE_SCHEMA | Constraint::CHECK_MODE_APPLY_DEFAULTS;
14+
15+
$validator = new Validator(new Factory(null, null, $checkMode)); // Setting the default check mode for all validate calls.
16+
$validator->validate($data, $schema, $checkMode); // Or set the check mode for this validation call.
17+
```
18+
19+
20+
21+
## Available flags
22+
| Flag | | Value | Description |
23+
|-------------------------------------------------|:--|--------------|---------------------------------------------------------------|
24+
| `Constraint::CHECK_MODE_NORMAL` | | `0x00000001` | Validate in 'normal' mode - this is the default |
25+
| `Constraint::CHECK_MODE_TYPE_CAST` | | `0x00000002` | Enable fuzzy type checking for associative arrays and objects |
26+
| `Constraint::CHECK_MODE_COERCE_TYPES` | | `0x00000004` | Convert data types to match the schema where possible |
27+
| `Constraint::CHECK_MODE_APPLY_DEFAULTS` | | `0x00000008` | Apply default values from the schema if not set |
28+
| `Constraint::CHECK_MODE_EXCEPTIONS` | | `0x00000010` | Throw an exception immediately if validation fails |
29+
| `Constraint::CHECK_MODE_DISABLE_FORMAT` | | `0x00000020` | Do not validate "format" constraints |
30+
| `Constraint::CHECK_MODE_EARLY_COERCE` | | `0x00000040` | Apply type coercion as soon as possible |
31+
| `Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS` | | `0x00000080` | When applying defaults, only set values that are required |
32+
| `Constraint::CHECK_MODE_VALIDATE_SCHEMA` | | `0x00000100` | Validate the schema as well as the provided document |

_docs/configuration.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

_site/docs/check-mode.html

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>JSON Schema for PHP - Check mode</title>
7+
8+
9+
10+
<meta name="twitter:title" content="JSON Schema for PHP - Check mode">
11+
<meta property="og:title" content="JSON Schema for PHP - Check mode">
12+
13+
14+
<meta name="generator" content="HydePHP v1.8.0">
15+
<meta property="og:site_name" content="JSON Schema for PHP">
16+
17+
18+
19+
20+
<style>[x-cloak] {display: none!important}</style>
21+
22+
23+
<link rel="stylesheet" href="../media/app.css?v=a59783ccdd4cd8cac4dda07ccf5e1ce3">
24+
25+
26+
27+
28+
29+
30+
<meta id="meta-color-scheme" name="color-scheme" content="light">
31+
<script>if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.documentElement.classList.add('dark'); document.getElementById('meta-color-scheme').setAttribute('content', 'dark');} else { document.documentElement.classList.remove('dark') } </script>
32+
33+
34+
35+
36+
37+
38+
</head>
39+
<body id="hyde-docs" class="bg-white dark:bg-gray-900 dark:text-white min-h-screen w-screen relative overflow-x-hidden overflow-y-auto"
40+
x-data="{ sidebarOpen: false, searchWindowOpen: false }" x-on:keydown.escape="searchWindowOpen = false; sidebarOpen = false" x-on:keydown.slash="searchWindowOpen = true">
41+
42+
<a href="#content" id="skip-to-content" class="sr-only focus:not-sr-only bg-black border-4 border-yellow-400 focus:absolute focus:mt-2 focus:mx-auto focus:p-2 focus:w-64 h-auto left-0 overflow-auto right-0 rounded-md text-center text-lg text-white top-auto z-50 ">Skip to content</a> <nav id="mobile-navigation" class="bg-white dark:bg-gray-800 md:hidden flex justify-between w-full h-16 z-40 fixed left-0 top-0 p-4 leading-8 shadow-lg print:hidden">
43+
<strong class="px-2 mr-auto">
44+
JSON Schema for PHP Docs
45+
</strong>
46+
<ul class="flex items-center">
47+
<li class="h-8 flex mr-1">
48+
<button @click="toggleTheme" class="theme-toggle-button flex items-center px-2 py-1 hover:text-gray-700 dark:text-gray-200 opacity-75 hover:opacity-100" title="Toggle theme">
49+
<span class="sr-only">Toggle dark theme</span>
50+
<svg width="1.25rem" height="1.25rem" class="w-5 h-5 hidden dark:block" fill="#FFFFFF" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
51+
<svg width="1.25rem" height="1.25rem" class="w-5 h-5 block dark:hidden" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path></svg>
52+
</button>
53+
</li>
54+
<li class="h-8 flex">
55+
<button id="sidebar-toggle" title="Toggle sidebar" aria-label="Toggle sidebar navigation menu" @click="sidebarOpen = ! sidebarOpen" :class="{'active' : sidebarOpen}">
56+
<span class="icon-bar dark:bg-white h-0" role="presentation"></span>
57+
<span class="icon-bar dark:bg-white h-0" role="presentation"></span>
58+
<span class="icon-bar dark:bg-white h-0" role="presentation"></span>
59+
<span class="icon-bar dark:bg-white h-0" role="presentation"></span>
60+
</button> </li>
61+
</ul>
62+
</nav> <aside id="sidebar" x-cloak :class="sidebarOpen ? 'visible left-0' : 'invisible -left-64 md:visible md:left-0'" class="bg-gray-100 dark:bg-gray-800 dark:text-gray-200 h-screen w-64 fixed z-30 md:flex flex-col shadow-lg md:shadow-none transition-all duration-300">
63+
<header id="sidebar-header" class="h-16">
64+
<div id="sidebar-brand" class="flex items-center justify-between h-16 py-4 px-2">
65+
<strong class="px-2">
66+
JSON Schema for PHP Docs
67+
</strong>
68+
<button @click="toggleTheme" class="theme-toggle-button flex items-center px-2 py-1 hover:text-gray-700 dark:text-gray-200 opacity-75 hover:opacity-100" title="Toggle theme">
69+
<span class="sr-only">Toggle dark theme</span>
70+
<svg width="1.25rem" height="1.25rem" class="w-5 h-5 hidden dark:block" fill="#FFFFFF" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
71+
<svg width="1.25rem" height="1.25rem" class="w-5 h-5 block dark:hidden" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path></svg>
72+
</button>
73+
</div> </header>
74+
<nav id="sidebar-navigation" class="p-2 overflow-y-auto border-y border-gray-300 dark:border-[#1b2533] h-full">
75+
<ul id="sidebar-items" role="list" class="pl-2">
76+
<li class="sidebar-item -ml-4 pl-4" role="listitem">
77+
<a href="../docs/getting-started.html" class="block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10">
78+
Getting started
79+
</a>
80+
</li> <li class="sidebar-item -ml-4 pl-4 active bg-black/5 dark:bg-black/10" role="listitem">
81+
<a href="../docs/check-mode.html" aria-current="true" class="-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out">
82+
Check mode
83+
</a>
84+
85+
<span class="sr-only">Table of contents</span>
86+
<ul class="table-of-contents">
87+
<li><a href="#available-flags">Available flags</a></li>
88+
</ul>
89+
90+
</li> <li class="sidebar-item -ml-4 pl-4" role="listitem">
91+
<a href="../docs/advanced-topics.html" class="block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10">
92+
Advanced topics
93+
</a>
94+
</li> <li class="sidebar-item -ml-4 pl-4" role="listitem">
95+
<a href="../docs/community-guide.html" class="block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10">
96+
Community guide
97+
</a>
98+
</li> <li class="sidebar-item -ml-4 pl-4" role="listitem">
99+
<a href="../docs/contributors.html" class="block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10">
100+
Contributors
101+
</a>
102+
</li> </ul>
103+
</nav>
104+
<footer id="sidebar-footer" class="h-16 p-4 w-full bottom-0 left-0 text-center leading-8">
105+
<p>
106+
<a href="../index.html">Back to home page</a>
107+
</p> </footer>
108+
</aside>
109+
<main id="content" class="dark:bg-gray-900 min-h-screen bg-gray-50 md:bg-white absolute top-16 md:top-0 w-screen md:left-64 md:w-[calc(100vw_-_16rem)] print:top-0">
110+
<article id="document" itemscope itemtype="https://schema.org/Article" class="mx-auto lg:ml-8 max-w-3xl p-12 md:px-16 max-w-[1000px] min-h-[calc(100vh_-_4rem)] prose dark:prose-invert">
111+
112+
<header id="document-header" class="flex items-center flex-wrap justify-between prose-h1:mb-3">
113+
<h1>Check mode</h1>
114+
</header>
115+
<section id="document-main-content" itemprop="articleBody">
116+
<p>JSON Schema for PHP check mode can be configured using the flags from the Constraint class. These can be configured as default
117+
or provided for a single <code>validate()</code> call.</p>
118+
<pre><code class="language-php">$checkMode = Constraint::CHECK_MODE_NORMAL | Constraint::CHECK_MODE_VALIDATE_SCHEMA | Constraint::CHECK_MODE_APPLY_DEFAULTS;
119+
120+
$validator = new Validator(new Factory(null, null, $checkMode)); // Setting the default check mode for all validate calls.
121+
$validator-&gt;validate($data, $schema, $checkMode); // Or set the check mode for this validation call.
122+
</code></pre>
123+
<h2>Available flags<a id="available-flags" href="#available-flags" class="heading-permalink" title="Permalink"></a></h2>
124+
<table>
125+
<thead>
126+
<tr>
127+
<th>Flag</th>
128+
<th align="left"></th>
129+
<th>Value</th>
130+
<th>Description</th>
131+
</tr>
132+
</thead>
133+
<tbody>
134+
<tr>
135+
<td><code>Constraint::CHECK_MODE_NORMAL</code></td>
136+
<td align="left"></td>
137+
<td><code>0x00000001</code></td>
138+
<td>Validate in 'normal' mode - this is the default</td>
139+
</tr>
140+
<tr>
141+
<td><code>Constraint::CHECK_MODE_TYPE_CAST</code></td>
142+
<td align="left"></td>
143+
<td><code>0x00000002</code></td>
144+
<td>Enable fuzzy type checking for associative arrays and objects</td>
145+
</tr>
146+
<tr>
147+
<td><code>Constraint::CHECK_MODE_COERCE_TYPES</code></td>
148+
<td align="left"></td>
149+
<td><code>0x00000004</code></td>
150+
<td>Convert data types to match the schema where possible</td>
151+
</tr>
152+
<tr>
153+
<td><code>Constraint::CHECK_MODE_APPLY_DEFAULTS</code></td>
154+
<td align="left"></td>
155+
<td><code>0x00000008</code></td>
156+
<td>Apply default values from the schema if not set</td>
157+
</tr>
158+
<tr>
159+
<td><code>Constraint::CHECK_MODE_EXCEPTIONS</code></td>
160+
<td align="left"></td>
161+
<td><code>0x00000010</code></td>
162+
<td>Throw an exception immediately if validation fails</td>
163+
</tr>
164+
<tr>
165+
<td><code>Constraint::CHECK_MODE_DISABLE_FORMAT</code></td>
166+
<td align="left"></td>
167+
<td><code>0x00000020</code></td>
168+
<td>Do not validate &quot;format&quot; constraints</td>
169+
</tr>
170+
<tr>
171+
<td><code>Constraint::CHECK_MODE_EARLY_COERCE</code></td>
172+
<td align="left"></td>
173+
<td><code>0x00000040</code></td>
174+
<td>Apply type coercion as soon as possible</td>
175+
</tr>
176+
<tr>
177+
<td><code>Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS</code></td>
178+
<td align="left"></td>
179+
<td><code>0x00000080</code></td>
180+
<td>When applying defaults, only set values that are required</td>
181+
</tr>
182+
<tr>
183+
<td><code>Constraint::CHECK_MODE_VALIDATE_SCHEMA</code></td>
184+
<td align="left"></td>
185+
<td><code>0x00000100</code></td>
186+
<td>Validate the schema as well as the provided document</td>
187+
</tr>
188+
</tbody>
189+
</table>
190+
</section>
191+
<footer id="document-footer" class="flex items-center flex-wrap mt-8 prose-p:my-3 justify-between text-[90%]">
192+
<p class="edit-page-link">
193+
<a href="https://github.com/jsonrainbow/docs/edit/main/_docs/check-mode.md">
194+
Found a typo?
195+
</a>
196+
</p>
197+
</footer>
198+
</article> </main>
199+
200+
<div id="support">
201+
<div id="sidebar-backdrop" x-cloak="" x-show="sidebarOpen" x-transition @click="sidebarOpen = false" title="Click to close sidebar" class="w-screen h-screen fixed top-0 left-0 cursor-pointer z-10 bg-black/50"></div>
202+
<button id="searchMenuButton" x-on:click="searchWindowOpen = ! searchWindowOpen"
203+
:title="searchWindowOpen ? 'Close search window' : 'Open search window'; $nextTick(() => { setTimeout(() => { document.getElementById('search-input').focus(); }); });"
204+
class="absolute right-4 top-4 mr-4 z-10 opacity-75 hover:opacity-100 hidden md:block"
205+
aria-label="Toggle search window">
206+
<span x-show="! searchWindowOpen">
207+
Search <svg class="float-left mr-1 dark:fill-white" xmlns="http://www.w3.org/2000/svg" height="24"
208+
viewBox="0 0 24 24" width="24" role="presentation">
209+
<path d="M0 0h24v24H0z" fill="none"/>
210+
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
211+
</span>
212+
<span x-show="searchWindowOpen">
213+
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
214+
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
215+
</svg>
216+
</span>
217+
</button>
218+
<button id="searchMenuButtonMobile" x-on:click="searchWindowOpen = ! searchWindowOpen"
219+
:title="searchWindowOpen ? 'Close search window' : 'Open search window'; $nextTick(() => { setTimeout(() => { document.getElementById('search-input').focus(); }); });"
220+
class="block md:hidden fixed bottom-4 right-4 z-10 rounded-full p-2 opacity-75 hover:opacity-100 fill-black bg-gray-200 dark:fill-gray-200 dark:bg-gray-700 print:hidden"
221+
aria-label="Toggle search menu">
222+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" role="presentation">
223+
<path d="M0 0h24v24H0z" fill="none"/>
224+
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
225+
</svg>
226+
</button>
227+
228+
<div id="search-window-container" x-show="searchWindowOpen" x-cloak role="dialog"
229+
class="z-30 fixed top-0 left-0 w-screen h-screen flex flex-col items-center px-8 py-24 md:py-16">
230+
<aside x-on:click.away="searchWindowOpen = false" id="searchMenu"
231+
class="prose dark:prose-invert bg-white dark:bg-gray-800 z-50 p-4 rounded-lg overflow-y-hidden min-h-[300px] max-h-[75vh] w-[70ch] max-w-full cursor-auto ">
232+
<header class="flex justify-between pb-3 mb-3 border-b dark:border-gray-700 md:hidden">
233+
<strong>Search the documentation site</strong>
234+
<button @click="searchWindowOpen = false" title="Close search window" class="opacity-75 hover:opacity-100"
235+
aria-label="Close search window">
236+
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
237+
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
238+
</svg>
239+
</button>
240+
</header>
241+
<div>
242+
<div id="hyde-search">
243+
<noscript>
244+
The search feature requires JavaScript to be enabled in your browser.
245+
</noscript>
246+
<input class="w-full rounded text-base leading-normal bg-gray-100 dark:bg-gray-700 py-2 px-3" type="search" name="search" id="search-input" placeholder="Search..." autocomplete="off" autofocus>
247+
</div> </div>
248+
<footer class="mt-auto -mb-2 leading-4 text-center font-mono hidden sm:flex justify-center">
249+
<small>
250+
Press <code><kbd title="Forward slash">/</kbd></code> to open search window.
251+
Use <code><kbd title="Escape key">esc</kbd></code> to close.
252+
</small>
253+
</footer>
254+
</aside>
255+
256+
<div id="search-window-backdrop" class="w-screen h-screen cursor-pointer z-40 bg-black/50 absolute top-0" title="Click to close search window"></div>
257+
</div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/HydeSearch.min.js" defer></script>
258+
<script>
259+
window.addEventListener('load', function () {
260+
const searchIndexLocation = '../docs/search.json';
261+
const Search = new HydeSearch(searchIndexLocation);
262+
263+
Search.init();
264+
});
265+
</script> </div>
266+
267+
<script defer src="../media/app.js?v=df4829542141b3634f113c4cb9e386aa"></script>
268+
269+
270+
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js" integrity="sha256-gOkV4d9/FmMNEkjOzVlyM2eNAWSUXisT+1RbMTTIgXI=" crossorigin="anonymous"></script>
271+
272+
<script>
273+
function toggleTheme() {
274+
if (localStorage.getItem('color-theme') === 'dark' || !('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) {
275+
document.documentElement.classList.remove("dark");
276+
localStorage.setItem('color-theme', 'light');
277+
document.getElementById('meta-color-scheme').setAttribute('content', 'light');
278+
} else {
279+
document.documentElement.classList.add("dark");
280+
localStorage.setItem('color-theme', 'dark');
281+
document.getElementById('meta-color-scheme').setAttribute('content', 'dark');
282+
}
283+
}
284+
</script>
285+
286+
287+
288+
289+
290+
291+
</body>
292+
</html>

0 commit comments

Comments
 (0)