Skip to content

Commit 836b75c

Browse files
committed
Add os info component
1 parent 81b9a0c commit 836b75c

3 files changed

Lines changed: 133 additions & 0 deletions

File tree

Writerside/boson.tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
</toc-element>
5151
<toc-element topic="events.md" />
5252
</toc-element>
53+
<toc-element topic="components.md">
54+
<toc-element topic="os-info.md" />
55+
</toc-element>
5356
<toc-element toc-title="Integrations">
5457
<toc-element topic="static-files.md" />
5558
<toc-element topic="symfony-adapter.md"

Writerside/topics/components.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Components
2+
3+
<show-structure for="chapter" depth="2"/>
4+
5+
Boson's architecture is built on a collection of versatile components that can
6+
be used independently of the main framework. These components are designed to
7+
be flexible and adaptable, allowing developers to integrate them into any web
8+
project or framework of their choice.
9+
10+
Whether you're building with Boson or working on a standalone website, these
11+
components provide powerful functionality without imposing any architectural
12+
constraints or technical limitations. This modular approach ensures that you
13+
can use exactly what you need, when you need it, while maintaining complete
14+
freedom in how you structure and implement your application.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Operating System Info
2+
3+
<show-structure for="chapter" depth="2"/>
4+
5+
The OS Info component provides a robust and flexible way to detect and work with
6+
operating system information in your applications. It offers a comprehensive
7+
set of features for identifying operating systems, their families, and
8+
supported standards.
9+
10+
## Installation
11+
12+
<tldr>
13+
<p>
14+
Via <a href="https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies">Composer</a>:
15+
</p>
16+
<p>
17+
<code lang="bash">composer require boson-php/os-info</code>
18+
</p>
19+
</tldr>
20+
21+
**Requirements:**
22+
23+
* `PHP ^8.4`
24+
* `ext-ffi` (optional, provides more detailed and accurate information about the OS)
25+
* `ext-com_dotnet` (optional, provides more detailed and accurate information about the OS)
26+
27+
## Usage
28+
29+
### Basic Detection
30+
31+
```php
32+
use Boson\Component\OsInfo\OperatingSystem;
33+
34+
// Get current operating system information
35+
$os = OperatingSystem::createFromGlobals();
36+
37+
// Access basic information
38+
echo 'Family: ' . $os->family . "\n";
39+
echo 'Name: ' . $os->name . "\n";
40+
echo 'Version: ' . $os->version . "\n";
41+
echo 'Codename: ' . ($os->codename ?? '~') . "\n";
42+
echo 'Edition: ' . ($os->edition ?? '~') . "\n";
43+
echo 'Standards: ' . implode(', ', $os->standards) . "\n";
44+
```
45+
46+
This code will output something like the following information
47+
48+
<tabs>
49+
<tab title="Windows">
50+
<code-block>
51+
Family: Windows
52+
Name: Windows 10 Pro
53+
Version: 10.0.19045
54+
Codename: 22H2
55+
Edition: Professional
56+
Standards: ~
57+
</code-block>
58+
</tab>
59+
<tab title="Linux">
60+
<code-block>
61+
Family: Linux
62+
Name: Ubuntu
63+
Version: 20.04.6
64+
Codename: Focal Fossa
65+
Edition: ~
66+
Standards: POSIX
67+
</code-block>
68+
</tab>
69+
</tabs>
70+
71+
### OS Families
72+
73+
You can get the OS family information from the OS information
74+
object (`$os->family`). However, if you do not need all the OS information,
75+
it is enough to get the family separately using the `Family::createFromGlobals()`
76+
method.
77+
78+
```php
79+
use Boson\Component\OsInfo\Family;
80+
81+
// Get current OS family
82+
$family = Family::createFromGlobals();
83+
84+
// Check for specific family
85+
if ($family->is(Family::Windows)) {
86+
// Windows-specific (or windows-like) code
87+
}
88+
```
89+
90+
Please note that the `$family->is()` check includes the check of the family
91+
itself and its parents.
92+
93+
```php
94+
if ($family->is(Family::Unix)) {
95+
// All operating systems from the Unix family
96+
// will be subject to this check:
97+
// - Darwin (macOS)
98+
// - Linux
99+
// - BSD
100+
// - ...and other Unix-like
101+
}
102+
```
103+
104+
### Standards Support
105+
106+
```php
107+
use Boson\Component\OsInfo\OperatingSystem;
108+
use Boson\Component\OsInfo\Standard;
109+
110+
$os = OperatingSystem::createFromGlobals();
111+
112+
// Check if OS supports a specific standard
113+
if ($os->isSupports(Standard::Posix)) {
114+
// Standard is supported
115+
}
116+
```

0 commit comments

Comments
 (0)