Skip to content

Commit 985249b

Browse files
committed
Update docs
1 parent 3fa869f commit 985249b

File tree

3 files changed

+137
-133
lines changed

3 files changed

+137
-133
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
['documentation/', 'How It Works'],
2929
['documentation/getting-started', 'Getting Started'],
3030
['documentation/configuration', 'Configuration'],
31+
['documentation/the-config-instance', 'The Config Instance'],
3132
]
3233
}
3334
]
Lines changed: 4 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Basic Configuration
22

3+
There isn't much configuration that needs to be done to get started with this library. You only need to set the
4+
connections and being using it.
5+
36
### Static call on Win32Model class
47
``` php
58
$connection = Connection::simple('computer-one', 'admin', 'password');
@@ -42,7 +45,7 @@ this connection.
4245
$scripting = new Scripting;
4346
$scripting->addConnection(
4447
'computer-one',
45-
Connection::simple('computer-one', 'admin', 'password)
48+
Connection::simple('computer-one', 'admin', 'password')
4649
);
4750

4851
$builder = $scripting->query('computer-one)->loggedOnUser();
@@ -70,135 +73,3 @@ If no configuration is provided then the library's default connection is localho
7073
will be used.
7174
:::
7275

73-
## The Configuration Instance
74-
75-
The configuration instance, `Config`, is the core of this library. Upon instantiation of, either a model or `Scripting`,
76-
an instance of `Config` gets created.
77-
78-
`Config` uses a singleton-like pattern to make querying on a model directly possible.
79-
Due to the usage of this pattern you typically would not `new` the `Config` object directly. However, if you feel
80-
you need to access the `Config` directly you should do so using the `::instance()` static method.
81-
82-
### Defaults
83-
84-
The only default that is currently expected to be used is the default `Connection`. This is set to the local machine
85-
that `PHP` is running on.
86-
87-
``` php
88-
# config/connections.php
89-
90-
return [
91-
'default' => 'local',
92-
93-
'servers' => [
94-
'local' => [
95-
'server' => '.',
96-
'namespace' => 'Root\CIMv2',
97-
'user' => null,
98-
'password' => null,
99-
'locale' => null,
100-
'authority' => null,
101-
'security_flags' => null,
102-
],
103-
],
104-
];
105-
```
106-
107-
If you would like to define a list of connections from a file or array you should construct the array and
108-
instantiate `Config` as follows:
109-
110-
``` php
111-
$connections = [
112-
'wmi' => [
113-
'connections' => [
114-
'default' => 'computer-two',
115-
116-
'servers' => [
117-
'computer-one' => [
118-
'server' => 'computer1',
119-
'user' => 'admin',
120-
'password' => 'password',
121-
],
122-
123-
'computer-two' => [
124-
'server' => 'computer2',
125-
'user' => 'admin',
126-
'password' => 'password',
127-
],
128-
]
129-
]
130-
]
131-
];
132-
133-
Config::instance($connections);
134-
// or
135-
new Config($connections);
136-
```
137-
138-
Either method above will instantiate the `Config` object to be used later. Again, be sure to do this prior to any
139-
calls to assure predictable behavior. If you use `Config::instance($connections)` the new connections will simply be
140-
merged in to an already started instance.
141-
142-
Accessing the configuration object in the following way keeps you from trampling over the current configuration and
143-
allows you to make global changes.
144-
145-
``` php
146-
// This is how the library accesses the Config object.
147-
$config = Config::instance();
148-
```
149-
150-
### Config Methods
151-
152-
While not all of the `Config` methods are outlined here below are the ones that may be most useful to you.
153-
154-
#### `Config::instance(array $items = [], Resolver $resolver = null)`
155-
156-
If called without any arguments this will either return the currently instantiated instance or return a new instance
157-
with default setting.
158-
159-
If called with the `$items` array set this will merge the given configuration into the currently existing configuration.
160-
161-
If called with `$resolver` set then it will replace the current `Resolver` instance with the one given. You shouldn't
162-
need to override this, but it could be useful when testing.
163-
164-
#### `Config::newInstance(array $items = [], Resolver $resolver = null)`
165-
166-
Operates the same as above with the exception that this will always return a brand new instance. This is also useful
167-
when testing to assure that previously set configuration options do not leak into other tests.
168-
169-
```php
170-
class FeatureTest extends TestCase
171-
{
172-
/** @var Config */
173-
protected $config;
174-
175-
protected function setUp(): void
176-
{
177-
$this->config = Config::newInstance();
178-
}
179-
}
180-
```
181-
182-
#### `$config->getConnection(string $name = null)`
183-
184-
Returns a connection from the `Config` container by name. If `$name` is not provided or set to `'default`` then it will
185-
return the default connection.
186-
187-
If a connection is not found it will simply return `null`.
188-
189-
#### `$config->addConnection(string $name, Connection $connection)`
190-
191-
Add a connection to the `Config` instance.
192-
193-
#### `$config->setDefaultConnection(string $name)`
194-
195-
This will set the default connection by its name. If the connection name does not exist then it will throw an
196-
`InvalidConnectionException`.
197-
198-
#### `$config->getDefaultConnection()`
199-
200-
Returns the currently set default connection.
201-
202-
#### `$config->getDefaultConnectionName()`
203-
204-
Returns the currently set default connection name.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
## The Configuration Instance
2+
3+
The configuration instance, `Config`, is the core of this library. Upon instantiation of, either a model or `Scripting`,
4+
an instance of `Config` gets created.
5+
6+
`Config` uses a singleton-like pattern to make querying on a model directly possible.
7+
Due to the usage of this pattern you typically would not `new` the `Config` object directly. However, if you feel
8+
you need to access the `Config` directly you should do so using the `::instance()` static method.
9+
10+
### Defaults
11+
12+
The only default that is currently expected to be used is the default `Connection`. This is set to the local machine
13+
that `PHP` is running on.
14+
15+
``` php
16+
# config/connections.php
17+
18+
return [
19+
'default' => 'local',
20+
21+
'servers' => [
22+
'local' => [
23+
'server' => '.',
24+
'namespace' => 'Root\CIMv2',
25+
'user' => null,
26+
'password' => null,
27+
'locale' => null,
28+
'authority' => null,
29+
'security_flags' => null,
30+
],
31+
],
32+
];
33+
```
34+
35+
If you would like to define a list of connections from a file or array you should construct the array and
36+
instantiate `Config` as follows:
37+
38+
``` php
39+
$connections = [
40+
'wmi' => [
41+
'connections' => [
42+
'default' => 'computer-two',
43+
44+
'servers' => [
45+
'computer-one' => [
46+
'server' => 'computer1',
47+
'user' => 'admin',
48+
'password' => 'password',
49+
],
50+
51+
'computer-two' => [
52+
'server' => 'computer2',
53+
'user' => 'admin',
54+
'password' => 'password',
55+
],
56+
]
57+
]
58+
]
59+
];
60+
61+
Config::instance($connections);
62+
// or
63+
new Config($connections);
64+
```
65+
66+
Either method above will instantiate the `Config` object to be used later. Again, be sure to do this prior to any
67+
calls to assure predictable behavior. If you use `Config::instance($connections)` the new connections will simply be
68+
merged in to an already started instance.
69+
70+
Accessing the configuration object in the following way keeps you from trampling over the current configuration and
71+
allows you to make global changes.
72+
73+
``` php
74+
// This is how the library accesses the Config object.
75+
$config = Config::instance();
76+
```
77+
78+
### Config Methods
79+
80+
While not all of the `Config` methods are outlined here below are the ones that may be most useful to you.
81+
82+
#### `Config::instance(array $items = [], Resolver $resolver = null)`
83+
84+
If called without any arguments this will either return the currently instantiated instance or return a new instance
85+
with default setting.
86+
87+
If called with the `$items` array set this will merge the given configuration into the currently existing configuration.
88+
89+
If called with `$resolver` set then it will replace the current `Resolver` instance with the one given. You shouldn't
90+
need to override this, but it could be useful when testing.
91+
92+
#### `Config::newInstance(array $items = [], Resolver $resolver = null)`
93+
94+
Operates the same as above with the exception that this will always return a brand new instance. This is also useful
95+
when testing to assure that previously set configuration options do not leak into other tests.
96+
97+
```php
98+
class FeatureTest extends TestCase
99+
{
100+
/** @var Config */
101+
protected $config;
102+
103+
protected function setUp(): void
104+
{
105+
$this->config = Config::newInstance();
106+
}
107+
}
108+
```
109+
110+
#### `$config->getConnection(string $name = null)`
111+
112+
Returns a connection from the `Config` container by name. If `$name` is not provided or set to `'default'` then it will
113+
return the default connection.
114+
115+
If a connection is not found it will simply return `null`.
116+
117+
#### `$config->addConnection(string $name, Connection $connection)`
118+
119+
Add a connection to the `Config` instance.
120+
121+
#### `$config->setDefaultConnection(string $name)`
122+
123+
This will set the default connection by its name. If the connection name does not exist then it will throw an
124+
`InvalidConnectionException`.
125+
126+
#### `$config->getDefaultConnection()`
127+
128+
Returns the currently set default connection.
129+
130+
#### `$config->getDefaultConnectionName()`
131+
132+
Returns the currently set default connection name.

0 commit comments

Comments
 (0)