Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yii-extension/simple-widget
Simple widget for PHP.
https://github.com/yii-extension/simple-widget
php widget yii2 yii3
Last synced: 25 days ago
JSON representation
Simple widget for PHP.
- Host: GitHub
- URL: https://github.com/yii-extension/simple-widget
- Owner: yii-extension
- License: bsd-3-clause
- Created: 2021-03-27T14:03:23.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T06:02:01.000Z (almost 2 years ago)
- Last Synced: 2024-11-26T03:30:58.505Z (about 1 month ago)
- Topics: php, widget, yii2, yii3
- Language: PHP
- Homepage:
- Size: 50.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Simple widget
[![Total Downloads](https://poser.pugx.org/yii-extension/simple-widget/downloads.png)](https://packagist.org/packages/yii-extension/simple-widget)
[![Build Status](https://github.com/yii-extension/simple-widget/workflows/build/badge.svg)](https://github.com/yii-extension/simple-widget/actions?query=workflow%3Abuild)
[![codecov](https://codecov.io/gh/yii-extension/simple-widget/branch/master/graph/badge.svg?token=gaUysTvoUu)](https://codecov.io/gh/yii-extension/simple-widget)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii-extension%2Fsimple-widget%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yii-extension/simple-widget/master)
[![static analysis](https://github.com/yii-extension/simple-widget/workflows/static%20analysis/badge.svg)](https://github.com/yii-extension/simple-widget/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yii-extension/simple-widget/coverage.svg)](https://shepherd.dev/github/yii-extension/simple-widget)## Installation
```shell
composer require simple-widget
```## Usage
### Create a new widget without dependencies:
```php
attributes)) . '>';
}public function id(string $value): self
{
$new = clone $this;
$new->attributes['id'] = $value;
return $new;
}protected function beforeRun(): bool
{
if (isset($this->attributes['id']) && $this->attributes['id'] === 'beforerun') {
return false;
}return parent::beforeRun();
}protected function afterRun(string $result): string
{
$result = parent::afterRun($result);if (isset($this->attributes['id']) && $this->attributes['id'] === 'afterrun') {
$result = '' . $result . '';
}return $result;
}
}
```Using in view:
```php
Widget::create()->id('id-test')->attributes(['class' => 'text-danger'])->render();
```Code generated:
```html
```
### Using widget in view with config factory:
```php
Widget::create(['attributes()' => [['class' => 'test-class']], 'id()' => ['id-tests']])->render();
```Code generated:
```html
```
### Using widget in view with config file:
Load config from file: `/config/widget-definitions.php`:
```php
return [
'attributes()' => ['class' => 'test-class'],
'id()' => 'id-tests',
];
``````php
Widget::create()->loadConfigFile(__DIR__ . '/config/widget-definitions.php')->render();
```Code generated:
```html```
### Create a new widget with depedencie injection:
```php
html->renderTagAttributes($this->attributes)) . '>';
}public function id(string $value): self
{
$new = clone $this;
$new->attributes['id'] = $value;
return $new;
}
}
```Using view:
```php
[['class' => 'test-class']]], [new Html()])->id('w0')->render();
```Code generated:
```html```
### Using widget load config file with `CONSTANT`:
Defined `CONSTANT`: `WIDGET_CONFIG_PATH` for example:
```php
define('WIDGET_CONFIG_PATH', __DIR__ . '/config');
```Create file `/config/widget-definitions.php`:
```php
[method() => [$value]
'Widget' => [
'attributes()' => [['class' => 'test-class']],
'id()' => ['id-tests'],
],
];
```### Unit testing
The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
```shell
./vendor/bin/phpunit
```### Mutation testing
The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:
```shell
./vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered
```## Static analysis
The code is statically analyzed with [Psalm](https://psalm.dev/docs). To run static analysis:
```shell
./vendor/bin/psalm
```### Support the project
[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)
## License
The simple-widget for Yii Packages is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.Maintained by [Yii Extension](https://github.com/yii-extension).