|
1 | 1 | # R2D2 |
2 | 2 |
|
3 | 3 |  |
4 | | -[](https://github.com/dutchenkoOleg/node-w3c-validator/blob/master/LICENSE) |
| 4 | +[](https://github.com/WezomAgency/r2d2/blob/master/LICENSE) |
5 | 5 | [](https://packagist.org/packages/wezom-agency/r2d2) |
6 | 6 | [](https://github.com/WezomAgency) |
7 | 7 |
|
|
11 | 11 |
|
12 | 12 | --- |
13 | 13 |
|
14 | | -### *Table of contents* |
15 | | - |
16 | | -- [Install](#install) |
17 | | -- [Setup](#setup) |
18 | | -- [API](#api) |
19 | | - - [eject](#eject) |
20 | | - - [instance::set](#instanceset) |
21 | | - - [instance::fileUrl](#instancefileurl) |
22 | | - - [instance::fileContent](#instancefilecontent) |
23 | | - - [instance::resourceUrl](#instanceresourceurl) |
24 | | - - [instance::resourceContent](#instanceresourcecontent) |
25 | | - - [instance::str2number](#instancestr2number) |
26 | | - |
27 | | ---- |
28 | 14 |
|
29 | 15 |
|
30 | | - |
31 | | -# Install |
| 16 | +### Install |
32 | 17 |
|
33 | 18 | ```bash |
34 | 19 | composer require wezom-agency/r2d2 |
35 | 20 | ``` |
36 | 21 |
|
37 | 22 | --- |
38 | 23 |
|
39 | | -# Setup |
| 24 | +### Setup |
40 | 25 |
|
41 | 26 | in your core app file: |
42 | 27 |
|
43 | 28 | ```php |
44 | | -use WezomAgency\R2D2; |
45 | | - |
46 | | -R2D2::eject()->set('KEY', VALUE); |
47 | | - |
48 | | -``` |
49 | | - |
50 | | -List of settings: |
51 | | - |
52 | | -- `debug: bool = false` |
53 | | -- `host: string = ''` |
54 | | -- `protocol: string = 'http://'` |
55 | | -- `rootPath: string = ''` |
56 | | -- `resourceRelativePath: string = ''` - _"shortcut"_ to your resources/assets directory |
57 | | -- `svgSpritemapPath: string = ''` - default path to svg sprite map file |
58 | | - |
59 | | - |
60 | | -Example of settings |
61 | | - |
62 | | -```php |
63 | | -use WezomAgency\R2D2; |
64 | | - |
65 | | -R2D2::eject() |
66 | | - ->set(debug, true) |
67 | | - ->set('host', $_SERVER['HTTP_HOST']) |
68 | | - ->set('protocol', 'https://') |
69 | | - ->set('rootPath', './') |
70 | | - ->set('resourceRelativePath', '/my/path/to/resources/') |
71 | | - ->set( |
72 | | - 'svgSpritemapPath', |
73 | | - R2D2::eject()->resourceUrl('assets/svg/common.svg', true) |
74 | | - ); |
75 | | -``` |
76 | | - |
77 | | ---- |
78 | | - |
79 | | -# API |
80 | | - |
81 | | -## eject |
82 | | - |
83 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
84 | | - |
85 | | -```php |
86 | | -R2D2::eject() instance |
| 29 | +WezomAgency\R2D2::eject()->set('KEY', VALUE); |
87 | 30 | ``` |
88 | 31 |
|
89 | | -Ejecting R2D2 instance. |
90 | | -Below a list of instance methods |
91 | | - |
92 | | - |
93 | | ---- |
94 | | - |
95 | | -## instance::set |
96 | | - |
97 | | -Setup instance |
98 | | - |
99 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
100 | | - |
101 | | -```php |
102 | | -R2D2::eject()->set($key, $value) instance |
103 | | -``` |
104 | | - |
105 | | -_Parameters:_ |
106 | | - |
107 | | -| Name | Data type | Default value | Description | |
108 | | -| :--------- | :-------- | :------------ | :------------- | |
109 | | -| **$name** | _string_ | | settings name | |
110 | | -| **$value** | _any_ | | settings value | |
111 | | - |
112 | | -List of available settings and their values, see above ([#setup section](#setup)) |
113 | | - |
114 | | - |
| 32 | +[See list of all settings ►](https://github.com/WezomAgency/r2d2/blob/master/docs/api/instance-set.md) |
115 | 33 |
|
116 | 34 | --- |
117 | 35 |
|
118 | | -## instance::fileUrl |
119 | | - |
120 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
121 | | - |
122 | | -Generate file URL |
123 | | - |
124 | | -```php |
125 | | -R2D2::eject()->fileUrl($url, $timestamp = false, $absolute = false) string |
126 | | -``` |
127 | | - |
128 | | - |
129 | | -_Parameters:_ |
130 | | - |
131 | | -| Name | Data type | Default value | Description | |
132 | | -| :------------- | :-------- | :------------ | :------------- | |
133 | | -| **$url** | _string_ | | file relative url, from site root, e.q `/assets/css/my.css` | |
134 | | -| **$timestamp** | _boolean_ | `false` | set file versioning with query pair `?time=xxx`, if file doesn't exist - query will be empty string | |
135 | | -| **$absolute** | _boolean_ | `false` | generate absolute url, with `protocol` and `host` setting (see [#setup section](#setup)) | |
136 | | - |
137 | | -_Returns:_ URL |
138 | | - |
139 | | - |
140 | | -#### Usage example |
141 | | - |
142 | | -```php |
143 | | -<?php |
144 | | - |
145 | | -use WezomAgency\R2D2; |
146 | | - |
147 | | -// in core app file: |
148 | | -// R2D2::eject() |
149 | | -// ->set('host', 'my-site.com') |
150 | | -// ->set('protocol', 'https://') |
151 | | - |
152 | | -?> |
153 | | -<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style1.css'); ?>"> |
154 | | -<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style2.css', true); ?>"> |
155 | | -<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style3.css', true, true); ?>"> |
156 | | -``` |
157 | | -#### Result |
158 | | - |
159 | | -```html |
160 | | -<link rel="stylesheet" href="/assets/css/style1.css"> |
161 | | -<link rel="stylesheet" href="/assets/css/style2.css?time=1545054627"> |
162 | | -<link rel="stylesheet" href="https://my-site.com/assets/css/style3.css?time=1545054627"> |
163 | | -``` |
| 36 | +### API |
164 | 37 |
|
| 38 | +[See docs sections ►](https://github.com/WezomAgency/r2d2/blob/master/docs/index.md) |
165 | 39 |
|
166 | 40 | --- |
167 | 41 |
|
168 | | -## instance::fileContent |
169 | | - |
170 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
171 | | - |
172 | | -Get file contents |
173 | | - |
174 | | -```php |
175 | | -R2D2::eject()->fileContent($path) string |
176 | | -``` |
177 | | - |
178 | | -_Parameters:_ |
179 | | - |
180 | | -| Name | Data type | Default value | Description | |
181 | | -| :------------- | :-------- | :------------ | :------------- | |
182 | | -| **$path** | _string_ | | file relative url, from the `rootPath` (see [#setup section](#setup)) | |
183 | | - |
184 | | -_Returns:_ file contents |
185 | | - |
186 | | - |
187 | | -#### Usage example |
188 | | - |
189 | | -```php |
190 | | -<?php |
191 | | - |
192 | | -use WezomAgency\R2D2; |
193 | | - |
194 | | -// in core app file: |
195 | | -// R2D2::eject() |
196 | | -// ->set('rootPath', './') |
197 | | - |
198 | | -?> |
199 | | -<style><?= R2D2::eject()->fileContent('/assets/css/critical.css'); ?></style> |
200 | | -``` |
201 | | -#### Result |
202 | | - |
203 | | -```html |
204 | | -<style>html{font:14px/1.3em Arial;color:#222}h1{color:red;font-size:2em}.wysiswyg{font-size:16px;line-height:normal}</style> |
205 | | -``` |
206 | | - |
207 | | - |
208 | | - |
209 | | ---- |
210 | | - |
211 | | -## instance::resourceUrl |
212 | | - |
213 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
214 | | - |
215 | | -This is the same method as [`instance::fileUrl`](#instancefileurl). |
216 | | -The only difference is in the relative path that is used to create a full URL. |
217 | | - |
218 | | -This can be useful for frequently used paths that have a large nesting of directories. |
219 | | -You can _"save"_ initial part of the path, and specify the rest when calling the method. |
220 | | - |
221 | | - |
222 | | -```php |
223 | | -R2D2::eject()->resourceUrl($url, $timestamp = false, $absolute = false) string |
224 | | -``` |
225 | | - |
226 | | - |
227 | | -_Parameters:_ |
228 | | - |
229 | | -| Name | Data type | Default value | Description | |
230 | | -| :------------- | :-------- | :------------ | :------------- | |
231 | | -| **$url** | _string_ | | file relative url, from the `resourceRelativePath` (see [#setup section](#setup)) | |
232 | | -| **$timestamp** | _boolean_ | `false` | set file versioning with query pair `?time=xxx`, if file doesn't exist - query will be empty string | |
233 | | -| **$absolute** | _boolean_ | `false` | generate absolute url, with `protocol` and `host` setting (see [#setup section](#setup)) | |
234 | | - |
235 | | -_Returns:_ URL |
236 | | - |
237 | | - |
238 | | -#### Usage example |
239 | | - |
240 | | -```php |
241 | | -<?php |
242 | | - |
243 | | -use WezomAgency\R2D2; |
244 | | - |
245 | | -// in core app file: |
246 | | -// R2D2::eject() |
247 | | -// ->set('resourceRelativePath', '/my/path/to/resources/folder') |
248 | | - |
249 | | -?> |
250 | | -<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style1.css'); ?>"> |
251 | | -<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style2.css', true); ?>"> |
252 | | -<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style3.css', true, true); ?>"> |
253 | | -``` |
254 | | -#### Result |
255 | | - |
256 | | -```html |
257 | | -<link rel="stylesheet" href="/my/path/to/resources/folder/css/style1.css"> |
258 | | -<link rel="stylesheet" href="/my/path/to/resources/folder/css/style2.css?time=1545054627"> |
259 | | -<link rel="stylesheet" href="https://my-site.com/my/path/to/resources/folder/css/style3.css?time=1545054627"> |
260 | | -``` |
261 | | - |
262 | | - |
263 | | ---- |
264 | | - |
265 | | -### instance::resourceContent |
266 | | - |
267 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
268 | | - |
269 | | -This is the same method as [`instance::fileContent`](#instancefilecontent). |
270 | | -The only difference is in the relative path that is used to create a full path to the file. |
271 | | - |
272 | | -This can be useful for frequently used paths that have a large nesting of directories. |
273 | | -You can _"save"_ initial part of the path, and specify the rest when calling the method. |
274 | | - |
275 | | -```php |
276 | | -R2D2::eject()->resourceContent($path) string |
277 | | -``` |
278 | | - |
279 | | -_Parameters:_ |
280 | | - |
281 | | -| Name | Data type | Default value | Description | |
282 | | -| :------------- | :-------- | :------------ | :------------- | |
283 | | -| **$path** | _string_ | | file relative url, from the `rootPath` (see [#setup section](#setup)) | |
284 | | - |
285 | | -_Returns:_ file content |
286 | | - |
287 | | - |
288 | | -#### Usage example |
289 | | - |
290 | | -```php |
291 | | -<?php |
292 | | - |
293 | | -use WezomAgency\R2D2; |
294 | | - |
295 | | -// in core app file: |
296 | | -// R2D2::eject() |
297 | | -// ->set('rootPath', './') |
298 | | -// ->set('resourceRelativePath', '/my/path/to/resources/folder') |
299 | | - |
300 | | -?> |
301 | | -<style><?= R2D2::eject()->resourceContent('css/critical.css'); ?></style> |
302 | | -<!-- will get content from file ./my/path/to/resources/folder/css/critical.css --> |
303 | | -``` |
304 | | -#### Result |
305 | | - |
306 | | -```html |
307 | | -<style>html{font:14px/1.3em Arial;color:#222}h1{color:red;font-size:2em}.wysiswyg{font-size:16px;line-height:normal}</style> |
308 | | -``` |
309 | | - |
310 | | - |
311 | | - |
312 | | - |
313 | | - |
314 | | ---- |
315 | | - |
316 | | -### instance::str2number |
317 | | - |
318 | | -:arrow_up: [_Table of contents_](#table-of-contents) |
319 | | - |
320 | | -This method is used to convert string attribute values to numbers. |
321 | | - |
322 | | -```php |
323 | | -R2D2::eject()->str2number($value = '', $int = false) float|int |
324 | | -``` |
325 | | - |
326 | | -_Parameters:_ |
327 | | - |
328 | | -| Name | Data type | Default value | Description | |
329 | | -| :------------- | :--------- | :------------ | :-------------------- | |
330 | | -| **$value** | _string_ | empty string | html attr value | |
331 | | -| **$int** | _boolean_ | `false` | returns only integers | |
332 | | - |
333 | | -_Returns:_ float / int / 0 - if `$value` includes `%` character |
334 | | - |
335 | | - |
| 42 | +### License |
336 | 43 |
|
| 44 | +[MIT License ►](https://github.com/WezomAgency/r2d2/blob/master/LICENSE) |
0 commit comments