|
9 | 9 |
|
10 | 10 | <img src="https://raw.githubusercontent.com/dutchenkoOleg/storage/master/img/r2d2/r2d2.gif" alt> |
11 | 11 |
|
12 | | ----- |
| 12 | +--- |
| 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 | + |
| 24 | +--- |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +# Install |
| 29 | + |
| 30 | +```bash |
| 31 | +composer require wezom-agency/browserizr |
| 32 | +``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +# Setup |
| 37 | + |
| 38 | +in your core app file: |
| 39 | + |
| 40 | +```php |
| 41 | +use WezomAgency\R2D2; |
| 42 | + |
| 43 | +R2D2::eject()->set('KEY', VALUE); |
| 44 | + |
| 45 | +``` |
| 46 | + |
| 47 | +List of settings: |
| 48 | + |
| 49 | +- `debug: bool = false` |
| 50 | +- `host: string = ''` |
| 51 | +- `protocol: string = 'http://'` |
| 52 | +- `rootPath: string = ''` |
| 53 | +- `resourceRelativePath: string = ''` - _"shortcut"_ to your resources/assets directory |
| 54 | +- `svgSpritemapPath: string = ''` - default path to svg sprite map file |
| 55 | + |
| 56 | + |
| 57 | +Example of settings |
| 58 | + |
| 59 | +```php |
| 60 | +use WezomAgency\R2D2; |
| 61 | + |
| 62 | +R2D2::eject() |
| 63 | + ->set(debug, true) |
| 64 | + ->set('host', $_SERVER['HTTP_HOST']) |
| 65 | + ->set('protocol', 'https://') |
| 66 | + ->set('rootPath', './') |
| 67 | + ->set('resourceRelativePath', '/my/path/to/resources/') |
| 68 | + ->set( |
| 69 | + 'svgSpritemapPath', |
| 70 | + R2D2::eject()->resourceUrl('assets/svg/common.svg', true) |
| 71 | + ); |
| 72 | +``` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +# API |
| 77 | + |
| 78 | +## eject |
| 79 | + |
| 80 | +```php |
| 81 | +R2D2::eject() instance |
| 82 | +``` |
| 83 | + |
| 84 | +Ejecting R2D2 instance. |
| 85 | +Below a list of instance methods |
| 86 | + |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +### instance::set |
| 91 | + |
| 92 | +```php |
| 93 | +R2D2::eject()->set($key, $value) instance |
| 94 | +``` |
| 95 | + |
| 96 | +_Parameters:_ |
| 97 | + |
| 98 | +| Name | Data type | Default value | Description | |
| 99 | +| :--------- | :-------- | :------------ | :------------- | |
| 100 | +| **$name** | _string_ | | settings name | |
| 101 | +| **$value** | _any_ | | settings value | |
| 102 | + |
| 103 | +List of available settings and their values, see above ([#setup section](#setup)) |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +### instance::fileUrl |
| 110 | + |
| 111 | +Generate file url. |
| 112 | + |
| 113 | +```php |
| 114 | +R2D2::eject()->fileUrl($url, $timestamp = false, $absolute = false) string |
| 115 | +``` |
| 116 | + |
| 117 | + |
| 118 | +_Parameters:_ |
| 119 | + |
| 120 | +| Name | Data type | Default value | Description | |
| 121 | +| :------------- | :-------- | :------------ | :------------- | |
| 122 | +| **$url** | _string_ | | file relative url, from site root, e.q `/assets/css/my.css` | |
| 123 | +| **$timestamp** | _booleab_ | `false` | set file versioning with query pair `?time=xxx`, if file doesn't exist - query will be empty string | |
| 124 | +| **$absolute** | _booleab_ | `false` | generate absolute url, with `protocol` and `host` setting (see [#setup section](#setup)) | |
| 125 | + |
| 126 | +_Returns:_ URL |
| 127 | + |
| 128 | + |
| 129 | +#### Usage example |
| 130 | + |
| 131 | +```php |
| 132 | +<?php |
| 133 | + |
| 134 | +use WezomAgency\R2D2; |
| 135 | + |
| 136 | +// in core app file: |
| 137 | +// R2D2::eject() |
| 138 | +// ->set('host', 'my-site.com') |
| 139 | +// ->set('protocol', 'https://') |
| 140 | + |
| 141 | +?> |
| 142 | +<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style1.css'); ?>"> |
| 143 | +<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style2.css', true); ?>"> |
| 144 | +<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style3.css', true, true); ?>"> |
| 145 | +``` |
| 146 | +#### Result |
| 147 | + |
| 148 | +```html |
| 149 | +<link rel="stylesheet" href="/assets/css/style1.css"> |
| 150 | +<link rel="stylesheet" href="/assets/css/style2.css?time=1545054627"> |
| 151 | +<link rel="stylesheet" href="https://my-site.com/assets/css/style3.css?time=1545054627"> |
| 152 | +``` |
| 153 | + |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +### instance::fileContent |
| 158 | + |
| 159 | +Get file content. |
| 160 | + |
| 161 | +```php |
| 162 | +R2D2::eject()->fileContent($path) string |
| 163 | +``` |
| 164 | + |
| 165 | +_Parameters:_ |
| 166 | + |
| 167 | +| Name | Data type | Default value | Description | |
| 168 | +| :------------- | :-------- | :------------ | :------------- | |
| 169 | +| **$path** | _string_ | | file relative url, from the `rootPath` (see [#setup section](#setup)) | |
| 170 | + |
| 171 | +_Returns:_ file content |
| 172 | + |
| 173 | + |
| 174 | +#### Usage example |
| 175 | + |
| 176 | +```php |
| 177 | +<?php |
| 178 | + |
| 179 | +use WezomAgency\R2D2; |
| 180 | + |
| 181 | +// in core app file: |
| 182 | +// R2D2::eject() |
| 183 | +// ->set('rootPath', './') |
| 184 | + |
| 185 | +?> |
| 186 | +<style><?= R2D2::eject()->fileContent('/assets/css/critical.css'); ?></style> |
| 187 | +``` |
| 188 | +#### Result |
| 189 | + |
| 190 | +```html |
| 191 | +<style>html{font:14px/1.3em Arial;color:#222}h1{color:red;font-size:2em}.wysiswyg{font-size:16px;line-height:normal}</style> |
| 192 | +``` |
| 193 | + |
| 194 | + |
| 195 | + |
0 commit comments