Skip to content

Format files #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
# php-feather

PHP Library for [Feather](https://feathericons.com/).

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

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

## Installing

php-feather uses [Composer](https://getcomposer.org/). Run the following to install it.

```
composer require pixelrobin/php-feather
```

If you want to install composer without all the tests and nodejs stuff, use `--prefer-dist`.

```
composer require pixelrobin/php-feather --prefer-dist
```

Then, don't forget to autoload your Composer packages!

```php
require 'vendor/autoload.php';
```

## Usage

### Get an icon

Icons echo by default.

```php
<?php
require 'vendor/autoload.php';
Expand All @@ -35,13 +46,17 @@ $icons = new Feather\Icons;
```

### Get an icon with modified properties

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.

```php
$icons->get('feather', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-label' => 'Battery icon'));
// <svg ... class="feather feather-feather fooclass", stroke-width="1", aria-label="Battery icon" ... >...</svg>
```

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.
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.

```php
$icons->setAttributes(array(
'color' => 'red',
Expand All @@ -51,24 +66,32 @@ $icons->setAttributes(array(
$icons->get('mail');
// <svg ... color="red" stroke-width="3" ... >...</svg>
```

### Get an icon as a string

Set the third argument to `false` to get a string instead of echoing the icon.

```php
$icon_string = $icons->get('activity', array(), false);
// Then do whatever with $icon_string
```

## API

### `Feather\Icons`

Usage:

```php
$icons = new Feather\Icons;
```

<br>

### `Feather\Icons->get($name, $attributes = array(), $echo = true)`

Gets an icon as svg. Can be echoed (default) or returned as a string. Attributes passed will be merged over the class defaults.

```php
$icons = new Feather\Icons;

Expand All @@ -84,7 +107,9 @@ $icons->get('battery', array('class' => 'fooclass', 'stroke-width' => 1, 'aria-l
$cloud_icon = $icons->get('cloud', array(), false);
doStuffWith($cloud_icon);
```

#### Arguments

|Argument |Type |Description |
|------------|-------|---------------------------------------------------------------------------------|
|$name |string |The name of the icon. A full list can be found [here](https://feathericons.com/).|
Expand All @@ -94,7 +119,10 @@ doStuffWith($cloud_icon);
<br>

### `Feather\Icons->setAttributes($attributes, $merge = true)`
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.

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.

```php
$icons = new Feather\Icons;

Expand All @@ -105,7 +133,9 @@ $icons->setAttributes(array('color' => 'red', 'stroke-width' => 3));
$icons->get('delete');
// <svg ... color="red" stroke-width="1" ... >...</svg>
```

#### Arguments

|Argument |Type |Description |
|-----------|-------|---------------------------------------------------------------------------|
|$attributes|array |Attributes to add |
Expand All @@ -114,7 +144,9 @@ $icons->get('delete');
<br>

### `Feather\Icons->getAttributes()`

Get the current attributes for the class. To set it, use the `setAttributes()` method;

```php
$icons = new Feather\Icons;

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

### `Feather\DEFAULT_ATTRIBUTES`

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.

```php
$icons = new Feather\Icons;

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

## Contributing

Feel free to open up issues and PRs for suggesstions.

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

Better contributing docs are coming soon!

## License

Licensed under the [MIT License](https://github.com/Pixelrobin/php-feather/blob/master/LICENSE).

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).
28 changes: 14 additions & 14 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ const feather = require('feather-icons');
const fs = require('fs');
const path = require('path');

const outPath = path.resolve(__dirname, '../icons');
const outPath = path.resolve(__dirname, '../icons');
let defaultAttrs = null;

Object.keys(feather.icons)
.forEach(key => {
const { name, contents, attrs } = feather.icons[key];
.forEach(key => {
const {name, contents, attrs} = feather.icons[key];

if (defaultAttrs === null) {
defaultAttrs = attrs;
}
if (defaultAttrs === null) {
defaultAttrs = attrs;
}

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

delete defaultAttrs.class;

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

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

fs.writeFileSync(path.resolve(__dirname, '../src/defaultAttributes.php'), php);
57 changes: 31 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
{
"name": "pixelrobin/php-feather",
"type": "library",
"description": "PHP library for feather icons",
"keywords": ["feather", "icons", "svg", "pixelrobin"],
"license": "MIT",
"authors": [
{
"name": "Michael Savchuk",
"email": "[email protected]"
},
{
"name": "Nate Wiebe",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Feather\\": "src/"
}
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "7"
}
"name": "pixelrobin/php-feather",
"type": "library",
"description": "PHP library for feather icons",
"keywords": [
"feather",
"icons",
"svg",
"pixelrobin"
],
"license": "MIT",
"authors": [
{
"name": "Michael Savchuk",
"email": "[email protected]"
},
{
"name": "Nate Wiebe",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Feather\\": "src/"
}
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "7"
}
}
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "feather-php",
"version": "1.0.0",
"description": "PHP library for feather icons",
"main": "index.js",
"scripts": {
"build": "node bin/build.js",
"test": "node tests/prepare && vendor/bin/phpunit --verbose --bootstrap vendor/autoload.php tests/FeatherTest"
},
"author": "",
"license": "MIT",
"dependencies": {
"feather-icons": "^4.26.0"
}
"name": "feather-php",
"version": "1.0.0",
"description": "PHP library for feather icons",
"main": "index.js",
"scripts": {
"build": "node bin/build.js",
"test": "node tests/prepare && vendor/bin/phpunit --verbose --bootstrap vendor/autoload.php tests/FeatherTest"
},
"author": "",
"license": "MIT",
"dependencies": {
"feather-icons": "^4.26.0"
}
}
Loading