Skip to content

Commit 01e45d4

Browse files
committed
Add installation instructions & a minimal autoloader
1 parent 66868d0 commit 01e45d4

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ The `Generator` will try to calculate the anticipated image sizes for the regist
129129

130130
## Installation
131131

132-
This library requires PHP 7.1 or later. I recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies.
132+
This library requires PHP 7.1 or later. I recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies. It's installable and autoloadable via [Composer](https://getcomposer.org/) as [jkphl/responsive-images-css](https://packagist.org/packages/jkphl/responsive-images-css).
133+
134+
```bash
135+
composer require jkphl/responsive-images-css
136+
```
137+
138+
Alternatively, [download a release](https://github.com/jkphl/responsive-images-css/releases) or clone this repository, then require or include its [`autoload.php`](autoload.php) file.
133139

134140
## Dependencies
135141

autoload.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* responsive-images-css
5+
*
6+
* @category Jkphl
7+
* @package Jkphl\Respimgcss
8+
* @author Joschi Kuphal <[email protected]> / @jkphl
9+
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
10+
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
11+
*/
12+
13+
/***********************************************************************************
14+
* The MIT License (MIT)
15+
*
16+
* Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
17+
*
18+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
19+
* this software and associated documentation files (the "Software"), to deal in
20+
* the Software without restriction, including without limitation the rights to
21+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
22+
* the Software, and to permit persons to whom the Software is furnished to do so,
23+
* subject to the following conditions:
24+
*
25+
* The above copyright notice and this permission notice shall be included in all
26+
* copies or substantial portions of the Software.
27+
*
28+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
30+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
31+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
32+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34+
***********************************************************************************/
35+
36+
/**
37+
* Register a minimal PSR-4 compatible autoloader
38+
*
39+
* @see http://www.php-fig.org/psr/psr-4/
40+
*/
41+
spl_autoload_register(
42+
function ($class) {
43+
$namespace = 'Jkphl';
44+
$prefixes = [
45+
"{$namespace}\\" => [
46+
__DIR__.'/src',
47+
],
48+
];
49+
foreach ($prefixes as $prefix => $dirs) {
50+
$prefixLength = strlen($prefix);
51+
if (substr($class, 0, $prefixLength) !== $prefix) {
52+
continue;
53+
}
54+
$class = substr($class, $prefixLength);
55+
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
56+
foreach ($dirs as $dir) {
57+
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
58+
$file = $dir.DIRECTORY_SEPARATOR.$part;
59+
if (is_readable($file)) {
60+
require $file;
61+
return;
62+
}
63+
}
64+
}
65+
}
66+
);

0 commit comments

Comments
 (0)