Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit f77eba2

Browse files
author
Nate Wiebe
authored
Merge pull request #16 from Pixelrobin/psr-12
Format files
2 parents 653b534 + 34f3851 commit f77eba2

File tree

8 files changed

+246
-185
lines changed

8 files changed

+246
-185
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
# php-feather
2+
23
PHP Library for [Feather](https://feathericons.com/).
34

45
For more information on Feather itself, please refer to their [README](https://github.com/feathericons/feather).
56

67
This project is still pretty young, and I'm still a little new to PHP. Suggestions are welcome!
78

89
## Installing
10+
911
php-feather uses [Composer](https://getcomposer.org/). Run the following to install it.
12+
1013
```
1114
composer require pixelrobin/php-feather
1215
```
16+
1317
If you want to install composer without all the tests and nodejs stuff, use `--prefer-dist`.
18+
1419
```
1520
composer require pixelrobin/php-feather --prefer-dist
1621
```
22+
1723
Then, don't forget to autoload your Composer packages!
24+
1825
```php
1926
require 'vendor/autoload.php';
2027
```
28+
2129
## Usage
30+
2231
### Get an icon
32+
2333
Icons echo by default.
34+
2435
```php
2536
<?php
2637
require 'vendor/autoload.php';
@@ -35,13 +46,17 @@ $icons = new Feather\Icons;
3546
```
3647

3748
### Get an icon with modified properties
49+
3850
Simply pass an array with the attributes you want. This will be merged over the `Icons` class default attributes, except for `class`, which gets concatenated to the default classes.
51+
3952
```php
4053
$icons->get('feather', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
4154
// <svg ... class="feather feather-feather fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>
4255
```
4356

44-
You can also change the default attributes in the `Icons` class if you want some attributes consistent across multiple `get` calls. The passed attributes are merged over the current attributes in the class by default.
57+
You can also change the default attributes in the `Icons` class if you want some attributes consistent across multiple `get` calls. The passed attributes are merged over the current attributes in the
58+
class by default.
59+
4560
```php
4661
$icons->setAttributes(array(
4762
'color' => 'red',
@@ -51,24 +66,32 @@ $icons->setAttributes(array(
5166
$icons->get('mail');
5267
// <svg ... color="red" stroke-width="3" ... >...</svg>
5368
```
69+
5470
### Get an icon as a string
71+
5572
Set the third argument to `false` to get a string instead of echoing the icon.
73+
5674
```php
5775
$icon_string = $icons->get('activity', array(), false);
5876
// Then do whatever with $icon_string
5977
```
6078

6179
## API
80+
6281
### `Feather\Icons`
82+
6383
Usage:
84+
6485
```php
6586
$icons = new Feather\Icons;
6687
```
6788

6889
<br>
6990

7091
### `Feather\Icons->get($name, $attributes = array(), $echo = true)`
92+
7193
Gets an icon as svg. Can be echoed (default) or returned as a string. Attributes passed will be merged over the class defaults.
94+
7295
```php
7396
$icons = new Feather\Icons;
7497

@@ -84,7 +107,9 @@ $icons->get('battery', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-l
84107
$cloud_icon = $icons->get('cloud', array(), false);
85108
doStuffWith($cloud_icon);
86109
```
110+
87111
#### Arguments
112+
88113
|Argument |Type |Description |
89114
|------------|-------|---------------------------------------------------------------------------------|
90115
|$name |string |The name of the icon. A full list can be found [here](https://feathericons.com/).|
@@ -94,7 +119,10 @@ doStuffWith($cloud_icon);
94119
<br>
95120

96121
### `Feather\Icons->setAttributes($attributes, $merge = true)`
97-
Sets default attributes of the class. These are used as default attributes for the `get` method. By default, the `$attributes` argument is merged over the current attributes in the class. You can disable this by setting the `$merge` argument to false, but only do it if you know what you are doing.
122+
123+
Sets default attributes of the class. These are used as default attributes for the `get` method. By default, the `$attributes` argument is merged over the current attributes in the class. You can
124+
disable this by setting the `$merge` argument to false, but only do it if you know what you are doing.
125+
98126
```php
99127
$icons = new Feather\Icons;
100128

@@ -105,7 +133,9 @@ $icons->setAttributes(array('color' => 'red', 'stroke-width' => 3));
105133
$icons->get('delete');
106134
// <svg ... color="red" stroke-width="1" ... >...</svg>
107135
```
136+
108137
#### Arguments
138+
109139
|Argument |Type |Description |
110140
|-----------|-------|---------------------------------------------------------------------------|
111141
|$attributes|array |Attributes to add |
@@ -114,7 +144,9 @@ $icons->get('delete');
114144
<br>
115145

116146
### `Feather\Icons->getAttributes()`
147+
117148
Get the current attributes for the class. To set it, use the `setAttributes()` method;
149+
118150
```php
119151
$icons = new Feather\Icons;
120152

@@ -124,7 +156,9 @@ $attrs = $icons->getAttributes();
124156
<br>
125157

126158
### `Feather\DEFAULT_ATTRIBUTES`
159+
127160
Constant array of default attributes. They are applied to every new `Icons` class. You can use this to reset the attributes of an `Icons` class.
161+
128162
```php
129163
$icons = new Feather\Icons;
130164

@@ -139,13 +173,15 @@ $icons->setAttributes(Feather\DEFAULT_ATTRIBUTES, false);
139173
```
140174

141175
## Contributing
176+
142177
Feel free to open up issues and PRs for suggesstions.
143178

144179
Developing requires both nodejs and composer. The icons are included as a node module and built for use in php.
145180

146181
Better contributing docs are coming soon!
147182

148183
## License
184+
149185
Licensed under the [MIT License](https://github.com/Pixelrobin/php-feather/blob/master/LICENSE).
150186

151187
The icons in this code are from [Feather](https://github.com/feathericons/feather). It is also licensed under the [MIT License](https://github.com/feathericons/feather/blob/master/LICENSE).

bin/build.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ const feather = require('feather-icons');
22
const fs = require('fs');
33
const path = require('path');
44

5-
const outPath = path.resolve(__dirname, '../icons');
5+
const outPath = path.resolve(__dirname, '../icons');
66
let defaultAttrs = null;
77

88
Object.keys(feather.icons)
9-
.forEach(key => {
10-
const { name, contents, attrs } = feather.icons[key];
9+
.forEach(key => {
10+
const {name, contents, attrs} = feather.icons[key];
1111

12-
if (defaultAttrs === null) {
13-
defaultAttrs = attrs;
14-
}
12+
if (defaultAttrs === null) {
13+
defaultAttrs = attrs;
14+
}
1515

16-
fs.writeFileSync(path.resolve(outPath, name + '.svg'), contents);
17-
});
16+
fs.writeFileSync(path.resolve(outPath, name + '.svg'), contents);
17+
});
1818

1919
delete defaultAttrs.class;
2020

2121
let php = Object.keys(defaultAttrs)
22-
.map(key => `'${ key }' => '${ defaultAttrs[key] }'`)
23-
.reduce((final, current) => final + current + ',', '');
22+
.map(key => `'${key}' => '${defaultAttrs[key]}'`)
23+
.reduce((final, current) => final + current + ',', '');
2424

2525
php = '<?php\n\n'
26-
+ '/* !!! THIS FILE IS AUTO-GENERATED !!! */\n\n'
27-
+ 'namespace Feather; const DEFAULT_ATTRIBUTES = array('
28-
+ php.substring(0, php.length - 1)
29-
+ ');';
26+
+ '/* !!! THIS FILE IS AUTO-GENERATED !!! */\n\n'
27+
+ 'namespace Feather; const DEFAULT_ATTRIBUTES = array('
28+
+ php.substring(0, php.length - 1)
29+
+ ');';
3030

3131
fs.writeFileSync(path.resolve(__dirname, '../src/defaultAttributes.php'), php);

composer.json

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
{
2-
"name": "pixelrobin/php-feather",
3-
"type": "library",
4-
"description": "PHP library for feather icons",
5-
"keywords": ["feather", "icons", "svg", "pixelrobin"],
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Michael Savchuk",
10-
"email": "[email protected]"
11-
},
12-
{
13-
"name": "Nate Wiebe",
14-
"email": "[email protected]"
15-
}
16-
],
17-
"autoload": {
18-
"psr-4": {
19-
"Feather\\": "src/"
20-
}
21-
},
22-
"require": {
23-
"php": ">=5.6.0"
24-
},
25-
"require-dev": {
26-
"phpunit/phpunit": "7"
27-
}
2+
"name": "pixelrobin/php-feather",
3+
"type": "library",
4+
"description": "PHP library for feather icons",
5+
"keywords": [
6+
"feather",
7+
"icons",
8+
"svg",
9+
"pixelrobin"
10+
],
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Michael Savchuk",
15+
"email": "[email protected]"
16+
},
17+
{
18+
"name": "Nate Wiebe",
19+
"email": "[email protected]"
20+
}
21+
],
22+
"autoload": {
23+
"psr-4": {
24+
"Feather\\": "src/"
25+
}
26+
},
27+
"require": {
28+
"php": ">=5.6.0"
29+
},
30+
"require-dev": {
31+
"phpunit/phpunit": "7"
32+
}
2833
}

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"name": "feather-php",
3-
"version": "1.0.0",
4-
"description": "PHP library for feather icons",
5-
"main": "index.js",
6-
"scripts": {
7-
"build": "node bin/build.js",
8-
"test": "node tests/prepare && vendor/bin/phpunit --verbose --bootstrap vendor/autoload.php tests/FeatherTest"
9-
},
10-
"author": "",
11-
"license": "MIT",
12-
"dependencies": {
13-
"feather-icons": "^4.26.0"
14-
}
2+
"name": "feather-php",
3+
"version": "1.0.0",
4+
"description": "PHP library for feather icons",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "node bin/build.js",
8+
"test": "node tests/prepare && vendor/bin/phpunit --verbose --bootstrap vendor/autoload.php tests/FeatherTest"
9+
},
10+
"author": "",
11+
"license": "MIT",
12+
"dependencies": {
13+
"feather-icons": "^4.26.0"
14+
}
1515
}

0 commit comments

Comments
 (0)