Skip to content

Commit da51b11

Browse files
committed
Update docs
1 parent 985249b commit da51b11

File tree

5 files changed

+106
-87
lines changed

5 files changed

+106
-87
lines changed

docs/.vuepress/config.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@ module.exports = {
2222
sidebar: {
2323
'/documentation': [
2424
{
25-
title: 'Documentation',
25+
title: 'Quick Start',
2626
collapsable: false,
2727
children: [
2828
['documentation/', 'How It Works'],
2929
['documentation/getting-started', 'Getting Started'],
30-
['documentation/configuration', 'Configuration'],
31-
['documentation/the-config-instance', 'The Config Instance'],
30+
// ['documentation/configuration', 'Configuration'],
3231
]
33-
}
34-
]
32+
},
33+
{
34+
title: 'Digging Deeper',
35+
collapsable: false,
36+
children: [
37+
['documentation/digging-deeper/', 'Introduction'],
38+
['documentation/digging-deeper/the-config-instance', 'The Config Instance'],
39+
]
40+
},
41+
],
3542
}
3643
}
3744
};

docs/documentation/configuration.md

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Introduction
2+
3+
The following section will dive into the internals of the library. You typically do not need to dive this
4+
deep, but I feel it would be good to document it for all of our benefit.

docs/documentation/the-config-instance.md renamed to docs/documentation/digging-deeper/the-config-instance.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## The Configuration Instance
1+
# The Config Instance
22

33
The configuration instance, `Config`, is the core of this library. Upon instantiation of, either a model or `Scripting`,
44
an instance of `Config` gets created.
@@ -7,7 +7,7 @@ an instance of `Config` gets created.
77
Due to the usage of this pattern you typically would not `new` the `Config` object directly. However, if you feel
88
you need to access the `Config` directly you should do so using the `::instance()` static method.
99

10-
### Defaults
10+
## Defaults
1111

1212
The only default that is currently expected to be used is the default `Connection`. This is set to the local machine
1313
that `PHP` is running on.
@@ -75,10 +75,11 @@ allows you to make global changes.
7575
$config = Config::instance();
7676
```
7777

78-
### Config Methods
78+
## Config Methods
7979

8080
While not all of the `Config` methods are outlined here below are the ones that may be most useful to you.
8181

82+
### instance
8283
#### `Config::instance(array $items = [], Resolver $resolver = null)`
8384

8485
If called without any arguments this will either return the currently instantiated instance or return a new instance
@@ -89,6 +90,7 @@ If called with the `$items` array set this will merge the given configuration in
8990
If called with `$resolver` set then it will replace the current `Resolver` instance with the one given. You shouldn't
9091
need to override this, but it could be useful when testing.
9192

93+
### newInstance
9294
#### `Config::newInstance(array $items = [], Resolver $resolver = null)`
9395

9496
Operates the same as above with the exception that this will always return a brand new instance. This is also useful
@@ -107,26 +109,32 @@ class FeatureTest extends TestCase
107109
}
108110
```
109111

112+
### getConnection
110113
#### `$config->getConnection(string $name = null)`
111114

112115
Returns a connection from the `Config` container by name. If `$name` is not provided or set to `'default'` then it will
113116
return the default connection.
114117

115118
If a connection is not found it will simply return `null`.
116119

120+
### addConnection
117121
#### `$config->addConnection(string $name, Connection $connection)`
118122

119123
Add a connection to the `Config` instance.
120124

125+
### setDefaultConnection
121126
#### `$config->setDefaultConnection(string $name)`
122127

123128
This will set the default connection by its name. If the connection name does not exist then it will throw an
124129
`InvalidConnectionException`.
125130

126-
#### `$config->getDefaultConnection()`
127-
128-
Returns the currently set default connection.
129131

132+
### getDefaultConnectionName
130133
#### `$config->getDefaultConnectionName()`
131134

132135
Returns the currently set default connection name.
136+
137+
### getDefaultConnection
138+
#### `$config->getDefaultConnection()`
139+
140+
Returns the currently set default connection.

docs/documentation/getting-started.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,79 @@ Windows and the `com_dotnet` extension enabled (available in every [`Windows PHP
1010
## Install
1111
``` sh
1212
composer require phpwintools/wmi-scripting
13-
```
13+
```
14+
15+
## Basic Configuration
16+
17+
There isn't much configuration that needs to be done to get started with this library. You only need to set the
18+
connections before using this in your own application.
19+
20+
### Local Connection
21+
``` php
22+
// Returns a ModelCollection of LoggedOnUser models from the local machine
23+
$local = LoggedOnUser::query()->get();
24+
25+
$scripting = new Scripting;
26+
// Same as above
27+
$local = $scripting->query()->loggedOnUser()->get();
28+
```
29+
30+
If no configuration is provided then the library's default connection is localhost.
31+
32+
### Static call on Win32Model class
33+
``` php
34+
$connection = Connection::simple('computer-one', 'admin', 'password');
35+
36+
// Returns an instance of Query\Builder
37+
$builder = LoggedOnUser::query($connection);
38+
39+
// Returns a ModelCollection of Models\LoggedOnUsers
40+
$loggedOnUsers = $builder->get();
41+
```
42+
43+
A connection defined in this way will not be stored in the `Config` container. This is useful when you need to reference
44+
many connections in an array to poll many computers across your network.
45+
46+
``` php
47+
$username = 'admin';
48+
$password = 'password';
49+
$computers = ['computer_one', 'computer_two'];
50+
51+
$results = [];
52+
53+
foreach ($computers as $computer) {
54+
// $results becomes an array of ModelCollections
55+
$results[] = LoggedOnUser::query(Connection::simple($computer, $user $password));
56+
}
57+
```
58+
59+
### With `Scripting` Class
60+
``` php
61+
$scripting = new Scripting(Connection::simple('computer-one', 'admin', 'password));
62+
63+
// Returns and instance of Query\Builder (same as above)
64+
$builder = $scripting->query()->loggedOnUser();
65+
```
66+
67+
This will set the given connection as the default connection. All models queried without a given connection will use
68+
this connection.
69+
70+
``` php
71+
$scripting = new Scripting;
72+
$scripting->addConnection(
73+
'computer-one',
74+
Connection::simple('computer-one', 'admin', 'password')
75+
);
76+
77+
$builder = $scripting->query('computer-one)->loggedOnUser();
78+
79+
// This connection is also available to the Models
80+
$builder = LoggedOnUser::query('computer-one');
81+
```
82+
83+
Adding a connection in this way will store the connection for later and repeated use.
84+
85+
::: danger
86+
`Scripting` should only be instantiated once. If it is instantiated more than once then the last configuration options
87+
will be used.
88+
:::

0 commit comments

Comments
 (0)